def test_json_parsed(): content = ''' { "container": { "id": 1138003, "inner": [ { "end": { "id": 123 } } ] } } ''' parser = JSONParser({ 'success': { 'base': 'container > inner > 0 > end > id' } }) assert parser.parse(content).success == 123 parser = JSONParser({ 'success': { 'base': 'container > inner', 'children': 'end > id', } }) assert parser.parse(content).success == [123]
def test_parse_memoization(): api = JSONParser().parse(JSON_CONTENT) with patch.object(api, 'get_from_dict', wraps=api.get_from_dict) as patched: assert api.parse('container > test') == 'value' assert patched.call_count == 1 assert api.parse('container > test') == 'value' assert patched.call_count == 1