Exemplo n.º 1
0
def test_store_and_load_simpledata():
    res = _construct_simpledata()
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    for key, val in zip(simpledata_str, simpledata_val):
        assert(res[key] == val)
Exemplo n.º 2
0
def test_read_empty_array_via_path():
    res = {'a': np.array([[], []])}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn, path='a')
    assert_array_equal(res, [[], []])
    assert(np.shape(res) == (2, 0))
Exemplo n.º 3
0
def test_write_empty_array():
    res = {'a': [], 'b': np.array([])}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    assert_array_equal(res['a'], [])
    assert_array_equal(res['b'], [])
Exemplo n.º 4
0
def test_load_lazy_simple():
    res = _construct_simpledata()
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn, lazy=True)
    for key, obj in res.items():
        assert(obj is None)
Exemplo n.º 5
0
def test_store_and_load_quantities_array():
    data = {'times': np.array([1, 2, 3]) * pq.ms, 'positions':
            np.array([1, 2, 3]) * pq.cm}
    h5w.save(fn, data, overwrite_dataset=True)
    # loading the whole data
    res = h5w.load(fn)
    assert(res['times'].dimensionality == data['times'].dimensionality)
Exemplo n.º 6
0
def test_write_nested_empty_array():
    res = {'a': [[], []], 'b': np.array([[], []])}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    assert_array_equal(res['a'], [[], []])
    assert(np.shape(res['a']) == (2, 0))
    assert_array_equal(res['b'], [[], []])
    assert(np.shape(res['b']) == (2, 0))
Exemplo n.º 7
0
def test_store_and_load_arraydata():
    res = {}
    for key, val in zip(arraydata_str, arraydata_val):
        res[key] = val
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    for key, val in zip(arraydata_str, arraydata_val):
        assert_array_equal(res[key], val)
Exemplo n.º 8
0
def test_load_lazy_nested():
    res = {'a': 1, 'test1': {'b': 2}, 'test2': {
        'test3': {'c': np.array([1, 2, 3])}}}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn, lazy=True)
    assert(res['a'] is None)
    assert(res['test1']['b'] is None)
    assert(res['test2']['test3']['c'] is None)
Exemplo n.º 9
0
def test_store_and_test_key_types():
    data = {'a': 1, (1, 2): {4: 2.}, 4.: 3.}
    h5w.save(fn, data, write_mode='w')
    res = h5w.load(fn)

    keys = ['a', (1, 2), 4.]
    for k in keys:
        assert(k in res.keys())
    assert(4 in res[(1, 2)].keys())
Exemplo n.º 10
0
def test_store_and_load_dictdata():
    res = {}
    for key, val in zip(dictdata_str, dictdata_val):
        res[key] = val
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    for dkey, dval in zip(dictdata_str, dictdata_val):
        for key, val in dval.items():
            assert(res[dkey][key] == val)
Exemplo n.º 11
0
def test_store_and_load_custom_array():
    a = [[1, 2, 3, 4], [6, 7]]
    h5w.save(fn, {'a': a}, overwrite_dataset=True)
    # loading the whole data
    res = h5w.load(fn)
    for i in xrange(len(a)):
        assert(abs(np.sum(a[i] - res['a'][i])) < 1e-12)
    # loading path directly
    res = h5w.load(fn, path='a/')
    for i in xrange(len(a)):
        assert(abs(np.sum(a[i] - res[i])) < 1e-12)
Exemplo n.º 12
0
def test_handle_nonexisting_path():
    res = {}
    stest = 'this is a test'
    h5w.save(fn, res, write_mode='w')
    try:
        res = h5w.load(fn, path='test/')
        raise Exception()  # should not get until here
    except KeyError:
        res['test'] = stest
        h5w.save(fn, res)
        res.clear()
        res = h5w.load(fn, path='test/')
        assert(res == stest)
Exemplo n.º 13
0
def test_overwrite_dataset():
    res = {'a': 5}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = {'a': 6}
    with pytest.raises(KeyError):
        h5w.save(fn, res, write_mode='a', overwrite_dataset=False)
    res.clear()
    res = h5w.load(fn)
    assert(res['a'] == 5)  # dataset should still contain old value
    res.clear()
    res = {'a': 6}
    h5w.save(
        fn, res, write_mode='a', overwrite_dataset=True)
    res.clear()
    res = h5w.load(fn)
    assert(res['a'] == 6)  # dataset should contain new value
Exemplo n.º 14
0
def test_store_and_load_dataset_directly():
    res = _construct_simpledata()
    h5w.save(fn, res, write_mode='w')
    for key, val in zip(simpledata_str, simpledata_val):
        assert(h5w.load(fn, '/' + key) == val)
Exemplo n.º 15
0
def test_write_and_load_with_label():
    res = _construct_simpledata()
    h5w.save(fn, res, write_mode='w', dict_label='test_label')
    for key, val in zip(simpledata_str, simpledata_val):
        assert(h5w.load(fn, 'test_label/' + key) == val)
Exemplo n.º 16
0
def test_store_none():
    res = {'a1': None}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    assert(res['a1'] is None)
Exemplo n.º 17
0
def test_store_and_load_with_compression():
    data = {'a': 1, 'test1': {'b': 2}, 'test2': {
        'test3': {'c': np.array([1, 2, 3])}}}
    h5w.save(fn, data, write_mode='w', compression='gzip')
    h5w.load(fn)