From 9e0cffd2a6ff38f84b7c813a9bfad87bde0938d3 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Thu, 20 Jun 2024 00:23:45 -0400 Subject: added test for Trace saving in raw and compressed forms --- tests/test_trace.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/test_trace.py b/tests/test_trace.py index 65a9f5b..e811831 100644 --- a/tests/test_trace.py +++ b/tests/test_trace.py @@ -1,6 +1,7 @@ import pytest from qolab.data.trace import loadTrace import numpy as np +import os def isItExpectedTrace(tr): cfg = tr.getConfig() @@ -45,3 +46,45 @@ def test_tryCompressedIfMissing(): with pytest.raises(FileNotFoundError) as exc_info: tr = loadTrace(fname, tryCompressedIfMissing=False) + 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.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' + assert not os.path.exists(fname) + + 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' + assert not os.path.exists(fname) + + tr = loadTrace('tests/trace_test_data/xtrace1.dat') + tr.save(fname, compressionmethod='bzip') + trLoaded = loadTrace(fname) + assert isItExpectedTrace(trLoaded) + os.remove(fname) + -- cgit v1.2.3