def test_unpack_objects(): # Fun with objects Hello = create_node("Hello") assert objpack.loads("Hello()") == Hello() assert objpack.loads("Hello('world')") == Hello("world") assert objpack.loads("Hello('world', example=1)") == Hello("world", example=1) assert objpack.loads("Hello(example=1, 'world')") == Hello("world", example=1) assert objpack.loads("Hello(example=1)") == Hello(example=1) assert objpack.loads("Hello(\n\texample=1\n)") == Hello(example=1)
def test_unpack_objects(): # Fun with objects Hello = create_node('Hello') assert objpack.loads("Hello()") == Hello() assert objpack.loads("Hello('world')") == Hello('world') assert objpack.loads("Hello('world', example=1)") \ == Hello('world', example=1) assert objpack.loads("Hello(example=1, 'world')") \ == Hello('world', example=1) assert objpack.loads("Hello(example=1)") \ == Hello(example=1) assert objpack.loads("Hello(\n\texample=1\n)") \ == Hello(example=1)
def test_unpack_trailing_commas(): """Extra trailing commas are allowed in objects""" assert objpack.loads("[1, 2, 3, ]") == [1, 2, 3] with pytest.raises(TypeError): objpack.loads("[1, 2, 3,,]") with pytest.raises(TypeError): objpack.loads("[1, 2, , 3]") assert objpack.loads("{'a': 'b', 'c': 'd',}") == {"a": "b", "c": "d"} Obj = create_node("Obj") assert objpack.loads("Obj('a', 'b',)") == Obj("a", "b") assert objpack.loads("Obj(a='A', b='B',)") == Obj(a="A", b="B") assert objpack.loads("Obj(a='A', b='B', 'x', 'y',)") == Obj("x", "y", a="A", b="B")
def test_unpack_trailing_commas(): """Extra trailing commas are allowed in objects""" assert objpack.loads("[1, 2, 3, ]") == [1, 2, 3] with pytest.raises(TypeError): objpack.loads('[1, 2, 3,,]') with pytest.raises(TypeError): objpack.loads('[1, 2, , 3]') assert objpack.loads("{'a': 'b', 'c': 'd',}") == {'a': 'b', 'c': 'd'} Obj = create_node('Obj') assert objpack.loads("Obj('a', 'b',)") == Obj('a', 'b') assert objpack.loads("Obj(a='A', b='B',)") == Obj(a='A', b='B') assert objpack.loads("Obj(a='A', b='B', 'x', 'y',)") \ == Obj('x', 'y', a='A', b='B')