def test_read_gzip(): with tmpfile('json.gz') as fn: f = gzip.open(fn, 'wb') s = json.dumps(dat).encode('utf-8') f.write(s) f.close() js = JSON(fn) assert convert(list, js) == dat
def test_write_gzip(): with tmpfile('json.gz') as fn: j = JSON(fn) append(j, dat) f = gzip.open(fn) text = f.read() f.close() assert text.decode('utf-8').strip() == str(json.dumps(dat))
def test_write_gzip_lines(): with tmpfile('json.gz') as fn: j = JSONLines(fn) append(j, dat) f = gzip.open(fn) line = next(f) f.close() assert line.decode('utf-8').strip() == str(json.dumps(dat[0]))
def test_read_gzip_lines(): with tmpfile('json.gz') as fn: f = gzip.open(fn, 'wb') for item in dat: s = json.dumps(item).encode('utf-8') f.write(s) f.write(b'\n') f.close() js = JSONLines(fn) assert convert(list, js) == dat
def test_json_encoder(): result = json.dumps([1, datetime.datetime(2000, 1, 1, 12, 30, 0)], default=json_dumps) assert result == '[1, "2000-01-01T12:30:00Z"]' assert json.loads(result) == [1, "2000-01-01T12:30:00Z"]