Пример #1
0
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
Пример #2
0
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
Пример #3
0
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))
Пример #4
0
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]))
Пример #5
0
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))
Пример #6
0
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]))
Пример #7
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
Пример #8
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
Пример #9
0
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"]
Пример #10
0
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"]