本文整理汇总了Python中sqlitedict.SqliteDict.close方法的典型用法代码示例。如果您正苦于以下问题:Python SqliteDict.close方法的具体用法?Python SqliteDict.close怎么用?Python SqliteDict.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlitedict.SqliteDict
的用法示例。
在下文中一共展示了SqliteDict.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: adjust_evernote_font
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def adjust_evernote_font():
"""
Call for Evernote
"""
note_info = SqliteDict(conf.db.db_file, autocommit=True)
notes_in_evernote = list()
for note in get_notes(get_notebooks()):
guid = note.guid
notes_in_evernote.append(guid)
if guid not in note_info.keys() \
or note_info[guid][FONT_SIZE] != conf.font_size \
or note_info[guid][LINE_HEIGHT] != conf.line_height:
adjust_note(note)
note_info[guid] = {FONT_SIZE: conf.font_size,
LINE_HEIGHT: conf.line_height}
guids_to_forget = [guid for guid in note_info.keys()
if guid not in notes_in_evernote]
for guid in guids_to_forget:
logging.debug("Delete guid from DB: {}".format(guid))
del note_info[guid]
note_info.close()
示例2: assertIterationDataRecorded
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def assertIterationDataRecorded(self, expected, tolerance, root):
if self.comm.rank != 0:
return
db = SqliteDict(self.filename, self.tablename_iterations)
_assertIterationDataRecorded(self, db, expected, tolerance)
db.close()
示例3: assertMetadataRecorded
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def assertMetadataRecorded(self, expected):
if self.comm.rank != 0:
return
db = SqliteDict(self.filename, self.tablename_metadata)
_assertMetadataRecorded(self, db, expected)
db.close()
示例4: _import_sql_data
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def _import_sql_data(data_dir):
file_path = os.path.join(data_dir, DATA_FILE)
# Find out what format we have
with sqlite3.connect(file_path) as conn:
try:
conn.execute('select count(*) from zipgun_info')
zipgun_info = SqliteDict(file_path, tablename='zipgun_info')
version = zipgun_info.get('version', 0)
except sqlite3.OperationalError:
version = 0
if version == 0:
country_postal_codes = SqliteDict(file_path)
elif version == 1:
country_postal_codes = {}
for country_code in zipgun_info['country_codes']:
if country_code in country_postal_codes:
raise ValueError('Duplicate entry found for {}'.format(
country_code))
country_postal_codes[country_code] = SqliteDict(
file_path, tablename='zg_{}'.format(country_code),
journal_mode='OFF')
zipgun_info.close()
else:
raise ValueError('Unknown data file version {}'.format(version))
return country_postal_codes
示例5: test_as_str
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def test_as_str(self):
"""Verify SqliteDict.__str__()."""
# given,
db = SqliteDict()
# exercise
db.__str__()
# test when db closed
db.close()
db.__str__()
示例6: test_overwrite_using_flag_n
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def test_overwrite_using_flag_n(self):
"""Re-opening of a database with flag='c' destroys it all."""
# given,
fname = norm_file('tests/db/sqlitedict-override-test.sqlite')
orig_db = SqliteDict(filename=fname, tablename='sometable')
orig_db['key'] = 'value'
orig_db.commit()
orig_db.close()
# verify,
next_db = SqliteDict(filename=fname, tablename='sometable', flag='n')
self.assertNotIn('key', next_db.keys())
示例7: test_default_reuse_existing_flag_c
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def test_default_reuse_existing_flag_c(self):
"""Re-opening of a database does not destroy it."""
# given,
fname = norm_file('tests/db/sqlitedict-override-test.sqlite')
orig_db = SqliteDict(filename=fname)
orig_db['key'] = 'value'
orig_db.commit()
orig_db.close()
next_db = SqliteDict(filename=fname)
self.assertIn('key', next_db.keys())
self.assertEqual(next_db['key'], 'value')
示例8: basic_usage
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def basic_usage():
"""SqliteDict引擎会将任意的value转换为
"""
mydict = SqliteDict("test.sqlite", autocommit=True)
mydict["integer_value"] = 1
mydict["real_value"] = 2.2
mydict["text_value"] = "abc"
mydict["date_value"] = date.today()
mydict["datetime_value"] = datetime.now()
# if you don't use with SqliteDict("test.sqlite") as mydict: ...
# you have to close the connection explicitly
mydict.close()
示例9: assertDatasetEquals
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def assertDatasetEquals(self, expected, tolerance):
# Close the file to ensure it is written to disk.
self.recorder.close()
# self.recorder.out = None
sentinel = object()
db = SqliteDict( self.filename, self.tablename )
for coord, expect in expected:
iter_coord = format_iteration_coordinate(coord)
groupings = (
("Parameters", expect[0]),
("Unknowns", expect[1]),
("Residuals", expect[2])
)
#### Need to get the record with the key of 'iter_coord'
actual_group = db[iter_coord]
timestamp = actual_group['timestamp']
self.assertTrue(self.t0 <= timestamp and timestamp <= self.t1 )
for label, values in groupings:
actual = actual_group[label]
# If len(actual) == len(expected) and actual <= expected, then
# actual == expected.
self.assertEqual(len(actual), len(values))
for key, val in values:
found_val = actual.get(key, sentinel)
if found_val is sentinel:
self.fail("Did not find key '{0}'".format(key))
if isinstance(found_val, _ByObjWrapper):
found_val = found_val.val
try:
assert_rel_error(self, found_val, val, tolerance)
except TypeError as error:
self.assertEqual(found_val, val)
del db[iter_coord]
######## delete the record with the key 'iter_coord'
# Having deleted all found values, the file should now be empty.
###### Need a way to get the number of records in the main table
self.assertEqual(len(db), 0)
db.close()
示例10: assertDatasetEquals
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def assertDatasetEquals(self, expected, tolerance):
# Close the file to ensure it is written to disk.
self.recorder.close()
# self.recorder.out = None
sentinel = object()
db = SqliteDict( self.filename, self.tablename )
###### Need a way to get a list of the group_names in the order in which they were written and put it in a variable named order
order = db['order']
del db['order']
for coord, expect in expected:
iter_coord = format_iteration_coordinate(coord)
self.assertEqual(order.pop(0), iter_coord)
groupings = (
("Parameters", expect[0]),
("Unknowns", expect[1]),
("Residuals", expect[2])
)
#### Need to get the record with the key of 'iter_coord'
actual_group = db[iter_coord]
for label, values in groupings:
actual = actual_group[label]
# If len(actual) == len(expected) and actual <= expected, then
# actual == expected.
self.assertEqual(len(actual), len(values))
for key, val in values:
found_val = actual.get(key, sentinel)
if found_val is sentinel:
self.fail("Did not find key '{0}'".format(key))
assert_rel_error(self, found_val, val, tolerance)
del db[iter_coord]
######## delete the record with the key 'iter_coord'
# Having deleted all found values, the file should now be empty.
###### Need a way to get the number of records in the main table
self.assertEqual(len(db), 0)
# As should the ordering.
self.assertEqual(len(order), 0)
db.close()
示例11: test_irregular_tablenames
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def test_irregular_tablenames(self):
"""Irregular table names need to be quoted"""
db = SqliteDict(':memory:', tablename='9nine')
db['key'] = 'value'
db.commit()
self.assertEqual(db['key'], 'value')
db.close()
db = SqliteDict(':memory:', tablename='outer space')
db['key'] = 'value'
db.commit()
self.assertEqual(db['key'], 'value')
db.close()
with self.assertRaisesRegexp(ValueError, r'^Invalid tablename '):
SqliteDict(':memory:', '"')
示例12: test_driver_records_model_viewer_data
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def test_driver_records_model_viewer_data(self):
size = 3
prob = Problem(Group(), impl=impl)
G1 = prob.root.add('G1', ParallelGroup())
G1.add('P1', IndepVarComp('x', np.ones(size, float) * 1.0))
G1.add('P2', IndepVarComp('x', np.ones(size, float) * 2.0))
prob.root.add('C1', ABCDArrayComp(size))
prob.root.connect('G1.P1.x', 'C1.a')
prob.root.connect('G1.P2.x', 'C1.b')
prob.driver.add_recorder(self.recorder)
self.recorder.options['record_metadata'] = True
prob.setup(check=False)
prob.cleanup()
# do some basic tests to make sure the model_viewer_data was recorded correctly
if self.comm.rank == 0:
db = SqliteDict(self.filename, self.tablename_metadata)
model_viewer_data = db['model_viewer_data']
tr = model_viewer_data['tree']
self.assertEqual(set(['name', 'type', 'subsystem_type', 'children']), set(tr.keys()))
names = []
for ch1 in tr['children']:
# each is an ordereddict
names.append(ch1["name"] )
for ch2 in ch1["children"]:
names.append(ch2["name"] )
if "children" in ch2:
for ch3 in ch2["children"]:
names.append(ch3["name"] )
expected_names = ['G1', 'P1', 'x', 'P2', 'x', 'C1', 'a', 'b',
'in_string', 'in_list', 'c', 'd', 'out_string', 'out_list']
self.assertEqual( sorted(expected_names), sorted(names))
cl = model_viewer_data['connections_list']
for c in cl:
self.assertEqual(set(['src', 'tgt']), set(c.keys()))
db.close()
示例13: test_recording_system_metadata
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def test_recording_system_metadata(self):
prob = Problem()
prob.root = ConvergeDiverge()
prob.root.add_metadata("string", "just a test")
prob.root.add_metadata("ints", [1, 2, 3])
prob.driver.add_recorder(self.recorder)
self.recorder.options["record_metadata"] = True
prob.setup(check=False)
prob.cleanup() # closes recorders
# check the system metadata recording
sqlite_metadata = SqliteDict(filename=self.filename, flag="r", tablename="metadata")
system_metadata = sqlite_metadata["system_metadata"]
self.assertEqual(len(system_metadata), 2)
self.assertEqual(system_metadata["string"], "just a test")
self.assertEqual(system_metadata["ints"], [1, 2, 3])
sqlite_metadata.close()
示例14: test_mutiple_thread
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def test_mutiple_thread():
"""多个进程访问数据库的时候, 最好只有一个有写操作。如果需要多个进程进行写操作, 则需要每次在
写操作后进行commit, 也就是说需要打开autocommit
"""
dict1 = SqliteDict("test.sqlite", autocommit=False) # if False, then mutiple thread writing is
dict2 = SqliteDict("test.sqlite", autocommit=False) # not allowed
print(dict1["integer_value"])
print(dict2["integer_value"])
# dict1["integer_value"] = 2
print(dict1["integer_value"], dict2["integer_value"])
# dict2["integer_value"] = 3
print(dict1["integer_value"], dict2["integer_value"])
dict1.close()
dict2.close()
示例15: test_recording_model_viewer_data
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import close [as 别名]
def test_recording_model_viewer_data(self):
prob = Problem()
prob.root = ConvergeDiverge()
prob.driver.add_recorder(self.recorder)
self.recorder.options["record_metadata"] = True
prob.setup(check=False)
prob.cleanup() # closes recorders
# do some basic tests to make sure the model_viewer_data was recorded
db = SqliteDict(filename=self.filename, flag="r", tablename="metadata")
model_viewer_data = db["model_viewer_data"]
tr = model_viewer_data["tree"]
self.assertEqual(set(["name", "type", "subsystem_type", "children"]), set(tr.keys()))
cl = model_viewer_data["connections_list"]
for c in cl:
self.assertEqual(set(["src", "tgt"]), set(c.keys()))
db.close()