diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2024-07-13 18:05:01 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2024-07-13 18:05:01 -0400 |
commit | 1489ed576f57aabfe7bf222dcd62309c79019e32 (patch) | |
tree | 5764f32c77d31e929107fb3d0bfaf060a8548fd0 /tests/test_trace.py | |
parent | f5178adfefc27452bd0cf7b60f1247fe49b7e1f1 (diff) | |
download | qolab-1489ed576f57aabfe7bf222dcd62309c79019e32.tar.gz qolab-1489ed576f57aabfe7bf222dcd62309c79019e32.zip |
black formatter
Diffstat (limited to 'tests/test_trace.py')
-rw-r--r-- | tests/test_trace.py | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/tests/test_trace.py b/tests/test_trace.py index e811831..a08390a 100644 --- a/tests/test_trace.py +++ b/tests/test_trace.py @@ -1,43 +1,48 @@ import pytest from qolab.data.trace import loadTrace import numpy as np -import os +import os + def isItExpectedTrace(tr): cfg = tr.getConfig() - assert cfg['config']['version'] == '0.1' - assert cfg['config']['model'] == 'Trace' + assert cfg["config"]["version"] == "0.1" + assert cfg["config"]["model"] == "Trace" data = tr.getData() - assert np.all( (data - np.array([[1], [3], [2], [5]])) == 0 ) + assert np.all((data - np.array([[1], [3], [2], [5]])) == 0) return True + def test_load_uncompressed_v0dot1_trace(): - tr = loadTrace('tests/trace_test_data/xtrace1.dat') + tr = loadTrace("tests/trace_test_data/xtrace1.dat") assert isItExpectedTrace(tr) == True + def test_load_gzip_compressed_v0dot1_trace(): - tr = loadTrace('tests/trace_test_data/xtrace1.dat.gz') + tr = loadTrace("tests/trace_test_data/xtrace1.dat.gz") assert isItExpectedTrace(tr) == True + def test_load_bzip_compressed_v0dot1_trace(): - tr = loadTrace('tests/trace_test_data/xtrace1.dat.bz') + tr = loadTrace("tests/trace_test_data/xtrace1.dat.bz") assert isItExpectedTrace(tr) == True - tr = loadTrace('tests/trace_test_data/xtrace1.dat.bz2') + tr = loadTrace("tests/trace_test_data/xtrace1.dat.bz2") assert isItExpectedTrace(tr) == True + def test_tryCompressedIfMissing(): - fname = 'tests/trace_test_data/only_compressed_file1.dat' + fname = "tests/trace_test_data/only_compressed_file1.dat" # we check that the guess is working for gzip compressed file (.gz) tr = loadTrace(fname, tryCompressedIfMissing=True) assert isItExpectedTrace(tr) == True - fname = 'tests/trace_test_data/only_compressed_file2.dat' + fname = "tests/trace_test_data/only_compressed_file2.dat" # we check that the guess is working for bzip compressed file (.bz) tr = loadTrace(fname, tryCompressedIfMissing=True) assert isItExpectedTrace(tr) == True - fname = 'tests/trace_test_data/only_compressed_file3.dat' + fname = "tests/trace_test_data/only_compressed_file3.dat" # we check that the guess is working for bzip compressed file (.bz2) tr = loadTrace(fname, tryCompressedIfMissing=True) assert isItExpectedTrace(tr) == True @@ -46,45 +51,50 @@ def test_tryCompressedIfMissing(): with pytest.raises(FileNotFoundError) as exc_info: tr = loadTrace(fname, tryCompressedIfMissing=False) - tr = loadTrace('tests/trace_test_data/xtrace1.dat') + tr = loadTrace("tests/trace_test_data/xtrace1.dat") assert isItExpectedTrace(tr) == True + def test_saving_raw(): import tempfile + with tempfile.NamedTemporaryFile(delete=True) as fp: fp.close() fname = fp.name assert not os.path.exists(fname) - tr = loadTrace('tests/trace_test_data/xtrace1.dat') + tr = loadTrace("tests/trace_test_data/xtrace1.dat") tr.save(fname, compressionmethod=None) trLoaded = loadTrace(fname) assert isItExpectedTrace(trLoaded) os.remove(fname) + def test_saving_gzip(): import tempfile + with tempfile.NamedTemporaryFile(delete=False) as fp: fp.close() - fname = fp.name + '.gz' + fname = fp.name + ".gz" assert not os.path.exists(fname) - tr = loadTrace('tests/trace_test_data/xtrace1.dat') - tr.save(fname, compressionmethod='gzip') + tr = loadTrace("tests/trace_test_data/xtrace1.dat") + tr.save(fname, compressionmethod="gzip") trLoaded = loadTrace(fname) assert isItExpectedTrace(trLoaded) os.remove(fname) + def test_saving_gzip(): import tempfile + with tempfile.NamedTemporaryFile(delete=False) as fp: fp.close() - fname = fp.name + '.bz' + fname = fp.name + ".bz" assert not os.path.exists(fname) - tr = loadTrace('tests/trace_test_data/xtrace1.dat') - tr.save(fname, compressionmethod='bzip') + tr = loadTrace("tests/trace_test_data/xtrace1.dat") + tr.save(fname, compressionmethod="bzip") trLoaded = loadTrace(fname) assert isItExpectedTrace(trLoaded) os.remove(fname) - |