Beispiel #1
0
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'
Beispiel #2
0
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