def test_mix_handle_bin_path():
	# Based on issue 68
	data = {"fun": 1.1234567891234567e-13}
	path = join(mkdtemp(), 'test_mix_handle_bin_path.json')
	if is_py3:
		with raises(TypeError):
			dump(data, open(path, "wb"))
Example #2
0
def test_file_path_nonumpy():
	path = join(mkdtemp(), 'pytest-nonp.json')
	dump(nonpdata, path, compression=6)
	data2 = load(path, decompression=True)
	assert data2 == nonpdata
	data3 = load(path, decompression=None)  # autodetect gzip
	assert data3 == nonpdata
Example #3
0
def test_file_path():
    path = join(mkdtemp(), 'pytest-nonp.json')
    dump(nonpdata, path, compression=6)
    data2 = load(path, decompression=True)
    assert data2 == nonpdata
    data3 = load(path, decompression=None)  # autodetect gzip
    assert data3 == nonpdata
def test_mix_handle_str_path():
	# Based on issue 68
	data = {"fun": 1.1234567891234567e-13}
	path = join(mkdtemp(), 'test_mix_handle_str_path.json')
	dump(data, open(path, "w"))
	back = load(path)
	assert data == back
Example #5
0
def test_file_handle_nonumpy():
	path = join(mkdtemp(), 'pytest-nonp.json')
	with open(path, 'wb+') as fh:
		dump(nonpdata, fh, compression=6)
	with open(path, 'rb') as fh:
		data2 = load(fh, decompression=True)
	assert data2 == nonpdata
	with open(path, 'rb') as fh:
		data3 = load(fh, decompression=None)  # test autodetect gzip
	assert data3 == nonpdata
Example #6
0
def test_file_handle():
    path = join(mkdtemp(), 'pytest-nonp.json')
    with open(path, 'wb+') as fh:
        dump(nonpdata, fh, compression=6)
    with open(path, 'rb') as fh:
        data2 = load(fh, decompression=True)
    assert data2 == nonpdata
    with open(path, 'rb') as fh:
        data3 = load(fh, decompression=None)  # test autodetect gzip
    assert data3 == nonpdata
Example #7
0
def test_flush_no_errors():
	# just tests that flush doesn't cause problems; checking actual flushing is too messy.
	path = join(mkdtemp(), 'pytest-nonp.json')
	with open(path, 'wb+') as fh:
		dump(nonpdata, fh, compression=True, force_flush=True)
	with open(path, 'rb') as fh:
		data2 = load(fh, decompression=True)
	assert data2 == nonpdata
	# flush non-file IO
	sh = BytesIO()
	try:
		dump(ordered_map, fp=sh, compression=True, force_flush=True)
	finally:
		sh.close()
Example #8
0
def test_flush_no_errors():
    # just tests that flush doesn't cause problems; checking actual flushing is too messy.
    path = join(mkdtemp(), 'pytest-nonp.json')
    with open(path, 'wb+') as fh:
        dump(nonpdata, fh, compression=True, force_flush=True)
    with open(path, 'rb') as fh:
        data2 = load(fh, decompression=True)
    assert data2 == nonpdata
    # flush non-file IO
    sh = BytesIO()
    try:
        dump(ordered_map, fp=sh, compression=True, force_flush=True)
    finally:
        sh.close()
Example #9
0
def test_file_handle_types():
    path = join(mkdtemp(), 'pytest-text.json')
    for conv_str_byte in [True, False]:
        with open(path, 'w+') as fh:
            dump(nonpdata, fh, compression=False, conv_str_byte=conv_str_byte)
        with open(path, 'r') as fh:
            assert load(fh, conv_str_byte=conv_str_byte) == nonpdata
        with StringIO() as fh:
            dump(nonpdata, fh, conv_str_byte=conv_str_byte)
            fh.seek(0)
            assert load(fh, conv_str_byte=conv_str_byte) == nonpdata
    with BytesIO() as fh:
        with raises(TypeError):
            dump(nonpdata, fh)
    with BytesIO() as fh:
        dump(nonpdata, fh, conv_str_byte=True)
        fh.seek(0)
        assert load(fh, conv_str_byte=True) == nonpdata
    if is_py3:
        with open(path, 'w+') as fh:
            with raises(IOError):
                dump(nonpdata, fh, compression=6)
def test_wrong_arg_order():
	# Based on a problem from https://github.com/mverleg/array_storage_benchmark
	li = [[1.0, 2.0], [3.0, 4.0]]
	map = {"a": 1}
	path = join(mkdtemp(), 'pytest-np.json.gz')
	msg = 'json-tricks dump arguments are in the wrong order: provide the data to be serialized before file handle'
	with raises(ValueError) as ex:
		with open(path, 'wb+') as fh:
			dump(fh, li)
	assert msg in ex.value.args[0]
	with raises(ValueError) as ex:
		dump(path, li)
	assert msg in ex.value.args[0]
	with raises(ValueError) as ex:
		with open(path, 'wb+') as fh:
			dump(fh, map)
	assert msg in ex.value.args[0]
	with raises(ValueError) as ex:
		dump(path, map)
	assert msg in ex.value.args[0]
Example #11
0
#    ))

with open('testdata.json') as input_file:
    mythingies = load(input_file)

print("\nData from last run:")

pp = pprint.PrettyPrinter(indent=4)
pp.pprint(mythingies)

this_is_now = datetime.now()

print("\nTime since last checked:")
print(this_is_now - mythingies['current_time'])

if (this_is_now - mythingies['current_time']).days >= 1:
    print('Longer than 1 day since last run.')
else:
    print('Not longer than 1 day since last run.')

# print(dumps(
#    {"current_time": datetime.now()}
#))

# Write out new time if checked.
pp.pprint(args)
if args.check:
    print("Checking and resetting.")
    with open('testdata.json', 'w') as output_file:
        dump({"current_time": datetime.now()}, output_file)
def test_mix_path_handle():
	# Based on issue 68
	data = {"fun": 1.1234567891234567e-13}
	path = join(mkdtemp(), 'test_mix_path_handle.json')
	dump(data, path)