def test_objectfy_children(factory): @pix.register('A') class A(object): pass @pix.register('B') class B(object): pass obj = factory.objectfy({ 'class': 'A', 'id': 1, 'attr': 'foo', 'child': { 'class': 'B', 'id': 2, 'attr': 'bar', }, }) assert isinstance(obj, A) assert obj['attr'] == 'foo' assert isinstance(obj['child'], B) assert obj['child']['attr'] == 'bar'
def test_objectfy(factory, payload): obj = factory.objectfy(payload) assert obj['name'] == 'parent' assert hasattr(obj, 'get_one') assert len(obj['tests']) == 2 for child in obj['tests']: assert isinstance(child, PIXTestChildObj)
def test_objectfy_pixobject(factory): # testing type: (T) -> T behavior of objectfy class TestObj(pix.PIXObject): pass obj = TestObj(mock.MagicMock()) assert obj == factory.objectfy(obj)
def test_objectfy(factory): @pix.register('A') class A(object): pass obj = factory.objectfy({'class': 'A'}) assert isinstance(obj, A)
def test_objectfy_seq(factory, obj): @pix.register('A') class A(object): pass seq = factory.objectfy(obj) assert isinstance(seq[0], A)
def test_children(factory): @pix.register('A') class A(object): pass @pix.register('B') class B(object): pass obj = factory.objectfy({ 'class': 'A', 'id': 0, 'child1': { 'class': 'B', 'id': 1, }, 'child2': { 'class': 'B', 'id': 2, }, 'child3-4': [ { 'class': 'B', 'id': 3, }, { 'class': 'B', 'id': 4, }, ], 'not-a-child': 42, 'also-not-a-child': {'k': ['v']} }) children = obj.children() assert len(children) == 4 for child in children: assert isinstance(child, B)
def test_children(factory, payload): obj = factory.objectfy(payload) children = obj.children() assert len(children) == 2 for child in children: assert isinstance(child, PIXTestChildObj)
def test_objectfy_passthru(factory, obj): # testing type: (T) -> T behavior of objectfy assert obj == factory.objectfy(obj)