Ejemplo n.º 1
0
def _test(mod, doc, encoding):
    """Perform encoding specific serialization tests."""
    # Encode/decode and re-assert document.
    as_repr = tu.encode(doc, encoding)
    as_doc_1 = tu.decode(as_repr, encoding)
    tu.assert_doc(mod, as_doc_1)

    # Re-encode and assert encodings.
    as_repr_1 = tu.encode(as_doc_1, encoding)
    tu.assert_int(len(as_repr), len(as_repr_1))
    tu.assert_str(as_repr, as_repr_1)
Ejemplo n.º 2
0
def _test(mod, doc, encoding):
    """Perform encoding specific serialization tests."""
    # Encode/decode and re-assert document.
    as_repr = tu.encode(doc, encoding)
    as_doc_1 = tu.decode(as_repr, encoding)
    tu.assert_doc(mod, as_doc_1)

    # Re-encode and assert encodings.
    as_repr_1 = tu.encode(as_doc_1, encoding)
    tu.assert_int(len(as_repr), len(as_repr_1))
    tu.assert_str(as_repr, as_repr_1)
Ejemplo n.º 3
0
def _test(mod, doc, encoding):
    """Perform encoding specific serialization tests."""
    # Encode/decode and re-assert document.
    as_repr = tu.encode(doc, encoding)
    as_doc_1 = tu.decode(as_repr, encoding)
    tu.assert_doc(mod, as_doc_1)

    # Re-encode.
    as_repr_1 = tu.encode(as_doc_1, encoding)

    # TODO - explore why sometimes XML encoding is problematic
    # although all good when reencoding to json.
    if len(as_repr) != len(as_repr_1) and encoding == 'xml':
        as_repr = tu.encode(tu.decode(as_repr, encoding), 'json')
        as_repr_1 = tu.encode(tu.decode(as_repr_1, encoding), 'json')

    # Verify encoding equivalence.
    tu.assert_int(len(as_repr), len(as_repr_1), msg=str(type(doc)))
    tu.assert_str(as_repr, as_repr_1)