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
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)
def json_file(data): with tmpfile('.json') as fn: with open(fn, 'w') as f: json.dump(data, f, default=json_dumps) yield fn