Example #1
0
def jsonlines_file(data):
    with tmpfile('.json') as fn:
        with open(fn, 'w') as f:
            for item in data:
                json.dump(item, f, default=json_dumps)
                f.write('\n')

        yield fn
Example #2
0
def jsonlines_file(data):
    with tmpfile('.json') as fn:
        with open(fn, 'w') as f:
            for item in data:
                json.dump(item, f, default=json_dumps)
                f.write('\n')

        yield fn
Example #3
0
def test_multiple_jsonlines():
    a, b = '_test_a1.json', '_test_a2.json'
    try:
        with ignoring(OSError):
            os.remove(a)
        with ignoring(OSError):
            os.remove(b)
        with open(a, 'w') as f:
            json.dump(dat, f)
        with open(b'_test_a2.json', 'w') as f:
            json.dump(dat, f)
        r = resource('_test_a*.json')
        result = convert(list, r)
        assert len(result) == len(dat) * 2
    finally:
        with ignoring(OSError):
            os.remove(a)
        with ignoring(OSError):
            os.remove(b)
Example #4
0
def test_multiple_jsonlines():
    a, b = '_test_a1.json', '_test_a2.json'
    try:
        with ignoring(OSError):
            os.remove(a)
        with ignoring(OSError):
            os.remove(b)
        with open(a, 'w') as f:
            json.dump(dat, f)
        with open(b'_test_a2.json', 'w') as f:
            json.dump(dat, f)
        r = resource('_test_a*.json')
        result = convert(list, r)
        assert len(result) == len(dat) * 2
    finally:
        with ignoring(OSError):
            os.remove(a)
        with ignoring(OSError):
            os.remove(b)
Example #5
0
def json_file(data):
    with tmpfile('.json') as fn:
        with open(fn, 'w') as f:
            json.dump(data, f, default=json_dumps)

        yield fn
Example #6
0
def json_file(data):
    with tmpfile('.json') as fn:
        with open(fn, 'w') as f:
            json.dump(data, f, default=json_dumps)

        yield fn