Beispiel #1
0
def loads_from_cpython(case):
    print 'load_from_cpython', ` case `
    try:
        s = cpy_marshal.dumps(case, *cpy_dump_version)
    except ValueError:
        py.test.skip("this version of CPython doesn't support this object")
    obj = marshal.loads(s)
    assert obj == case
def loads_from_cpython(case):
    print 'load_from_cpython', `case`
    try:
        s = cpy_marshal.dumps(case, *cpy_dump_version)
    except ValueError:
        py.test.skip("this version of CPython doesn't support this object") 
    obj = marshal.loads(s)
    assert obj == case
def dumps_subclass(case):
    try:
        class Subclass(type(case)):
            pass
        case = Subclass(case)
    except TypeError:
        py.test.skip("this version of CPython doesn't support this object") 
    s = marshal.dumps(case)
    obj = marshal.loads(s)
    assert obj == case
def dumps_and_reload(case):
    print 'dump_and_reload', `case`
    s = marshal.dumps(case)
    obj = marshal.loads(s)
    assert obj == case
Beispiel #5
0
def test_loads_from_cpython(case):
    s = cpy_marshal.dumps(case, 1)  # XXX: fails with version 2
    obj = marshal.loads(s)
    assert obj == case
Beispiel #6
0
def test_dumps_and_reload(case):
    s = marshal.dumps(case)
    obj = marshal.loads(s)
    assert obj == case
Beispiel #7
0
def test_load_truncated_string():
    s = '(\x02\x00\x00\x00i\x03\x00\x00\x00sB\xf9\x00\x00\nabcd'
    with pytest.raises(EOFError):
        marshal.loads(s)
Beispiel #8
0
@pytest.mark.parametrize('case', TESTCASES)
def test_dumps_to_cpython(case):
    s = marshal.dumps(case)
    obj = cpy_marshal.loads(s)
    assert obj == case


@pytest.mark.parametrize('case', SUBCLASSABLE)
def test_dumps_subclass(case):
    class Subclass(type(case)):
        pass

    case = Subclass(case)
    s = marshal.dumps(case)
    obj = marshal.loads(s)
    assert obj == case


@pytest.mark.parametrize('case', TESTCASES)
def test_load_from_cpython(tmpdir, case):
    p = str(tmpdir.join('test.dat'))

    with open(p, "w") as f1:
        s = cpy_marshal.dump(case, f1, 1)  # XXX: fails with version 2
    with open(p, "r") as f2:
        obj = marshal.load(f2)
    assert obj == case


@pytest.mark.parametrize('case', TESTCASES)
Beispiel #9
0
def dumps_and_reload(case):
    print 'dump_and_reload', ` case `
    s = marshal.dumps(case)
    obj = marshal.loads(s)
    assert obj == case
Beispiel #10
0
def dumps_and_reload(case):
    print('dump_and_reload', repr(case))
    s = marshal.dumps(case)
    obj = marshal.loads(s)
    assert obj == case