示例#1
0
def test_keyvalue_data_stores_dict():
    with wrap() as wrapper:
        doc = Doc("hello.json",
                  wrapper, [],
                  data_type="keyvalue",
                  contents="dummy contents")

        wrapper.run_docs(doc)
        data = doc.output_data()

        assert data.alias == 'keyvalue'
        assert list(data.keys()) == []

        data.append("foo", 123)
        data.append("bar", 456)

        assert sorted(data.keys()) == ["bar", "foo"]
示例#2
0
文件: test_data.py 项目: GWhized/dexy
def test_keyvalue_data_stores_dict():
    with wrap() as wrapper:
        doc = Doc("hello.json",
                wrapper,
                [],
                data_type="keyvalue",
                contents="dummy contents"
                )

        wrapper.run_docs(doc)
        data = doc.output_data()

        assert data.alias == 'keyvalue'
        assert data.keys() == []

        data.append("foo", 123)
        data.append("bar", 456)

        assert sorted(data.keys()) == ["bar", "foo"]
示例#3
0
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"
示例#4
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'
示例#5
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'
示例#6
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"
示例#7
0
文件: test_data.py 项目: GWhized/dexy
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"
示例#8
0
文件: test_data.py 项目: GWhized/dexy
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'
示例#9
0
文件: test_data.py 项目: GWhized/dexy
def test_sectioned_data_setitem_delitem():
    with wrap() as wrapper:
        contents=[
                {},
                {
                    "name" : "Welcome",
                    "contents" : "This is the first section."
                }
            ]

        doc = Doc("hello.txt",
                wrapper,
                [],
                data_type="sectioned",
                contents=contents
                )

        wrapper.run_docs(doc)
        data = doc.output_data()

        assert data.alias == 'sectioned'
        assert len(data) == 1

        # Add a new section
        data["Conclusions"] = "This is the final section."

        assert len(data) == 2
        
        assert unicode(data['Welcome']) == "This is the first section."
        assert unicode(data["Conclusions"]) == "This is the final section."

        # Modify an existing section
        data["Welcome"] = "This is the initial section."

        assert len(data) == 2

        assert unicode(data['Welcome']) == "This is the initial section."
        assert unicode(data["Conclusions"]) == "This is the final section."

        del data["Conclusions"]

        assert len(data) == 1
        assert data.keys() == ["Welcome"]
示例#10
0
def test_sectioned_data_setitem_delitem():
    with wrap() as wrapper:
        contents = [{}, {
            "name": "Welcome",
            "contents": "This is the first section."
        }]

        doc = Doc("hello.txt",
                  wrapper, [],
                  data_type="sectioned",
                  contents=contents)

        wrapper.run_docs(doc)
        data = doc.output_data()

        assert data.alias == 'sectioned'
        assert len(data) == 1

        # Add a new section
        data["Conclusions"] = "This is the final section."

        assert len(data) == 2

        assert str(data['Welcome']) == "This is the first section."
        assert str(data["Conclusions"]) == "This is the final section."

        # Modify an existing section
        data["Welcome"] = "This is the initial section."

        assert len(data) == 2

        assert str(data['Welcome']) == "This is the initial section."
        assert str(data["Conclusions"]) == "This is the final section."

        del data["Conclusions"]

        assert len(data) == 1
        assert list(data.keys()) == ["Welcome"]
示例#11
0
    def d_data_for_artifact(klass, a):
        data = a.output_data.data()
        if hasattr(data, "keys") and data.keys() == ["1"]:
            data = data["1"]

        return data