def test_key_value_data_sqlite(): with wrap() as wrapper: data = dexy.data.KeyValueData("doc.sqlite3", ".sqlite3", "hash1", wrapper) data.append('foo', 'bar') assert len(data.keys()) == 1 assert data.value('foo') == 'bar' assert ["%s: %s" % (k, v) for k, v in data.storage][0] == "foo: bar" data.as_text() == "foo: bar"
def test_generic_data(): with wrap() as wrapper: wrapper.to_walked() wrapper.to_checked() CONTENTS = "contents go here" # Create a GenericData object settings = {'canonical-name': 'doc.txt'} data = dexy.data.Generic("doc.txt", ".txt", "abc000", settings, wrapper) data.setup_storage() # Assign some text contents data._data = CONTENTS assert data.has_data() assert not data.is_cached(True) # Save data to disk data.save() assert data.has_data() assert data.is_cached(True) assert data.filesize(True) > 10 # Clear data from memory data._data = None # Load it again from disk data.load_data(True) assert data._data == CONTENTS assert data.as_text() == CONTENTS
def test_generic_data(): with wrap() as wrapper: wrapper.to_walked() wrapper.to_checked() CONTENTS = "contents go here" # Create a GenericData object settings = { 'canonical-name' : 'doc.txt' } data = dexy.data.Generic("doc.txt", ".txt", "abc000", settings, wrapper) data.setup_storage() # Assign some text contents data._data = CONTENTS assert data.has_data() assert not data.is_cached(True) # Save data to disk data.save() assert data.has_data() assert data.is_cached(True) assert data.filesize(True) > 10 # Clear data from memory data._data = None # Load it again from disk data.load_data(True) assert data._data == CONTENTS assert data.as_text() == CONTENTS
def test_generic_data(): with wrap() as wrapper: CONTENTS = "contents go here" # Create a GenericData object data = dexy.data.GenericData("doc.txt", ".txt", "hash1", wrapper) # Assign some text contents data._data = CONTENTS assert data.has_data() assert not data.is_cached() assert not data.filesize() # Save data to disk data.save() assert data.has_data() assert data.is_cached() assert data.filesize() > 10 # Clear data from memory data._data = None assert data.has_data() # Load it again from disk data.load_data() assert data._data == CONTENTS # The convenience methods load from disk if needed. data._data = None assert data.as_text() == CONTENTS data._data = None assert data.as_sectioned()['1'] == CONTENTS
def test_key_value_data_sqlite(): with wrap() as wrapper: wrapper.to_walked() wrapper.to_checked() settings = {'canonical-name': 'doc.sqlite3'} data = dexy.data.KeyValue("doc.sqlite3", ".sqlite3", "abc000", settings, wrapper) data.setup_storage() data.storage.connect() data.append('foo', 'bar') assert len(data.keys()) == 1 assert data.value('foo') == 'bar' assert ["%s: %s" % (k, v) for k, v in data.storage][0] == "foo: bar" data.as_text() == "foo: bar"
def test_key_value_data_sqlite(): with wrap() as wrapper: wrapper.to_walked() wrapper.to_checked() settings = { 'canonical-name' : 'doc.sqlite3' } data = dexy.data.KeyValue("doc.sqlite3", ".sqlite3", "abc000", settings, wrapper) data.setup_storage() data.storage.connect() data.append('foo', 'bar') assert len(data.keys()) == 1 assert data.value('foo') == 'bar' assert ["%s: %s" % (k, v) for k, v in data.storage][0] == "foo: bar" data.as_text() == "foo: bar"
def test_key_value_data(): with wrap() as wrapper: data = dexy.data.KeyValueData("doc.json", ".json", "hash1", wrapper, storage_type='json') assert not data._data assert data.storage._data == {} # We use the append method to add key-value pairs. data.append('foo', 'bar') assert len(data.keys()) == 1 assert data.value('foo') == 'bar' assert data.storage['foo'] == 'bar' assert data.as_text() == "foo: bar" data.as_sectioned()['foo'] == 'bar'
def test_key_value_data(): with wrap() as wrapper: settings = {'canonical-name': 'doc.json', 'storage-type': 'json'} data = dexy.data.KeyValue("doc.json", ".json", "doc.json", settings, wrapper) data.setup_storage() assert not data._data assert data.storage._data == {} # We use the append method to add key-value pairs. data.append('foo', 'bar') assert len(data.keys()) == 1 assert data.value('foo') == 'bar' assert data.storage['foo'] == 'bar' assert data.as_text() == "foo: bar"
def test_key_value_data(): with wrap() as wrapper: settings = { 'canonical-name' : 'doc.json', 'storage-type' : 'json' } data = dexy.data.KeyValue("doc.json", ".json", "doc.json", settings, wrapper) data.setup_storage() assert not data._data assert data.storage._data == {} # We use the append method to add key-value pairs. data.append('foo', 'bar') assert len(data.keys()) == 1 assert data.value('foo') == 'bar' assert data.storage['foo'] == 'bar' assert data.as_text() == "foo: bar"