コード例 #1
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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)
コード例 #2
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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))
コード例 #3
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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'], [])
コード例 #4
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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)
コード例 #5
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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)
コード例 #6
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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))
コード例 #7
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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)
コード例 #8
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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)
コード例 #9
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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())
コード例 #10
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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)
コード例 #11
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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)
コード例 #12
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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)
コード例 #13
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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
コード例 #14
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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)
コード例 #15
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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)
コード例 #16
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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)
コード例 #17
0
ファイル: test_wrapper.py プロジェクト: jakobj/h5py_wrapper
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)