예제 #1
0
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
예제 #2
0
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)])
예제 #3
0
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()
    )
예제 #4
0
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"])
예제 #5
0
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()
    )
예제 #6
0
def test_false_conversion():
    assertEqual(Parser(b'').convert('FALSE', None), False)
예제 #7
0
def test_null_conversion():
    assertEqual(Parser(b'').convert('NULL', None), None)
예제 #8
0
def test_true_conversion():
    assertEqual(Parser(b'').convert('TRUE', None), True)
예제 #9
0
def test_negative_float_conversion():
    v = Parser(b'').convert('NUMBER', (b'-3.1415',))
    assertIsFloat(v)
    assertEqual(v, -3.1415)
예제 #10
0
def test_negative_digit_conversion():
    v = Parser(b'').convert('NUMBER', (b'-3',))
    assertIsInt(v)
    assertEqual(v, -3)
예제 #11
0
def test_double_digit_conversion():
    v = Parser(b'').convert('NUMBER', (b'13',))
    assertIsInt(v)
    assertEqual(v, 13)
예제 #12
0
def test_single_digit_conversion():
    v = Parser(b'').convert('NUMBER', (b'0',))
    assertIsInt(v)
    assertEqual(v, 0)
예제 #13
0
def test_string_conversion():
    assertEqual(
        Parser(b'').convert('STRING', (b't', b'e', b's', b't')),
        'test'
    )