# -*- coding: utf-8 -*- import os.path import re from datetime import datetime import numpy as np from numpy.testing import assert_array_almost_equal, assert_array_equal import pytest from galvani import BioLogic, MPTfile, MPRfile from galvani.BioLogic import MPTfileCSV # not exported def test_open_MPT(testdata_dir): mpt1, comments = MPTfile(os.path.join(testdata_dir, 'bio_logic1.mpt')) assert comments == [] assert mpt1.dtype.names == ( "mode", "ox/red", "error", "control changes", "Ns changes", "counter inc.", "time/s", "control/V/mA", "Ewe/V", "dQ/mA.h", "P/W", "I/mA", "(Q-Qo)/mA.h", "x", ) def test_open_MPT_fails_for_bad_file(testdata_dir): with pytest.raises(ValueError, match='Bad first line'): MPTfile(os.path.join(testdata_dir, 'bio_logic1.mpr')) def test_open_MPT_csv(testdata_dir): mpt1, comments = MPTfileCSV(os.path.join(testdata_dir, 'bio_logic1.mpt')) assert comments == [] assert mpt1.fieldnames == [ "mode", "ox/red", "error", "control changes", "Ns changes", "counter inc.", "time/s", "control/V/mA", "Ewe/V", "dq/mA.h", "P/W", "/mA", "(Q-Qo)/mA.h", "x", ] def test_open_MPT_csv_fails_for_bad_file(testdata_dir): with pytest.raises((ValueError, UnicodeDecodeError)): MPTfileCSV(os.path.join(testdata_dir, 'bio_logic1.mpr')) def test_colID_map_uniqueness(): """Check some uniqueness properties of the VMPdata_colID_xyz maps.""" field_colIDs = set(BioLogic.VMPdata_colID_dtype_map.keys()) flag_colIDs = set(BioLogic.VMPdata_colID_flag_map.keys()) field_names = [v[0] for v in BioLogic.VMPdata_colID_dtype_map.values()] flag_names = [v[0] for v in BioLogic.VMPdata_colID_flag_map.values()] assert not field_colIDs.intersection(flag_colIDs) # 'I/mA' and 'dQ/mA.h' are duplicated # assert len(set(field_names)) == len(field_names) assert len(set(flag_names)) == len(flag_names) assert not set(field_names).intersection(flag_names) @pytest.mark.parametrize('colIDs, expected', [ ([1, 2, 3], [('flags', 'u1')]), ([4, 6], [('time/s', '