diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2024-06-20 23:46:10 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2024-06-20 23:46:10 -0400 |
commit | ca942da36df41de3c63b49dbfa95f6feb956a7cb (patch) | |
tree | a26ff32b80db673dc798d5a2bbadf21a5de6fe4a /tests/test_file_utils.py | |
parent | de7c61873574690d596434a5106e13d74ff12213 (diff) | |
download | qolab-ca942da36df41de3c63b49dbfa95f6feb956a7cb.tar.gz qolab-ca942da36df41de3c63b49dbfa95f6feb956a7cb.zip |
added match_filename_to_compression option and test cases
Diffstat (limited to 'tests/test_file_utils.py')
-rw-r--r-- | tests/test_file_utils.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/test_file_utils.py b/tests/test_file_utils.py index dd31188..f35999d 100644 --- a/tests/test_file_utils.py +++ b/tests/test_file_utils.py @@ -1,6 +1,7 @@ import pytest +import os -from qolab.file_utils import infer_compression +from qolab.file_utils import infer_compression, save_table_with_header def test_infer_compression(): assert infer_compression('data.dat') is None @@ -9,3 +10,24 @@ def test_infer_compression(): assert infer_compression('data.dat.bz') == 'bzip' assert infer_compression('data.dat.bz2') == 'bzip' +def test_save_table_with_header_match_filename_to_compression(): + import tempfile + data = [ [1, 3], [2, 5] ] + headerstr=['header 1', 'header 2'] + with tempfile.TemporaryDirectory(prefix='qolab_test') as d: + fname = os.path.join(d, 't.dat') + assert save_table_with_header(fname, data, header=headerstr, compressionmethod=None, match_filename_to_compression=True) == (fname) + assert save_table_with_header(fname, data, header=headerstr, compressionmethod='gzip', match_filename_to_compression=True) == (fname+'.gz') + assert save_table_with_header(fname, data, header=headerstr, compressionmethod='bzip', match_filename_to_compression=True) == (fname+'.bz') + + # now cases when requested extension does not match the compression + assert save_table_with_header(fname+'.gz', data, header=headerstr, compressionmethod=None, match_filename_to_compression=True) == (fname+'.gz.dat') + assert save_table_with_header(fname+'.bz', data, header=headerstr, compressionmethod='gzip', match_filename_to_compression=True) == (fname+'.bz.gz') + assert save_table_with_header(fname+'.gz', data, header=headerstr, compressionmethod='bzip', match_filename_to_compression=True) == (fname+'.gz.bz') + + # do as I told cases, extension does not match compression + assert save_table_with_header(fname+'.gz', data, header=headerstr, compressionmethod=None, match_filename_to_compression=False) == (fname+'.gz') + assert save_table_with_header(fname, data, header=headerstr, compressionmethod='gzip', match_filename_to_compression=False) == (fname) + assert save_table_with_header(fname, data, header=headerstr, compressionmethod='bzip', match_filename_to_compression=False) == (fname) + + |