コード例 #1
0
    def test_provides_external_gc(self):
        adapter = MockAdapter()
        adapter.packundo.deleteObject = True
        storage = self.makeOne(adapter)

        assert_that(storage, validly_provides(IRelStorage))
        assert_that(storage, validly_provides(IExternalGC))
コード例 #2
0
ファイル: test_sync.py プロジェクト: NextThought/nti.site
    def testProxyHostComps(self):
        pers_comps = BaseComponents(BASE, 'persistent', (BASE,))
        host_comps = BaseComponents(BASE, 'example.com', (BASE,))
        host_sm = HSM('example.com', 'siteman', host_comps, pers_comps)
        host_site = MockSite(host_sm)
        host_site.__name__ = host_sm.__name__
        setSite(host_site)

        new_comps = BaseComponents(BASE, 'sub_site', (pers_comps,))
        new_site = MockSite(new_comps)
        new_site.__name__ = new_comps.__name__
        interface.alsoProvides(new_site, IFoo)

        threadSiteSubscriber(new_site, None)

        cur_site = getSite()
        # It should implement the static and dynamic
        # ifaces
        assert_that(cur_site, validly_provides(IFoo))
        assert_that(cur_site, validly_provides(IMock))

        # It should have the marker property
        assert_that(cur_site.getSiteManager(),
                    has_property('host_components',
                                   host_comps))

        assert_that(ro.ro(cur_site.getSiteManager()),
                    contains(
                         # The first entry is synthesized
                         has_property('__name__', new_comps.__name__),
                         pers_comps,
                         # The host comps appear after all the bases
                         # in the ro of the new site
                         host_comps,
                         BASE))
コード例 #3
0
ファイル: test_adapter.py プロジェクト: lungj/relstorage
    def test_implements(self):
        adapter = self._makeOne()
        assert_that(adapter, validly_provides(interfaces.IRelStorageAdapter))

        # pylint:disable=no-value-for-parameter
        for attr_name, field in interfaces.IRelStorageAdapter.namesAndDescriptions(
        ):
            if IObject.providedBy(field):
                attr_iface = field.schema
                attr_val = getattr(adapter, attr_name)
                # Look for functions/methods in its dict and check for __wrapped__ attributes;
                # these come from perfmetrics @metricmethod and that breaks validation.
                for k in dir(type(attr_val)):
                    if k not in attr_iface:
                        continue
                    v = getattr(attr_val, k)
                    if callable(v) and hasattr(v, '__wrapped__'):
                        orig = v.__wrapped__
                        if hasattr(orig, '__get__'):
                            # Must be Python 3, we got the raw unbound function, we need to bind it
                            # and add the self parameter.
                            orig = orig.__get__(type(attr_val), attr_val)
                        try:
                            setattr(attr_val, k, orig)
                        except AttributeError:
                            # Must be slotted.
                            continue
                assert_that(attr_val, validly_provides(attr_iface))
コード例 #4
0
 def test_provides_blob_dir(self):
     tempd = tempfile.mkdtemp(".rstest_storage")
     self.addCleanup(shutil.rmtree, tempd, True)
     storage = self.makeOne(blob_dir=tempd)
     assert_that(storage, validly_provides(IRelStorage))
     assert_that(storage, validly_provides(IBlobStorage))
     assert_that(storage, validly_provides(IBlobStorageRestoreable))
コード例 #5
0
 def test_provides(self):
     cat = self._makeOne()
     assert_that(type(cat), implements(self.main_interface))
     assert_that(cat, validly_provides(self.main_interface))
     assert_that(cat, validly_provides(*self.extra_interfaces))
     assert_that(
         cat,
         does_not(verifiably_provides(*self.doesnt_provide_interfaces)))
コード例 #6
0
 def test_provides_history_free(self):
     storage = self.makeOne(keep_history=False)
     assert_that(storage, validly_provides(IRelStorage))
     assert_that(storage, does_not(provides(IStorageUndoable)))
     assert_that(storage, does_not(provides(IExternalGC)))
     assert_that(storage, does_not(provides(IBlobStorage)))
     assert_that(storage, does_not(provides(IBlobStorageRestoreable)))
     assert_that(storage, does_not(validly_provides(IExternalGC)))
コード例 #7
0
    def test_consume(self, fudge_time):

        fudge_time.is_callable()
        fudge_time.returns(0)
        bucket = PersistentTokenBucket(2)

        assert_that(bucket, validly_provides(interfaces.ITokenBucket))

        # at time 0, the bucket has two tokens in it
        assert_that(bucket.consume(), is_true())
        assert_that(bucket.consume(), is_true())

        # Which are now gone
        assert_that(bucket.consume(), is_false())

        # If we strobe the clock forward, we can get another token, since
        # we are refilling at one per second
        fudge_time.returns(1)

        assert_that(bucket.consume(), is_true())
        assert_that(bucket.consume(), is_false())

        # skip forward two seconds, and we can consume both tokens again
        fudge_time.returns(3)
        assert_that(bucket.consume(2), is_true())
        assert_that(bucket.consume(), is_false())

        # cover
        assert_that(repr(bucket), is_('PersistentTokenBucket(2.0,1.0)'))
コード例 #8
0
    def test_implements_interface(self):

        class Callable(object):
            pass

        factory = self._makeOne(Callable)

        assert_that(factory(), is_(Callable))
        assert_that(factory.title, is_(''))
        assert_that(factory.description, is_(''))

        assert_that(factory, validly_provides(self._getInterface()))
コード例 #9
0
    def test_stale(self):

        method = Foo().method

        stale = method.stale(KeyError) # pylint:disable=no-member
        assert_that(stale, validly_provides(IStaleAware))

        with self.assertRaises(KeyError):
            stale()

        stale_again = stale.stale(ValueError)
        self.assertIs(stale_again, stale)

        not_stale = stale.no_longer_stale()
        self.assertIs(not_stale, method)
        not_stale2 = not_stale.no_longer_stale()
        self.assertIs(not_stale2, method)
コード例 #10
0
ファイル: test_wref.py プロジェクト: NextThought/nti.zodb
    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)))
コード例 #11
0
    def test_ctor(self):
        from relstorage.tests.fakecache import Client
        from relstorage.cache.memcache_client import MemcacheStateCache
        c = self._makeOne()
        assert_that(c, validly_provides(IStorageCache))

        cache = c.cache
        self.assertIsInstance(cache.g, MemcacheStateCache)
        self.assertIsInstance(cache.g.client, Client)
        self.assertEqual(cache.g.client.servers, ['host:9999'])
        self.assertEqual(c.prefix, 'myprefix')
        self.assertEqual(len(c), 0) # size may be greater than 0
        self.assertEqual(c.limit, MockOptionsWithFakeCache.cache_local_mb * 1000000)

        # can be closed multiple times
        c.close()
        c.close()
        self.test_closed_state(c)
コード例 #12
0
    def test_entries(self):
        cache = self._makeOne(20)
        cache[1] = (b'abc', 0)
        entries = list(cache.values())
        self.assertEqual(1, len(entries))
        entry = entries[0]
        assert_that(entry, validly_provides(interfaces.ILRUEntry))
        self.assertEqual(1, entry.key)
        self.assertEqual(b'abc', entry.value)
        self.assertEqual(1, entry.frequency)

        # Getting it again updates its frequency, not
        # necessarily on the same object though.
        self.assertIsNotNone(cache[1])
        entries = list(cache.values())
        self.assertEqual(1, len(entries))
        entry = entries[0]
        self.assertEqual(1, entry.key)
        self.assertEqual(b'abc', entry.value)
        self.assertEqual(2, entry.frequency)
コード例 #13
0
 def test_item_implements(self):
     cache = self._makeOne(20)
     cache[1] = (b'', 0)
     entrya = cache[1]
     assert_that(entrya, validly_provides(interfaces.ILRUEntry))
コード例 #14
0
    def test_cannot_have_line_breaks_in_text_line(self):
        ipt = PlainTextContentFragment(u'This\nis\nnot\nvalid')
        assert_that(ipt, validly_provides(IPlainTextContentFragment))

        assert_that(calling(Title().validate).with_args(ipt),
                    raises(ConstraintNotSatisfied))
コード例 #15
0
 def test_provides(self):
     assert_that(self._makeOne(), validly_provides(self.iface))
コード例 #16
0
 def test_eden_implements(self):
     cache = self._makeOne(100)
     assert_that(cache.eden, validly_provides(interfaces.IGeneration))
コード例 #17
0
    def test_provides(self):

        method = Foo().method

        assert_that(method, validly_provides(IStaleAware))
コード例 #18
0
 def test_interface(self):
     u = IntIds("_ds_id")
     assert_that(u, validly_provides(IIntIds))
     assert_that(u, verifiably_provides(IIntIds))
     assert_that(repr(u), is_not(none()))
コード例 #19
0
 def test_provides(self):
     assert_that(self._makeOne(), validly_provides(IStateCache))
コード例 #20
0
ファイル: test_minmax.py プロジェクト: NextThought/nti.zodb
 def test_numeric_counter_interface(self):
     assert_that(self._makeOne(),
                 validly_provides(interfaces.INumericCounter))
コード例 #21
0
 def test_implements(self):
     cache = super(GenericGenerationalLRUCacheTests, self).test_implements()
     assert_that(cache.eden, validly_provides(interfaces.IGeneration))
     assert_that(cache.protected, validly_provides(interfaces.IGeneration))
     assert_that(cache.probation, validly_provides(interfaces.IGeneration))
コード例 #22
0
 def test_provides(self):
     cm = self._makeOne()
     assert_that(cm, validly_provides(interfaces.IConnectionManager))
コード例 #23
0
 def test_provides(self):
     assert_that(self.makeOne(), validly_provides(IBlobHelper))
コード例 #24
0
 def test_mock(self):
     from hamcrest import assert_that
     from nti.testing.matchers import validly_provides
     drivers = MockDrivers()
     assert_that(drivers, validly_provides(IDBDriverOptions))
コード例 #25
0
    def test_TextUnicodeContentFragment(self):
        t = TextUnicodeContentFragment(default=u'abc')
        assert_that(t.default, validly_provides(IUnicodeContentFragment))


        assert_that(t.fromUnicode(t.default), is_(t.default))
コード例 #26
0
 def test_implements(self):
     assert_that(self._makeOne(),
                 validly_provides(interfaces.IStorageCacheMVCCDatabaseCoordinator))
コード例 #27
0
 def test_provides(self):
     assert_that(self._makeOne(), validly_provides(interfaces.IStateCache))
     assert_that(self._makeOne().new_instance(),
                 validly_provides(interfaces.IStateCache))
コード例 #28
0
ファイル: test_lru_cffiring.py プロジェクト: lungj/relstorage
 def test_implements(self):
     cache = self._makeOne(100)
     assert_that(cache, validly_provides(self._getIface()))
     self.assertIsInstance(cache.stats(), dict)
     return cache
コード例 #29
0
ファイル: test_lru_cffiring.py プロジェクト: lungj/relstorage
 def test_item_implements(self):
     cache = self._makeOne(20)
     entrya = cache.add_MRU((1, 0), (b'', 0))
     assert_that(entrya, validly_provides(interfaces.ILRUEntry))
コード例 #30
0
 def test_provides(self):
     assert_that(self._makeOne(), validly_provides(ITransactionControl))
コード例 #31
0
 def test_implements(self):
     cache = self._makeOne(100)
     assert_that(cache, validly_provides(self._getIface()))
     return cache
コード例 #32
0
ファイル: test_tpc.py プロジェクト: gotcha/relstorage
 def test_verify_interface(self):
     assert_that(self._makeOne(),
                 validly_provides(ITPCStateNotInTransaction))
コード例 #33
0
 def test_provides(self):
     assert_that(self._make_default(), validly_provides(IBlobHelper))