Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 einstein_energy(self, phase, param_search):
einstein_param_query = (
(where('phase_name') == phase.name) & \
(where('parameter_type') == 'THETA') & \
(where('constituent_array').test(self._array_validity))
)
theta = self.redlich_kister_sum(phase, param_search, einstein_param_query)
self.TE = self.einstein_temperature = theta
x = theta / v.T
self.testprop = 3.0 * v.R * ((x**2) * sympy.exp(x) / ((sympy.exp(x) - 1.0) ** 2))
result = 3 * v.R * theta * (0.5 + 1./(sympy.exp(x) - 1))
return result
def delete_job(database, name, owner):
database.remove((where('entity') == "job") & (where('owner') == owner) & (where('name') == name))
def _param_present_in_database(dbf, phase_name, configuration, param_type):
const_arr = tuple([tuple(map(lambda x: v.Species(x), subl)) for subl in map(tuplify, configuration)])
# parameter order doesn't matter here, since the generated might not exactly match. Always override.
query = (where('phase_name') == phase_name) & \
(where('parameter_type') == param_type) & \
(where('constituent_array') == const_arr)
search_result = dbf._parameters.search(query)
if len(search_result) > 0:
return True
keys (dict): data keys to query.
match_any (bool): If True then any key may match or if False then all keys must match.
Returns:
Query: The query object.
"""
def _and(lhs, rhs):
return lhs & rhs
def _or(lhs, rhs):
return lhs | rhs
join = _or if match_any else _and
itr = keys.iteritems()
key, val = itr.next()
query = (tinydb.where(key) == val)
for key, value in itr:
query = join(query, (tinydb.where(key) == value))
return query
def get_release_version(self, suppress_db_warning=False):
db = self._get_db(suppress_db_warning)
version = db.table(self.__table_name).get(where("release_version").exists())
db.close()
return version["release_version"] if version else "0.0.0.0"