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))
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))
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))
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))
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)))
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)))
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)'))
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()))
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)
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)))
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)
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)
def test_item_implements(self): cache = self._makeOne(20) cache[1] = (b'', 0) entrya = cache[1] assert_that(entrya, validly_provides(interfaces.ILRUEntry))
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))
def test_provides(self): assert_that(self._makeOne(), validly_provides(self.iface))
def test_eden_implements(self): cache = self._makeOne(100) assert_that(cache.eden, validly_provides(interfaces.IGeneration))
def test_provides(self): method = Foo().method assert_that(method, validly_provides(IStaleAware))
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()))
def test_provides(self): assert_that(self._makeOne(), validly_provides(IStateCache))
def test_numeric_counter_interface(self): assert_that(self._makeOne(), validly_provides(interfaces.INumericCounter))
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))
def test_provides(self): cm = self._makeOne() assert_that(cm, validly_provides(interfaces.IConnectionManager))
def test_provides(self): assert_that(self.makeOne(), validly_provides(IBlobHelper))
def test_mock(self): from hamcrest import assert_that from nti.testing.matchers import validly_provides drivers = MockDrivers() assert_that(drivers, validly_provides(IDBDriverOptions))
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))
def test_implements(self): assert_that(self._makeOne(), validly_provides(interfaces.IStorageCacheMVCCDatabaseCoordinator))
def test_provides(self): assert_that(self._makeOne(), validly_provides(interfaces.IStateCache)) assert_that(self._makeOne().new_instance(), validly_provides(interfaces.IStateCache))
def test_implements(self): cache = self._makeOne(100) assert_that(cache, validly_provides(self._getIface())) self.assertIsInstance(cache.stats(), dict) return cache
def test_item_implements(self): cache = self._makeOne(20) entrya = cache.add_MRU((1, 0), (b'', 0)) assert_that(entrya, validly_provides(interfaces.ILRUEntry))
def test_provides(self): assert_that(self._makeOne(), validly_provides(ITransactionControl))
def test_implements(self): cache = self._makeOne(100) assert_that(cache, validly_provides(self._getIface())) return cache
def test_verify_interface(self): assert_that(self._makeOne(), validly_provides(ITPCStateNotInTransaction))
def test_provides(self): assert_that(self._make_default(), validly_provides(IBlobHelper))