Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
 def _data_for_doc_info(self, doc_info):
     args = []
     args.extend(doc_info)
     args.append(self.wrapper)
     data = dexy.data.Data.create_instance(*args)
     data.setup_storage()
     if hasattr(data.storage, 'connect'):
         data.storage.connect()
     return data
Beispiel #4
0
 def _data_for_doc_info(self, doc_info):
     args = []
     args.extend(doc_info)
     args.append(self.wrapper)
     data = dexy.data.Data.create_instance(*args)
     data.setup_storage()
     if hasattr(data.storage, 'connect'):
         data.storage.connect()
     return data
Beispiel #5
0
 def data(self, doc_key, input_or_output='output'):
     """
     Retrieves a data object given the doc key.
     """
     doc_info = self.doc_info(doc_key)["%s-data" % input_or_output]
     args = list(doc_info)
     args.append(self.wrapper)
     data = dexy.data.Data.create_instance(*args)
     data.setup_storage()
     if hasattr(data.storage, 'connect'):
         data.storage.connect()
     return data
Beispiel #6
0
 def data(self, doc_key, input_or_output='output'):
     """
     Retrieves a data object given the doc key.
     """
     doc_info = self.doc_info(doc_key)["%s-data" % input_or_output]
     args = list(doc_info)
     args.append(self.wrapper)
     data = dexy.data.Data.create_instance(*args)
     data.setup_storage()
     if hasattr(data.storage, 'connect'):
         data.storage.connect()
     return data
Beispiel #7
0
def test_init_data():
    with wrap() as wrapper:
        settings = {'canonical-name': 'doc.abc'}
        data = dexy.data.Generic("doc.txt", ".abc", "def123", settings,
                                 wrapper)
        data.setup_storage()

        assert data.key == "doc.txt"
        assert data.name == "doc.abc"
        assert data.ext == ".abc"
        assert data.storage_key == "def123"

        assert not data.has_data()
        assert not data.is_cached()
Beispiel #8
0
def test_init_data():
    with wrap() as wrapper:
        settings = {
                'canonical-name' : 'doc.abc'
                }
        data = dexy.data.Generic("doc.txt", ".abc", "def123", settings, wrapper)
        data.setup_storage()

        assert data.key == "doc.txt"
        assert data.name == "doc.abc"
        assert data.ext == ".abc"
        assert data.storage_key == "def123"

        assert not data.has_data()
        assert not data.is_cached()
Beispiel #9
0
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(list(data.keys())) == 1

        assert data.value('foo') == 'bar'
        assert data.storage['foo'] == 'bar'
Beispiel #10
0
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(list(data.keys())) == 1

        assert data.value('foo') == 'bar'
        assert ["%s: %s" % (k, v) for k, v in data.items()][0] == "foo: bar"
Beispiel #11
0
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.iteritems()][0] == "foo: bar"
Beispiel #12
0
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'