Пример #1
0
def test_dset_md_update_fail():

    md_test = {
        'int': 1,
        'float': 1.0,
        'complex': 1 + 1j,
        'numpy': np.arange(5),
        'string': 'abc'
    }

    md_test2 = {
        'int': 2,
        'float': 2.0,
        'complex': 2 + 1j,
        'numpy': np.arange(5) * 2,
        'string': 'def'
    }

    with infra.path_provider() as base_path:
        # hacky version of generating a random name
        tmp_fname = os.path.join(
            base_path, ''.join(('test_md_roundtrip_', ''.join(
                random.choice(string.ascii_uppercase + string.digits)
                for x in range(N)), '.h5')))
        test_data = range(50)
        dset_name = 'test'
        with closing(ds.SM_serial.open(tmp_fname, 'w')) as test_sms:
            test_sms.dumps(0, dset_name, test_data, meta_data=md_test)

        with closing(ds.SM_serial.open(tmp_fname, 'r')) as test_sms:
            read_md = test_sms.get_dset_md(0, dset_name)
            print read_md
            assert [read_md[k] == md_test[k] for k in md_test.keys()]

        with closing(ds.SM_serial.open(tmp_fname, 'r+')) as test_sms:
            try:
                test_sms.update_dset_md(0,
                                        dset_name,
                                        meta_data=md_test2,
                                        over_write=False)
                # this should fail and raise a RuntimeError
            except RuntimeError:
                pass
            else:
                # if this gets hit, something is wrong
                assert False

        with closing(ds.SM_serial.open(tmp_fname, 'r')) as test_sms:
            read_md = test_sms.get_dset_md(0, dset_name)
            print read_md
            assert [read_md[k] == md_test[k] for k in md_test.keys()]
Пример #2
0
def test_dset_md_update_fail():

    md_test = {'int': 1,
               'float': 1.0,
               'complex': 1 + 1j,
               'numpy': np.arange(5),
               'string': 'abc'}

    md_test2 = {'int': 2,
                'float': 2.0,
                'complex': 2 + 1j,
                'numpy': np.arange(5) * 2,
                'string': 'def'}

    with infra.path_provider() as base_path:
        # hacky version of generating a random name
        tmp_fname = os.path.join(base_path,
                                 ''.join(('test_md_roundtrip_',
                                         ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N)),
                                         '.h5')))
        test_data = range(50)
        dset_name = 'test'
        with closing(ds.SM_serial.open(tmp_fname, 'w')) as test_sms:
            test_sms.dumps(0, dset_name, test_data, meta_data=md_test)

        with closing(ds.SM_serial.open(tmp_fname, 'r')) as test_sms:
            read_md = test_sms.get_dset_md(0, dset_name)
            print read_md
            assert [read_md[k] == md_test[k] for k in md_test.keys()]

        with closing(ds.SM_serial.open(tmp_fname, 'r+')) as test_sms:
            try:
                test_sms.update_dset_md(0, dset_name, meta_data=md_test2, over_write=False)
                # this should fail and raise a RuntimeError
            except RuntimeError:
                pass
            else:
                # if this gets hit, something is wrong
                assert False

        with closing(ds.SM_serial.open(tmp_fname, 'r')) as test_sms:
            read_md = test_sms.get_dset_md(0, dset_name)
            print read_md
            assert [read_md[k] == md_test[k] for k in md_test.keys()]
Пример #3
0
def _roundtrip_no_md(test_data):

    M = 10  # number of frames to dump
    with infra.path_provider() as base_path:
        # hacky version of generating a random name
        tmp_fname = os.path.join(
            base_path, ''.join(('test_roundtrip_', ''.join(
                random.choice(string.ascii_uppercase + string.digits)
                for x in range(N)), '.h5')))

        with closing(ds.SM_serial.open(tmp_fname, 'w')) as test_sms:
            for dset_name, dtype, data in test_data:
                for k in range(M):
                    test_sms.dumps(k, dset_name, data)

        with closing(ds.SM_serial.open(tmp_fname, 'r')) as test_sms:
            for dset_name, dtype, data in test_data:
                for k in range(M):
                    read_data = test_sms.loads(k, dset_name)
                    assert read_data.dtype == dtype
                    assert np.all(read_data == data)
Пример #4
0
def _roundtrip_no_md(test_data):

    M = 10  # number of frames to dump
    with infra.path_provider() as base_path:
        # hacky version of generating a random name
        tmp_fname = os.path.join(base_path,
                                 ''.join(('test_roundtrip_',
                                         ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N)),
                                         '.h5')))

        with closing(ds.SM_serial.open(tmp_fname, 'w')) as test_sms:
            for dset_name, dtype, data in test_data:
                for k in range(M):
                    test_sms.dumps(k, dset_name, data)

        with closing(ds.SM_serial.open(tmp_fname, 'r')) as test_sms:
            for dset_name, dtype, data in test_data:
                for k in range(M):
                    read_data = test_sms.loads(k, dset_name)
                    assert read_data.dtype == dtype
                    assert np.all(read_data == data)
Пример #5
0
def test_frame_md():
    md_test = {'int': 1,
               'float': 1.0,
               'complex': 1 + 1j,
               'numpy': np.arange(5),
               'string': 'abc',
               'list': range(5)}

    with infra.path_provider() as base_path:
        # hacky version of generating a random name
        tmp_fname = os.path.join(base_path,
                                 ''.join(('test_int_roundtrip_',
                                         ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N)),
                                         '.h5')))

        with closing(ds.SM_serial.open(tmp_fname, 'w')) as test_sms:
            test_sms.set_frame_md(0, md_test)

        with closing(ds.SM_serial.open(tmp_fname, 'r')) as test_sms:
            read_md = test_sms.get_frame_md(0)
            assert [read_md[k] == md_test[k] for k in md_test.keys()]
Пример #6
0
def test_frame_md():
    md_test = {
        'int': 1,
        'float': 1.0,
        'complex': 1 + 1j,
        'numpy': np.arange(5),
        'string': 'abc',
        'list': range(5)
    }

    with infra.path_provider() as base_path:
        # hacky version of generating a random name
        tmp_fname = os.path.join(
            base_path, ''.join(('test_int_roundtrip_', ''.join(
                random.choice(string.ascii_uppercase + string.digits)
                for x in range(N)), '.h5')))

        with closing(ds.SM_serial.open(tmp_fname, 'w')) as test_sms:
            test_sms.set_frame_md(0, md_test)

        with closing(ds.SM_serial.open(tmp_fname, 'r')) as test_sms:
            read_md = test_sms.get_frame_md(0)
            assert [read_md[k] == md_test[k] for k in md_test.keys()]