How to use the mock.NonCallableMock function in mock

To help you get started, we’ve selected a few mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github caleb531 / youversion-suggest-alfred / tests / test_web.py View on Github external
def test_get_url_content_compressed(request):
    """should automatically decompress compressed URL content"""
    url = 'https://www.bible.com/bible/59/psa.23'
    gzip_buf = StringIO()
    with GzipFile(fileobj=gzip_buf, mode='wb') as gzip_file:
        gzip_file.write(html_content)
    gzipped_content = gzip_buf.getvalue()
    response_mock = NonCallableMock(
        read=Mock(return_value=gzipped_content),
        info=Mock(return_value=NonCallableMock(
            get=Mock(return_value='gzip'))))
    with patch('urllib2.urlopen', return_value=response_mock):
        url_content = web.get_url_content(url).encode('utf-8')
        nose.assert_equal(url_content, html_content)
github caleb531 / youversion-suggest-alfred / tests / test_add_language / test_get_language_name.py View on Github external
# tests.test_add_language.test_get_language_name
# coding=utf-8

from __future__ import unicode_literals
from mock import patch, Mock, NonCallableMock

import nose.tools as nose

import tests.test_add_language as tests
import utilities.add_language as add_lang

with open('tests/html/languages.html') as html_file:
    patch_urlopen = patch(
        'urllib2.urlopen', return_value=NonCallableMock(
            read=Mock(return_value=html_file.read())))


def set_up():
    patch_urlopen.start()
    tests.set_up()


def tear_down():
    patch_urlopen.stop()
    tests.tear_down()


@nose.with_setup(set_up, tear_down)
def test_get_language_name():
    """should fetch language name for the given language ID"""
github candlepin / subscription-manager / test / test_entbranding.py View on Github external
def test_get_brand_not_installed(self):

        stub_product = DefaultStubProduct()

        # note, no 'brand_type' set
        other_stub_product = StubProduct(id=321, name="A Non Branded Product")

        mock_product_dir = mock.NonCallableMock()
        mock_product_dir.get_installed_products.return_value = [other_stub_product.id]
        inj.provide(inj.PROD_DIR, mock_product_dir)

        mock_ent_cert = mock.Mock()
        mock_ent_cert.products = [stub_product]
        ent_certs = [mock_ent_cert]

        brand_picker = rhelentbranding.RHELBrandPicker(ent_certs)
        brand = brand_picker.get_brand()
        self.assertTrue(brand is None)
github bootc / pypuppetdbquery / tests / test_frontend.py View on Github external
def test_with_query_and_facts_list(self):
        mock_pdb = mock.NonCallableMock()
        mock_pdb.fact_contents = mock.Mock(return_value=[
            {
                'value': 14,
                'certname': 'alpha',
                'environment': 'production',
                'path': ['system_uptime', 'days'],
                'name': 'system_uptime',
            },
        ])

        out = self._query_fact_contents(
            mock_pdb, 'foo=bar', ['system_uptime.days'])

        mock_pdb.fact_contents.assert_called_once_with(query=json.dumps([
            'and',
            ['in', 'certname',
github pika / pika / tests / unit / blocking_connection_tests.py View on Github external
def test_flush_output(self, select_connection_class_mock):
        impl_mock = select_connection_class_mock.return_value
        with mock.patch.object(blocking_connection.BlockingConnection,
                               '_create_connection',
                               return_value=impl_mock):
            connection = blocking_connection.BlockingConnection('params')

        get_buffer_size_mock = mock.Mock(
            name='_get_write_buffer_size',
            side_effect=[100, 50, 0],
            spec=nbio_interface.AbstractStreamTransport.get_write_buffer_size)

        transport_mock = mock.NonCallableMock(
            spec_set=nbio_interface.AbstractStreamTransport)

        connection._impl._transport = transport_mock
        connection._impl._get_write_buffer_size = get_buffer_size_mock

        connection._flush_output(lambda: False, lambda: True)
github candlepin / subscription-manager / test / test_model_ent_cert.py View on Github external
def _inj_mock_dirs(self, stub_product=None):

        stub_product = stub_product or DefaultStubInstalledProduct()
        mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
        mock_prod_dir.get_installed_products.return_value = [stub_product.id]
        mock_prod_dir.get_provided_tags.return_value = stub_product.provided_tags

        mock_content = create_mock_content(tags=['awesomeos-ostree-1'])
        mock_cert_contents = [mock_content]

        mock_ent_cert = mock.Mock(name='MockEntCert')
        mock_ent_cert.products = [stub_product]
        mock_ent_cert.content = mock_cert_contents

        mock_ent_dir = mock.NonCallableMock(name='MockEntDir')
        mock_ent_dir.list_valid.return_value = [mock_ent_cert]
        mock_ent_dir.list_valid_with_content_access.return_value = [mock_ent_cert]

        inj.provide(inj.PROD_DIR, mock_prod_dir)
        inj.provide(inj.ENT_DIR, mock_ent_dir)
github testing-cabal / mock / tests / testcallable.py View on Github external
def test_attributes(self):
        one = NonCallableMock()
        self.assertTrue(issubclass(type(one.one), Mock))

        two = NonCallableMagicMock()
        self.assertTrue(issubclass(type(two.two), MagicMock))
github PyCQA / flake8 / tests / unit / test_plugin.py View on Github external
def test_load_noncallable_plugin():
    """Verify that we do not load a non-callable plugin."""
    entry_point = mock.Mock(spec=['load'])
    entry_point.load.return_value = mock.NonCallableMock()
    plugin = manager.Plugin('T000', entry_point)

    with pytest.raises(exceptions.FailedToLoadPlugin):
        plugin.load_plugin()
    entry_point.load.assert_called_once_with()
github intercom / python-intercom / tests / unit / test_user.py View on Github external
def it_returns_a_collectionproxy_for_all_without_making_any_requests(self):
        with mock.patch('intercom.request.Request.send_request_to_path', new_callable=mock.NonCallableMock):  # noqa
            res = self.client.users.all()
            self.assertIsInstance(res, CollectionProxy)
github testing-cabal / mock / tests / testpatch.py View on Github external
def assertNotCallable(self, obj, magic=True):
        MockClass = NonCallableMagicMock
        if not magic:
            MockClass = NonCallableMock

        self.assertRaises(TypeError, obj)
        self.assertTrue(is_instance(obj, MockClass))
        self.assertFalse(is_instance(obj, CallableMixin))