diff --git a/tests/conftest.py b/tests/conftest.py index 95a8a47..0b63a0e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,7 @@ import os import pytest -@pytest.fixture(scope='session') +@pytest.fixture(scope="session") def testdata_dir(): """Path to the testdata directory.""" - return os.path.join(os.path.dirname(__file__), 'testdata') + return os.path.join(os.path.dirname(__file__), "testdata") diff --git a/tests/test_Arbin.py b/tests/test_Arbin.py index 2286b2d..d708d3f 100644 --- a/tests/test_Arbin.py +++ b/tests/test_Arbin.py @@ -13,8 +13,7 @@ import pytest from galvani import res2sqlite -have_mdbtools = (subprocess.call(['which', 'mdb-export'], - stdout=subprocess.DEVNULL) == 0) +have_mdbtools = subprocess.call(["which", "mdb-export"], stdout=subprocess.DEVNULL) == 0 def test_res2sqlite_help(): @@ -22,39 +21,47 @@ def test_res2sqlite_help(): This should work even when mdbtools is not installed. """ - help_output = subprocess.check_output(['res2sqlite', '--help']) - assert b'Convert Arbin .res files to sqlite3 databases' in help_output + help_output = subprocess.check_output(["res2sqlite", "--help"]) + assert b"Convert Arbin .res files to sqlite3 databases" in help_output -@pytest.mark.skipif(have_mdbtools, reason='This tests the failure when mdbtools is not installed') +@pytest.mark.skipif( + have_mdbtools, reason="This tests the failure when mdbtools is not installed" +) def test_convert_Arbin_no_mdbtools(testdata_dir, tmpdir): """Checks that the conversion fails with an appropriate error message.""" - res_file = os.path.join(testdata_dir, 'arbin1.res') - sqlite_file = os.path.join(str(tmpdir), 'arbin1.s3db') - with pytest.raises(RuntimeError, match="Could not locate the `mdb-export` executable."): + res_file = os.path.join(testdata_dir, "arbin1.res") + sqlite_file = os.path.join(str(tmpdir), "arbin1.s3db") + with pytest.raises( + RuntimeError, match="Could not locate the `mdb-export` executable." + ): res2sqlite.convert_arbin_to_sqlite(res_file, sqlite_file) -@pytest.mark.skipif(not have_mdbtools, reason='Reading the Arbin file requires MDBTools') -@pytest.mark.parametrize('basename', ['arbin1', 'UM34_Test005E']) +@pytest.mark.skipif( + not have_mdbtools, reason="Reading the Arbin file requires MDBTools" +) +@pytest.mark.parametrize("basename", ["arbin1", "UM34_Test005E"]) def test_convert_Arbin_to_sqlite_function(testdata_dir, tmpdir, basename): """Convert an Arbin file to SQLite using the functional interface.""" - res_file = os.path.join(testdata_dir, basename + '.res') - sqlite_file = os.path.join(str(tmpdir), basename + '.s3db') + res_file = os.path.join(testdata_dir, basename + ".res") + sqlite_file = os.path.join(str(tmpdir), basename + ".s3db") res2sqlite.convert_arbin_to_sqlite(res_file, sqlite_file) assert os.path.isfile(sqlite_file) with sqlite3.connect(sqlite_file) as conn: - csr = conn.execute('SELECT * FROM Channel_Normal_Table;') + csr = conn.execute("SELECT * FROM Channel_Normal_Table;") csr.fetchone() -@pytest.mark.skipif(not have_mdbtools, reason='Reading the Arbin file requires MDBTools') +@pytest.mark.skipif( + not have_mdbtools, reason="Reading the Arbin file requires MDBTools" +) def test_convert_cmdline(testdata_dir, tmpdir): """Checks that the conversion fails with an appropriate error message.""" - res_file = os.path.join(testdata_dir, 'arbin1.res') - sqlite_file = os.path.join(str(tmpdir), 'arbin1.s3db') - subprocess.check_call(['res2sqlite', res_file, sqlite_file]) + res_file = os.path.join(testdata_dir, "arbin1.res") + sqlite_file = os.path.join(str(tmpdir), "arbin1.s3db") + subprocess.check_call(["res2sqlite", res_file, sqlite_file]) assert os.path.isfile(sqlite_file) with sqlite3.connect(sqlite_file) as conn: - csr = conn.execute('SELECT * FROM Channel_Normal_Table;') + csr = conn.execute("SELECT * FROM Channel_Normal_Table;") csr.fetchone() diff --git a/tests/test_BioLogic.py b/tests/test_BioLogic.py index ad7be6f..df90b18 100644 --- a/tests/test_BioLogic.py +++ b/tests/test_BioLogic.py @@ -17,33 +17,55 @@ from galvani.BioLogic import MPTfileCSV # not exported def test_open_MPT(testdata_dir): - mpt1, comments = MPTfile(os.path.join(testdata_dir, 'bio_logic1.mpt')) + 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", + "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')) + 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')) + 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", + "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')) + MPTfileCSV(os.path.join(testdata_dir, "bio_logic1.mpr")) def test_colID_map_uniqueness(): @@ -59,13 +81,16 @@ def test_colID_map_uniqueness(): assert not set(field_names).intersection(flag_names) -@pytest.mark.parametrize('colIDs, expected', [ - ([1, 2, 3], [('flags', 'u1')]), - ([4, 6], [('time/s', '