示例#1
0
    def test_application_info(self):

        app_info = {
            'text_key': u'a value',
            'byte_key': b'bytes',
            'int_key': 7,
            'list_key': [42,]
        }

        class IA(Interface):

            field = Attribute("A field")
            field.setTaggedValue(jsonschema.TAG_APPLICATION_INFO, app_info)

        schema = TranslateTestSchema(IA, context=u' TEST').make_schema()

        assert_that(schema, has_key("field"))
        field = schema['field']
        assert_that(field, has_key("application_info"))
        # The dict itself was copied
        assert_that(field['application_info'], is_not(same_instance(app_info)))
        # as were its contents
        assert_that(field['application_info'], has_entry('list_key', is_([42])))
        assert_that(field['application_info'],
                    has_entry('list_key', is_not(same_instance(app_info['list_key']))))

        # Text strings were translated
        assert_that(field['application_info'], has_entry('text_key', u'a value TEST'))

        # Byte strings were not (is that even legel in json?)
        assert_that(field['application_info'], has_entry('byte_key', b'bytes'))
def compare_swap(context):
    assert_that(context.iterator.compare,
                is_(same_instance(operator.ge)))

    assert_that(context.iterator.threshold_compare,
                is_(same_instance(operator.le)))
    return
示例#3
0
    def test_update_mapping_of_primitives_and_sequences(self):
        b = [1, 2, 3]
        ext = {'a': 1, 'b': b, 'c': {}}
        result = self._callFUT(self, ext)
        assert_that(result, is_(same_instance(self)))

        assert_that(ext, is_({'a': 1, 'b': b, 'c': {}}))
        assert_that(ext['b'], is_(same_instance(b)))
    def test_sanitize_user_html_chat(self):
        exp = u'<html><a href=\'http://tag:nextthought.com,2011-10:julie.zhu-OID-0x148a37:55736572735f315f54657374:hjJe3dfZMVb,"body":["5:::{\\"args\\\'>foo</html>'
        plain_text = frg_interfaces.IPlainTextContentFragment(exp)
        assert_that(plain_text, verifiably_provides(frg_interfaces.IPlainTextContentFragment))

        # idempotent
        assert_that(frag_html._sanitize_user_html_to_text(plain_text),
                    is_(same_instance(plain_text)))
        assert_that(frag_html._html_to_sanitized_text(plain_text),
                    is_(same_instance(plain_text)))
示例#5
0
    def test_fetch_device_and_config_when_device_and_config_exist(self):
        with self.provd_managers() as (device_manager, config_manager, _):
            expected_device = device_manager.get.return_value = {'id': self.deviceid,
                                                                 'config': self.config_id}
            expected_config = config_manager.get.return_value = Mock()
            device, config = device_dao.fetch_device_and_config(self.deviceid)

            assert_that(device, same_instance(expected_device))
            assert_that(config, same_instance(expected_config))
            device_manager.get.assert_called_once_with(self.deviceid)
            config_manager.get.assert_called_once_with(self.config_id)
示例#6
0
    def test_singleton_when_ancestor_is_singleton(self):
        X = SingletonDecorator('X', (object, ), {})
        Y = SingletonDecorator('Y', (X, ), {})

        class Z(Y):
            pass

        assert_that(X(), is_(same_instance(X())))
        assert_that(Y(), is_(same_instance(Y())))
        assert_that(Z(), is_(same_instance(Z())))
        assert_that(X(), is_not(same_instance(Z())))
        assert_that(Y(), is_not(same_instance(Z())))
示例#7
0
 def test_that_resolve_links_to_category(self):
     category_name = 'something'
     category = MockCategory(category_name)
     name = 'sample component'
     root = _component_tree_with_category(category_name, name)
     op = ComponentParser()
     
     op.parse(root)
     op.resolve([category])
     result = op.components[name]
     
     assert_that(result.category(category_name), is_(same_instance(category)))
     assert_that(category.set_component_was_called, is_(True))
     assert_that(category.component, is_(same_instance(result)))
示例#8
0
    def testCloneNode(self):
        doc = Document()
        one = doc.createElement('one')
        two = doc.createElement('two')
        three = doc.createTextNode('three')
        two.append(three)
        one.append(two)

        res = one.cloneNode(1)
        assert type(res) is type(one), '"%s" != "%s"' % (type(res), type(one))
        assert type(res[0]) is type(one[0])
        assert_that(res, is_(one))
        assert_that(res, is_not(same_instance(one)))
        assert_that(res[0], is_not(same_instance(one[0])))
示例#9
0
    def testCloneNode(self):
        doc = Document()
        one = doc.createElement('one')
        two = doc.createElement('two')
        three = doc.createTextNode('three')
        two.append(three)
        one.append(two)

        res = one.cloneNode(1)
        assert type(res) is type(one), '"%s" != "%s"' % (type(res), type(one))
        assert type(res[0]) is type(one[0])
        assert_that( res, is_(one))
        assert_that( res, is_not(same_instance(one)))
        assert_that( res[0], is_not( same_instance(one[0]) ))
示例#10
0
    def test_update_sequence_of_primitives_persistent_contained(self):
        from persistent import Persistent
        ext = [1, 2, 3]

        class O(Persistent):
            pass

        contained = O()
        result = self._callFUT(contained, ext)
        assert_that(result, is_(same_instance(ext)))
        assert_that(result, is_([1, 2, 3]))
        assert_that(
            contained,
            has_property('_v_updated_from_external_source',
                         is_(same_instance(ext))))
示例#11
0
    def test_new_from_template(self):
        garray = GrowableArray((3, ))
        garray[:] = [1, 2, 3]
        new_one = garray[1:]

        assert_that(new_one, is_not(same_instance(garray)))
        assert_array_equal(new_one, [2, 3])
示例#12
0
    def testTraverseFailsIntoSiblingSiteExceptHostPolicyFolders(self):
        new_comps = BaseComponents(BASE, 'sub_site', ())
        new_site = MockSite(new_comps)
        new_site.__name__ = new_comps.__name__

        with currentSite(None):
            threadSiteSubscriber(new_site, None)
            # If we walk into a site...

            # ...and then try to walk into a sibling site with no apparent relationship...
            new_comps2 = BaseComponents(BASE, 'sub_site', (new_comps,))
            new_site2 = MockSite(new_comps2)
            new_site2.__name__ = new_comps2.__name__

            # ... we fail...
            assert_that(calling(threadSiteSubscriber).with_args(new_site2, None),
                        raises(LocationError))

            # ...unless they are both HostPolicyFolders...
            interface.alsoProvides(new_site, IHostPolicyFolder)
            interface.alsoProvides(new_site2, IHostPolicyFolder)
            repr(new_site) # coverage
            str(new_site)
            threadSiteSubscriber(new_site2, None)

            # ... which does not change the site
            assert_that(getSite(), is_(same_instance(new_site)))
示例#13
0
    def test_get_token(self):
        coro = self.authenticator.get_token(sentinel.token_id)

        assert_that(
            coro, same_instance(self.websocketd_auth_client.get_token.return_value)
        )
        self.websocketd_auth_client.get_token.assert_called_once_with(sentinel.token_id)
示例#14
0
    def test_new_from_template(self):
        garray = GrowableArray((3,))
        garray[:] = [1, 2, 3]
        new_one = garray[1:]

        assert_that(new_one, is_not(same_instance(garray)))
        assert_array_equal(new_one, [2, 3])
示例#15
0
    def test_module_provides(self):

        from BTrees import family64
        from zope.interface import providedBy

        for name in IBTreeFamily:
            if 'int' in name:
                continue
            module = getattr(btrees.family64LargeBuckets, name)
            assert_that(module, verifiably_provides(IBTreeModule))
            assert_that(
                module,
                verifiably_provides(*providedBy(getattr(family64, name))))
            # That checks the un-adorned names like BTree; it doesn't
            # check that the prefix names are available.
            for attr_name in IBTreeModule:
                # The names are generic for 32-bit; the real named objects
                # are 64-bit
                prefix = name.replace('I', 'L').replace('U', 'Q')
                dec_attr_name = prefix + attr_name
                tree = getattr(module, attr_name)
                assert_that(module,
                            has_property(dec_attr_name, same_instance(tree)))

                assert_that(
                    tree, has_property('max_leaf_size', btrees.MAX_LEAF_SIZE))
                assert_that(
                    tree,
                    has_property('max_internal_size',
                                 btrees.MAX_INTERNAL_SIZE))
    def test_toExternalID(self):
        class T(object):
            pass

        assert_that(toExternalOID(T()), is_(None))

        t = T()
        t._p_oid = b'\x00\x01'
        assert_that(toExternalOID(t), is_(b'0x01'))

        t._p_jar = t
        db = T()
        db.database_name = 'foo'
        t.db = lambda: db
        del t._v_to_external_oid  # pylint:disable=no-member
        assert_that(toExternalOID(t), is_(b'0x01:666f6f'))

        assert_that(
            fromExternalOID('0x01:666f6f')[0],
            is_(b'\x00\x00\x00\x00\x00\x00\x00\x01'))
        assert_that(fromExternalOID('0x01:666f6f')[0], is_(bytes))
        assert_that(fromExternalOID('0x01:666f6f')[1], is_(b'foo'))

        # Given a plain OID, we return just the plain OID
        oid = b'\x00\x00\x00\x00\x00\x00\x00\x01'
        assert_that(fromExternalOID(oid),
                    contains_exactly(same_instance(oid), '', None))
    def test_display_other_end(self):
        call = ReceivedCall(sentinel.date, sentinel.duration,
                            sentinel.caller_name)

        result = call.display_other_end()

        assert_that(result, same_instance(sentinel.caller_name))
示例#18
0
def Load_DoNotReloadExtraConf_ForceEqualsTrue_test(app):
    with patch('ycmd.extra_conf_store._ShouldLoad', return_value=True):
        module = extra_conf_store.Load(PROJECT_EXTRA_CONF)
        assert_that(inspect.ismodule(module))
        assert_that(inspect.getfile(module), equal_to(PROJECT_EXTRA_CONF))
        assert_that(extra_conf_store.Load(PROJECT_EXTRA_CONF, force=True),
                    same_instance(module))
示例#19
0
    def test_zero(self):
        czv = ConstantZeroValue()
        assert_that(czv, is_(same_instance(ConstantZeroValue())))
        assert_that(czv, has_property('value', 0))

        # equality
        assert_that(czv, is_(czv))
        v = NumericMaximum()
        assert_that(czv, is_(v))
        assert_that(v, is_(czv))

        v.value = -1
        assert_that(v, is_(less_than(czv)))

        v.value = 1
        assert_that(v, is_(greater_than(czv)))

        czv.value = 1
        assert_that(czv, has_property('value', 0))

        czv.set(2)
        assert_that(czv, has_property('value', 0))

        assert_that(calling(pickle.dumps).with_args(czv),
                    raises(TypeError))
        assert_that(calling(czv._p_resolveConflict).with_args(None, None, None),
                    raises(NotImplementedError))
示例#20
0
    def test_site_mapping(self):
        """
        Test that we appropriately find mapped site components for
        non-persistent sites.
        """
        transient_site = 'TransientSite'

        with mock_db_trans() as conn:
            synchronize_host_policies()
            ds = conn.root()['nti.dataserver']
            assert ds is not None
            sites = ds['++etc++hostsites']

            # Base
            result = get_site_for_site_names((transient_site,))
            assert_that(result, is_(same_instance(getSite())))

            # Mapped
            site_mapping = SiteMapping(source_site_name=transient_site,
                                       target_site_name=DEMOALPHA.__name__)
            BASE.registerUtility(site_mapping,
                                 provided=ISiteMapping,
                                 name=transient_site)

            for site_name in (transient_site, DEMOALPHA.__name__):
                result = get_site_for_site_names((site_name,))
                assert_that(result, is_(same_instance(sites[DEMOALPHA.__name__])))

            # We can also map persistent sites.
            site_mapping = SiteMapping(source_site_name=DEMOALPHA.__name__,
                                       target_site_name=DEMO.__name__)
            try:
                BASE.registerUtility(site_mapping,
                                     provided=ISiteMapping,
                                     name=DEMOALPHA.__name__)

                for site_name in (DEMO.__name__, DEMOALPHA.__name__):
                    result = get_site_for_site_names((site_name,))
                    assert_that(result, is_(same_instance(sites[DEMO.__name__])))

                # This isn't transitive however.
                result = get_site_for_site_names((transient_site,))
                assert_that(result, is_(same_instance(sites[DEMOALPHA.__name__])))
            finally:
                BASE.unregisterUtility(site_mapping,
                                       name=DEMOALPHA.__name__,
                                       provided=ISiteMapping)
    def test_removeAllProxies_simple(self):

        obj = IM()

        # One layer of wrapping of each
        for wrap in ProxyBase, ContainedProxy, aq_proxied:
            wrapped = wrap(obj)
            assert_that(removeAllProxies(wrapped), is_(same_instance(obj)))
示例#22
0
    def test_copy(self):
        db = DB(None)
        conn = db.open()
        pers = Persistent()
        conn.add(pers)
        conn.root()['a'] = pers

        orig_wref = CopyingWeakRef(pers)


        assert_that(orig_wref, validly_provides(ICachingWeakRef))
        assert_that(orig_wref(), is_(same_instance(pers)))

        del orig_wref._v_ob
        orig_wref.dm = {}

        assert_that(orig_wref(), is_not(same_instance(pers)))
示例#23
0
    def test_new_sections_are_on_level(self):
        """
        Test that created sections are linked to level
        """
        sections = self.partitioner(self.level)

        for section in sections:
            assert_that(section['\ufdd0:level'], is_(same_instance(self.level)))
    def test_display_other_end(self):
        call = SentCall(sentinel.date,
                        sentinel.duration,
                        sentinel.extension)

        result = call.display_other_end()

        assert_that(result, same_instance(sentinel.extension))
示例#25
0
    def test_interpret_cel_unknown_events(self):
        cel = Mock(eventtype=CELEventType.answer)

        result = self.cel_interpretor.interpret_cel(cel, sentinel.call)

        assert_that(result, same_instance(sentinel.call))
        assert_that(self.cel_interpretor.chan_start.call_count, equal_to(0))
        assert_that(self.cel_interpretor.hangup.call_count, equal_to(0))
    def test_display_other_end(self):
        call = ReceivedCall(sentinel.date,
                            sentinel.duration,
                            sentinel.caller_name)

        result = call.display_other_end()

        assert_that(result, same_instance(sentinel.caller_name))
示例#27
0
    def test_pickle_zodb_lookup_utility(self):
        # Now, we can register a couple utilities in the base, save everything,
        # and look it up in the sub (when the classes don't match)
        storage = DemoStorage()
        self._store_base_subs_in_zodb(storage)

        db = DB(storage)
        conn = db.open()
        new_base = conn.root()['base']
        new_base._p_activate()
        new_sub = conn.root()['sub']


        new_base.utilities.btree_provided_threshold = 0
        new_base.utilities.btree_map_threshold = 0

        new_base.registerUtility(MockSite(),
                                 provided=IFoo)
        provided1 = new_base.adapters._provided
        # Previously this would fail. Now it works.
        new_base.registerUtility(MockSite(),
                                 provided=implementedBy(object),
                                 name=u'foo')

        new_base.registerUtility(MockSite(),
                                 provided=IMock,
                                 name=u'foo')

        provided2 = new_base.adapters._provided
        # Make sure that it only converted once
        assert_that(provided1, is_(same_instance(provided2)))
        assert_that(new_base._utility_registrations, is_(BTrees.OOBTree.OOBTree))

        assert_that(new_base._utility_registrations.keys(),
                    contains(
                        (IFoo, u''),
                        (IMock, u'foo'),
                        (implementedBy(object), u'foo'),
                    ))
        assert_that(new_base.utilities._provided, is_(BTrees.family64.OI.BTree))
        assert_that(new_base.utilities._adapters[0], is_(BTrees.family64.OO.BTree))

        assert_that(new_base.utilities._adapters[0][IFoo], is_(BTrees.family64.OO.BTree))


        transaction.commit()
        conn.close()
        db.close()

        db = DB(storage)
        conn = db.open()
        new_sub = conn.root()['sub']

        x = new_sub.queryUtility(IFoo)
        assert_that(x, is_(MockSite))

        x = new_sub.queryUtility(IMock, u'foo')
        assert_that(x, is_(MockSite))
 def test_removeAllProxies_doubled(self):
     # double wrapping in weird combos
     obj = IM()
     for wrap in ProxyBase, ContainedProxy, aq_proxied:
         wrapped = wrap(obj)
         for wrap2 in ContainedProxy, ProxyBase:
             __traceback_info__ = wrap, wrap2
             wrapped = wrap2(wrapped)
             assert_that(removeAllProxies(wrapped), is_(same_instance(obj)))
    def test_will_update_event(self):
        component.provideAdapter(CorrectUpdater)
        events = self.events

        ext = {'a': object()}
        domain = DomainObject()

        updater.update_from_external_object(domain, ext, require_updater=True)

        assert_that(events, has_length(2))
        assert_that(events[0],
                    is_(interfaces.ObjectWillUpdateFromExternalEvent))
        will = events[0]
        assert_that(will.root, is_(same_instance(domain)))
        assert_that(will.object, is_(same_instance(domain)))
        assert_that(will.external_value, is_(ext))

        assert_that(events[1], is_(interfaces.ObjectModifiedFromExternalEvent))
示例#30
0
    def test_get_token(self):
        self.auth_client.token.get.return_value = sentinel.token

        token = asyncio.get_event_loop().run_until_complete(
            self.websocketd_auth_client.get_token(sentinel.token_id)
        )

        assert_that(token, same_instance(sentinel.token))
        self.auth_client.token.get.assert_called_once_with(sentinel.token_id, self._ACL)
def test_wsgi_request_proceeds_for_content_exact_size():
    too_large_size = 10485760
    request = request_factory.post(
        '/', data={'': ''.join('x' * (too_large_size - 83))})
    assert request.META['CONTENT_LENGTH'] == too_large_size

    response = middleware_handler(request)

    assert_that(response, same_instance(test_response))
    def test_new_sections_are_on_level(self):
        """
        Test that created sections are linked to level
        """
        sections = self.partitioner(self.level)

        for section in sections:
            assert_that(section['\ufdd0:level'],
                        is_(same_instance(self.level)))
    def test_execute(self):
        s = _Shell(sentinel.sip_port, sentinel.rtp_port)
        s._process = Mock(pexpect.spawn)
        cmd = Mock(BaseCommand)

        result = s.execute(cmd)

        cmd.execute.assert_called_once_with(s._process)
        assert_that(result, same_instance(cmd.execute.return_value))
示例#34
0
    def test_find_found(self, fetch_device_and_config, to_model):
        device, config = fetch_device_and_config.return_value = (Mock(), Mock())
        model = to_model.return_value = Mock(Device)

        result = device_dao.find(self.deviceid)

        assert_that(result, same_instance(model))
        fetch_device_and_config.assert_called_once_with(self.deviceid)
        to_model.assert_called_once_with(device, config)
示例#35
0
def Load_DoNotReloadExtraConf_ForceEqualsTrue_test( app ):
  with patch( 'ycmd.extra_conf_store._ShouldLoad', return_value = True ):
    module = extra_conf_store.Load( PROJECT_EXTRA_CONF )
    assert_that( inspect.ismodule( module ) )
    assert_that( inspect.getfile( module ), equal_to( PROJECT_EXTRA_CONF ) )
    assert_that(
      extra_conf_store.Load( PROJECT_EXTRA_CONF, force = True ),
      same_instance( module )
    )
示例#36
0
    def test_get(self, fetch_device_and_config, to_model):
        fetch_device_and_config.return_value = self.provd_device, self.provd_config
        expected_device = to_model.return_value = Mock(Device)

        device = device_dao.get(self.deviceid)

        fetch_device_and_config.assert_called_once_with(self.deviceid)
        to_model.assert_called_once_with(self.provd_device, self.provd_config)
        assert_that(device, same_instance(expected_device))
def test_request_removes_qs_dupes():
    request = request_factory.get('/', data={'name': ['1', '2']})

    response = middleware_handler(request)

    assert_that(request.GET.urlencode(), equal_to('name=2'))
    assert_that(request.META['QUERY_STRING'], equal_to('name=2'))
    assert_that(request.environ['QUERY_STRING'], equal_to('name=2'))
    assert_that(response, same_instance(test_response))
    def test_SIF(self):
        from nti.externalization import externalization
        from nti.externalization import interfaces
        import warnings

        with warnings.catch_warnings(record=True):
            sif = getattr(externalization, 'StandardInternalFields')

        assert_that(sif, is_(same_instance(interfaces.StandardInternalFields)))
示例#39
0
 def Load_DoNotReloadExtraConf_ForceEqualsTrue_test(self):
     extra_conf_file = PathToTestFile('extra_conf', 'project',
                                      '.ycm_extra_conf.py')
     with patch('ycmd.extra_conf_store._ShouldLoad', return_value=True):
         module = extra_conf_store.Load(extra_conf_file)
         assert_that(inspect.ismodule(module))
         assert_that(inspect.getfile(module), equal_to(extra_conf_file))
         assert_that(extra_conf_store.Load(extra_conf_file, force=True),
                     same_instance(module))
示例#40
0
def Load_DoNotReloadExtraConf_NoForce_test(app):
    with patch('ycmd.extra_conf_store._ShouldLoad', return_value=True):
        module = extra_conf_store.Load(PROJECT_EXTRA_CONF)
        assert_that(inspect.ismodule(module))
        assert_that(inspect.getfile(module), equal_to(PROJECT_EXTRA_CONF))
        assert_that(module, has_property('is_global_ycm_extra_conf'))
        assert_that(module.is_global_ycm_extra_conf, equal_to(False))
        assert_that(extra_conf_store.Load(PROJECT_EXTRA_CONF),
                    same_instance(module))
示例#41
0
    def test_fetch_device_and_config_when_device_exists_and_references_no_config(self):
        with self.provd_managers() as (device_manager, config_manager, _):
            expected_device = device_manager.get.return_value = {'id': self.deviceid}

            device, config = device_dao.fetch_device_and_config(self.deviceid)

            assert_that(device, same_instance(expected_device))
            assert_that(config, none())
            device_manager.get.assert_called_once_with(self.deviceid)
            assert_that(config_manager.find.call_count, equal_to(0))
    def test_removeAllProxies_multiple_wraps(self):
        from itertools import permutations
        wrappers = [ProxyBase, ContainedProxy, EC.wrapping]
        obj = IM()
        wrapped = obj
        for permutation in permutations(wrappers):
            for wrapper in permutation:
                wrapped = wrapper(wrapped)

        assert_that(removeAllProxies(wrapped), is_(same_instance(obj)))
示例#43
0
    def test_move_to_first_observation_of_new_workunit(self):
        workunit1 = self.model.get_current_workunit()
        assert_that(self.model.get_current_obs_number(), equal_to(0))

        self.model.next_workunit()

        workunit2 = self.model.get_current_workunit()
        assert_that(workunit2, is_not(same_instance(workunit1)))

        assert_that(self.model.get_current_obs_number(), equal_to(0))
    def test_session__turbolinks_redirect_to_set_if_turbolinks_referrer_and_redirect_and_prev_not_location_set(self):
        self.original_response["Location"] = ".new-page"

        request = HttpRequest()
        request.session = {}
        request.META["HTTP_TURBOLINKS_REFERRER"] = True

        response = self.m(request)
        assert_that(response, same_instance(self.original_response))
        assert_that(request.session["_turbolinks_redirect_to"], equal_to(".new-page"))
示例#45
0
    def test_to_source_empty_mapping(self):
        mapping = {}

        model = Mock()

        converter = DatabaseConverter(mapping, self.Schema, self.Model)
        result = converter.to_source(model)

        self.Schema.assert_called_once_with()
        assert_that(result, same_instance(self.db_row))
示例#46
0
    def test_move_to_first_observation_of_new_workunit(self):
        workunit1 = self.model.get_current_workunit()
        assert_that(self.model.get_current_obs_number(), equal_to(0))

        self.model.next_workunit()

        workunit2 = self.model.get_current_workunit()
        assert_that(workunit2, is_not(same_instance(workunit1)))

        assert_that(self.model.get_current_obs_number(), equal_to(0))
示例#47
0
def test_get_by_binding_nonexisting():
    # Get the value for 'another.example' and hold onto it
    another_example = registry.get_by_binding("another.example")
    # Check that if we look 'another.example', that we get the same object
    # back.
    assert_that(registry.get_by_binding("another.example"),
                same_instance(another_example))
    # We should have gotten an empty dictionary back.
    eq_(another_example, {})

    # Now, check that a different, non-existing key gets us a different dict,
    # and not the same dict.
    something_else = registry.get_by_binding("something.else")
    # Check that we get the same thing back again...
    assert_that(registry.get_by_binding("something.else"),
                same_instance(something_else))
    # Check that it's not another_example
    assert_that(something_else, is_not(same_instance(another_example)))
    # We should have gotten an empty dictionary back.
    eq_(something_else, {})
def Load_DoNotReloadExtraConf_NoForce_test( app ):
  with patch( 'ycmd.extra_conf_store._ShouldLoad', return_value = True ):
    module = extra_conf_store.Load( PROJECT_EXTRA_CONF )
    assert_that( inspect.ismodule( module ) )
    assert_that( inspect.getfile( module ), equal_to( PROJECT_EXTRA_CONF ) )
    assert_that( module, has_property( 'is_global_ycm_extra_conf' ) )
    assert_that( module.is_global_ycm_extra_conf, equal_to( False ) )
    assert_that(
      extra_conf_store.Load( PROJECT_EXTRA_CONF ),
      same_instance( module )
    )
def test_get_by_binding_nonexisting():
    # Get the value for 'another.example' and hold onto it
    another_example = registry.get_by_binding("another.example")
    # Check that if we look 'another.example', that we get the same object
    # back.
    assert_that(registry.get_by_binding("another.example"),
                same_instance(another_example))
    # We should have gotten an empty dictionary back.
    eq_(another_example, {})

    # Now, check that a different, non-existing key gets us a different dict,
    # and not the same dict.
    something_else = registry.get_by_binding("something.else")
    # Check that we get the same thing back again...
    assert_that(registry.get_by_binding("something.else"),
                same_instance(something_else))
    # Check that it's not another_example
    assert_that(something_else, is_not(same_instance(another_example)))
    # We should have gotten an empty dictionary back.
    eq_(something_else, {})
示例#50
0
 def Load_DoNotReloadExtraConf_ForceEqualsTrue_test( self ):
   extra_conf_file = PathToTestFile( 'extra_conf', 'project',
                                     '.ycm_extra_conf.py' )
   with patch( 'ycmd.extra_conf_store._ShouldLoad', return_value = True ):
     module = extra_conf_store.Load( extra_conf_file )
     assert_that( inspect.ismodule( module ) )
     assert_that( inspect.getfile( module ), equal_to( extra_conf_file ) )
     assert_that(
       extra_conf_store.Load( extra_conf_file, force = True ),
       same_instance( module )
     )
示例#51
0
    def test_to_data_source(self):
        Source = Mock()
        source_obj = Source.return_value = Mock()

        model = TestModel(field1='value1', field2='value2')

        data_source = model.to_data_source(Source)

        assert_that(source_obj, same_instance(data_source))
        assert_that(data_source.db_field1, equal_to('value1'))
        assert_that(data_source.db_field2, equal_to('value2'))
示例#52
0
    def test_accept_moves_to_first_observation_of_new_workunit(self):
        workunit1 = self.model.get_current_workunit()

        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(0))

        self.accept_source_reading()

        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(1))

        self.accept_source_reading()

        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(2))

        self.accept_source_reading()

        assert_that(self.model.get_current_source_number(), equal_to(1))
        assert_that(self.model.get_current_obs_number(), equal_to(0))

        self.accept_source_reading()

        assert_that(self.model.get_current_source_number(), equal_to(1))
        assert_that(self.model.get_current_obs_number(), equal_to(1))

        self.accept_source_reading()

        assert_that(self.model.get_current_source_number(), equal_to(1))
        assert_that(self.model.get_current_obs_number(), equal_to(2))

        self.accept_source_reading()

        assert_that(self.model.get_current_source_number(), equal_to(2))
        assert_that(self.model.get_current_obs_number(), equal_to(0))

        self.accept_source_reading()

        assert_that(self.model.get_current_source_number(), equal_to(2))
        assert_that(self.model.get_current_obs_number(), equal_to(1))

        self.accept_source_reading()

        assert_that(self.model.get_current_source_number(), equal_to(2))
        assert_that(self.model.get_current_obs_number(), equal_to(2))

        self.accept_source_reading()

        workunit2 = self.model.get_current_workunit()

        assert_that(workunit2, is_not(same_instance(workunit1)))

        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
示例#53
0
    def test_register_implemented_by_lookup_utility(self):
        storage = DemoStorage()
        self._store_base_subs_in_zodb(storage)

        db = DB(storage)
        conn = db.open()
        new_base = conn.root()['base']
        new_base._p_activate()
        new_sub = conn.root()['sub']


        new_base.utilities.btree_provided_threshold = 0
        new_base.utilities.btree_map_threshold = 0

        new_base.registerUtility(MockSite(),
                                 provided=IFoo)
        provided1 = new_base.adapters._provided
        # In the past, we couldn't register by implemented, but now we can.
        new_base.registerUtility(MockSite(),
                                 provided=implementedBy(MockSite),
                                 name=u'foo')

        provided2 = new_base.adapters._provided
        # Make sure that it only converted once
        assert_that(provided1, is_(same_instance(provided2)))
        assert_that(new_base._utility_registrations, is_(BTrees.OOBTree.OOBTree))

        assert_that(new_base._utility_registrations.keys(),
                    contains(
                        (IFoo, u''),
                        ((implementedBy(MockSite), u'foo')),
                    ))
        assert_that(new_base.utilities._provided, is_(BTrees.family64.OI.BTree))
        assert_that(new_base.utilities._adapters[0], is_(BTrees.family64.OO.BTree))

        assert_that(new_base.utilities._adapters[0][IFoo], is_(BTrees.family64.OO.BTree))


        transaction.commit()
        conn.close()
        db.close()

        db = DB(storage)
        conn = db.open()
        new_sub = conn.root()['sub']

        x = new_sub.queryUtility(IFoo)
        assert_that(x, is_(MockSite))

        # But it can't actually be looked up, regardless of whether we
        # convert to btrees or not
        x = new_sub.queryUtility(MockSite, u'foo')
        assert_that(x, is_(none()))
 def test_it_can_find_related_part(self):
     """_RelationshipCollection can find related part"""
     # setup ------------------------
     reltype = RT_CORE_PROPS
     part = Mock(name='part')
     relationship = _Relationship('rId1', reltype, part)
     relationships = _RelationshipCollection()
     relationships._additem(relationship)
     # exercise ---------------------
     retval = relationships.related_part(reltype)
     # verify -----------------------
     assert_that(retval, same_instance(part))
 def test_that_resolve_links_backends_to_categories(self):
     backend_name = 'db'
     category = MockCategory()
     root = _build_tree_with_valid_category_include(backend_name, category)
     op = UsesParser()
     op.parse(root)
     backend = MockBackend()
     
     op.resolve([category], {}, {backend_name:backend})
     
     assert_that(backend.add_category_called, is_(True))
     assert_that(backend.categories, has_item(same_instance(category)))
 def test_that_resolve_links_categories_to_backend(self):
     backend = 'db'
     category = MockCategory()
     root = _build_tree_with_valid_category_include(backend, category)
     op = UsesParser()
     op.parse(root)
     example_backend = MockBackend()
     
     op.resolve([category], {}, {backend:example_backend})
     
     assert_that(category.set_backend_called, is_(True))
     assert_that(category.backend, is_(same_instance(example_backend)))
    def test_that_resolve_passes_backends_to_uses_parser_resolve(self):
        component_parser = MockComponentParser()
        uses_parser = MockUsesParser()
        backend_parser = MockBackendParser()
        dut = ParserCollection(
            backend_parser=backend_parser, component_parser=component_parser, uses_parser=uses_parser
        )
        categories = 5

        dut.resolve(categories)

        assert_that(uses_parser.resolve_backends, is_(same_instance(backend_parser.sample_backends)))
    def test_history_for_phone_missed(self, missed_calls):
        identifier = u'sip/abcdef'
        phone = {u'protocol': u'sip',
                 u'name': u'abcdef'}
        mode = HistoryMode.missed
        missed_calls.return_value = sentinel.calls

        result = call_history_manager.history_for_phone(phone,
                                                        mode,
                                                        sentinel.limit)

        missed_calls.assert_called_once_with(identifier, sentinel.limit)
        assert_that(result, same_instance(sentinel.calls))
示例#59
0
文件: test_astrom.py 项目: OSSOS/MOP
    def test_parse_source_readings_have_observations(self):
        astrom_data = self.parse(TEST_FILE_1)

        obs0 = astrom_data.observations[0]
        obs1 = astrom_data.observations[1]
        obs2 = astrom_data.observations[2]

        source0 = astrom_data.sources[0]
        assert_that(source0.get_reading(0).obs, same_instance(obs0))
        assert_that(source0.get_reading(1).obs, same_instance(obs1))
        assert_that(source0.get_reading(2).obs, same_instance(obs2))

        source1 = astrom_data.sources[1]
        assert_that(source1.get_reading(0).obs, same_instance(obs0))
        assert_that(source1.get_reading(1).obs, same_instance(obs1))
        assert_that(source1.get_reading(2).obs, same_instance(obs2))

        source2 = astrom_data.sources[2]
        assert_that(source2.get_reading(0).obs, same_instance(obs0))
        assert_that(source2.get_reading(1).obs, same_instance(obs1))
        assert_that(source2.get_reading(2).obs, same_instance(obs2))