diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2024-07-13 18:00:20 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2024-07-13 18:00:20 -0400 |
commit | f5c9611d2d277a7e456c8f952d7f6a78ca891f4a (patch) | |
tree | 4443d1641451e807b93cc324d6fffb7e9f46ab06 /tests/test_file_utils.py | |
parent | e566ab7fcdf9eebfba6bdcce5c7beb738ad906ea (diff) | |
download | qolab-f5c9611d2d277a7e456c8f952d7f6a78ca891f4a.tar.gz qolab-f5c9611d2d277a7e456c8f952d7f6a78ca891f4a.zip |
applied black formatter
Diffstat (limited to 'tests/test_file_utils.py')
-rw-r--r-- | tests/test_file_utils.py | 95 |
1 files changed, 75 insertions, 20 deletions
diff --git a/tests/test_file_utils.py b/tests/test_file_utils.py index f35999d..65ea0c4 100644 --- a/tests/test_file_utils.py +++ b/tests/test_file_utils.py @@ -3,31 +3,86 @@ import os from qolab.file_utils import infer_compression, save_table_with_header + def test_infer_compression(): - assert infer_compression('data.dat') is None - assert infer_compression('data.unknown_ext') is None - assert infer_compression('data.dat.gz') == 'gzip' - assert infer_compression('data.dat.bz') == 'bzip' - assert infer_compression('data.dat.bz2') == 'bzip' + assert infer_compression("data.dat") is None + assert infer_compression("data.unknown_ext") is None + assert infer_compression("data.dat.gz") == "gzip" + 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') + + 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') + 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) - - + 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) |