Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_subclass():
# Test that a new query test method in a custom subclass is properly usable
class MyQueryClass(Query):
def equal_double(self, rhs):
return self._generate_test(
lambda value: value == rhs * 2,
('equal_double', self._path, rhs)
)
query = MyQueryClass().val.equal_double('42')
assert query({'val': '4242'})
assert not query({'val': '42'})
assert not query({'': None})
assert hash(query)
def test_custom():
def test(value):
return value == 42
query = Query().val.test(test)
assert query({'val': 42})
assert not query({'val': 40})
assert not query({'val': '44'})
assert not query({'': None})
assert hash(query)
def in_list(value, l):
return value in l
query = Query().val.test(in_list, tuple([25, 35]))
assert not query({'val': 20})
assert query({'val': 25})
assert not query({'val': 30})
assert query({'val': 35})
assert not query({'val': 36})
def test_lru_cache_unlimited_explicit():
cache = LRUCache(capacity=None)
for i in range(100):
cache[i] = i
assert len(cache.lru) == 100
def test_add_new_pump(sdb, manufacturer, model):
'''Test if adding a new unique pump works properly'''
sdb.add_pump(manufacturer = manufacturer, model=model)
q = Query()
result = sdb.pumps.search((q.manufacturer == manufacturer) &
(q.model == model))
expected_result = {
'manufacturer': manufacturer,
'model': model
}
assert result[0] == expected_result
def get(s):
return db.get(where('name') == s)
def test_find_new_posts_and_pages():
entries = [e for e in find_new_posts_and_pages(DB)]
assert len(entries)
pages = [e[1] for e in entries if str(e[0]).endswith('page.md')]
assert len(pages)
assert len(DB.posts.all()) == 20
new_entries = [e for e in find_new_posts_and_pages(DB)]
# no new posts sould be found
assert len(DB.posts.all()) == 20
assert len(new_entries) == 0
[e[0].tags for e in entries]
foo = DB.tags.search(where('name') == 'foo')
assert foo[0]['post_ids'] == list(range(1, 16))
def test_update(db: TinyDB):
assert len(db) == 3
db.update({'int': 2}, where('char') == 'a')
assert db.count(where('int') == 2) == 1
assert db.count(where('int') == 1) == 2
def test_update_all(db: TinyDB):
assert db.count(where('int') == 1) == 3
db.update({'newField': True})
assert db.count(where('newField') == True) == 3 # noqa
def test_access_storage():
assert isinstance(TinyDB(storage=MemoryStorage).storage,
MemoryStorage)
assert isinstance(TinyDB(storage=CachingMiddleware(MemoryStorage)).storage,
CachingMiddleware)
def test_nested():
storage = CachingMiddleware(MemoryStorage)
storage() # Initialization
# Write contents
storage.write(doc)
# Verify contents
assert doc == storage.read()