mirror of
https://github.com/echemdata/galvani.git
synced 2025-12-14 01:15:34 +00:00
Add some tests for the res2sqlite command-line tool
Check that the --help option works even if mdbtools is not installed
This commit is contained in:
@@ -14,6 +14,15 @@ from galvani import res2sqlite
|
|||||||
have_mdbtools = (subprocess.call(['which', 'mdb-export'], stdout=None) == 0)
|
have_mdbtools = (subprocess.call(['which', 'mdb-export'], stdout=None) == 0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_res2sqlite_help():
|
||||||
|
"""Test running `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
|
||||||
|
|
||||||
|
|
||||||
@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):
|
def test_convert_Arbin_no_mdbtools(testdata_dir, tmpdir):
|
||||||
"""Checks that the conversion fails with an appropriate error message."""
|
"""Checks that the conversion fails with an appropriate error message."""
|
||||||
@@ -29,7 +38,7 @@ def test_convert_Arbin_no_mdbtools(testdata_dir, tmpdir):
|
|||||||
|
|
||||||
@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')
|
||||||
@pytest.mark.parametrize('basename', ['arbin1'])
|
@pytest.mark.parametrize('basename', ['arbin1'])
|
||||||
def test_convert_Arbin_to_sqlite(testdata_dir, tmpdir, basename):
|
def test_convert_Arbin_to_sqlite_function(testdata_dir, tmpdir, basename):
|
||||||
"""Convert an Arbin file to SQLite using the functional interface."""
|
"""Convert an Arbin file to SQLite using the functional interface."""
|
||||||
res_file = os.path.join(testdata_dir, basename + '.res')
|
res_file = os.path.join(testdata_dir, basename + '.res')
|
||||||
sqlite_file = os.path.join(str(tmpdir), basename + '.s3db')
|
sqlite_file = os.path.join(str(tmpdir), basename + '.s3db')
|
||||||
@@ -38,3 +47,15 @@ def test_convert_Arbin_to_sqlite(testdata_dir, tmpdir, basename):
|
|||||||
with sqlite3.connect(sqlite_file) as conn:
|
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()
|
csr.fetchone()
|
||||||
|
|
||||||
|
|
||||||
|
@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])
|
||||||
|
assert os.path.isfile(sqlite_file)
|
||||||
|
with sqlite3.connect(sqlite_file) as conn:
|
||||||
|
csr = conn.execute('SELECT * FROM Channel_Normal_Table;')
|
||||||
|
csr.fetchone()
|
||||||
|
|||||||
Reference in New Issue
Block a user