def parse(b): parser = Parser(BytesIO(b)) result = [] for event, value_gen in parser.parse(): if value_gen is not None: result.append((event, b''.join(value_gen))) else: result.append(event) return result
def test_yield_paths(): fh = open('test_data/api_weather_gov_points.json', 'rb') parser = Parser(fh) path = [ 'properties', 'relativeLocation', 'geometry', 'coordinates', 1 ] assertEqual(list(parser.yield_paths((path,))), [(path, 41.50324)])
def test_parity_with_builtin_json_load_github_repos(): _open = lambda: open('test_data/api_github_com_users_github_repos.json', 'rb') assertEqual( json.load(_open()), Parser(_open()).load() )
from bz2 import BZ2File from pprint import pprint from __init__ import Parser bzfile_path = "tmp/dewiktionary-latest-pages-articles-multistream.xml.bz2" bz = BZ2File(bzfile_path) for record in Parser(bz): pass # print(record["title"])
def test_parity_with_builtin_json_load_weather_data(): _open = lambda: open('test_data/api_weather_gov_points.json', 'rb') assertEqual( json.load(_open()), Parser(_open()).load() )
def test_false_conversion(): assertEqual(Parser(b'').convert('FALSE', None), False)
def test_null_conversion(): assertEqual(Parser(b'').convert('NULL', None), None)
def test_true_conversion(): assertEqual(Parser(b'').convert('TRUE', None), True)
def test_negative_float_conversion(): v = Parser(b'').convert('NUMBER', (b'-3.1415',)) assertIsFloat(v) assertEqual(v, -3.1415)
def test_negative_digit_conversion(): v = Parser(b'').convert('NUMBER', (b'-3',)) assertIsInt(v) assertEqual(v, -3)
def test_double_digit_conversion(): v = Parser(b'').convert('NUMBER', (b'13',)) assertIsInt(v) assertEqual(v, 13)
def test_single_digit_conversion(): v = Parser(b'').convert('NUMBER', (b'0',)) assertIsInt(v) assertEqual(v, 0)
def test_string_conversion(): assertEqual( Parser(b'').convert('STRING', (b't', b'e', b's', b't')), 'test' )