def test_namedtupled_json_array_memory(data=json_array): t = namedtupled.json(data) assert t[0].tito.tata == 'tutu' assert t[0].tito.frobnicator == ['this', 'is', 'not', 'a', 'mapping'] assert t[0].foo == 'bar' assert t[0].baz.qux == 'quux' assert t[0].alist[0].a == 'A' assert t[0].alist[1].two == '2' assert t[0].baz != {'qux': 'quux'} assert t[0].alist[0] != {'one': '1', 'a': 'A'}
def test_namedtupled_json_array_file(datafiles): path = datafiles.listdir()[0] t = namedtupled.json(path=path) assert t[0].tito.tata == 'tutu' assert t[0].tito.frobnicator == ['this', 'is', 'not', 'a', 'mapping'] assert t[0].foo == 'bar' assert t[0].baz.qux == 'quux' assert t[0].alist[0].a == 'A' assert t[0].alist[1].two == '2' assert t[0].baz != {'qux': 'quux'} assert t[0].alist[0] != {'one': '1', 'a': 'A'}
def test_json(): data = """{"binks": {"says": "meow"}}""" cat = namedtupled.json(data) assert cat.binks.says == 'meow'
def test_nametupled_json_error(data=json_object, path='foo.json'): with pytest.raises(ValueError) as e: namedtupled.json(data=data, path=path) 'expected one source' in str(e)