Exemplo n.º 1
0
def test_init():
    doc = Node()
    assert doc.get_data() is None
    assert doc.id is not None
    assert type(doc.id) == str
    assert doc.key is None
    assert doc.encoding == "utf-8"

    id = str(uuid4())
    key = "this is a key"
    doc = Node(id=id, key=key, data=TEST_VAL)
    assert doc.id == id
    assert doc.key == key
    assert doc.get_data() == TEST_VAL

    doc = Node(data=TEST_DATA)
    assert doc.get_data() == TEST_DATA

    encoding = DEFAULT_ENCODING
    bytes_val = TEST_DATA.encode(encoding)
    doc = Node(data=TEST_DATA)
    assert doc.get_data() == bytes_val.decode(encoding)

    encoding = "utf-16"
    bytes_val = TEST_DATA.encode(encoding)
    doc = Node(data=bytes_val, encoding=encoding)
    assert doc.get_data() == bytes_val.decode(encoding)
Exemplo n.º 2
0
def test_init_stream(tmpdir):
    str_value = dumps(TEST_VAL)
    val = tmpdir.mkdir("sub").join("value.json")
    val.write(str_value)
    doc = Node(data=val)
    assert doc.get_data() == TEST_VAL