Add loop_from_file and timestamp_from_file functions

to extract loop_index and timestamp from the temporary _LOOP.txt and .mpl files during MPRfile initialization
Added unit tests but cannot upload test files due to LFS quota exceeded

Edited by Chris Kerr to fix flake8 warnings and resolve my comments from
the original PR https://github.com/echemdata/galvani/pull/102
This commit is contained in:
Jonathan Schillings
2024-02-07 17:52:40 +01:00
committed by Chris Kerr
parent baec8934b8
commit 0d684af470
2 changed files with 113 additions and 0 deletions

View File

@@ -358,3 +358,25 @@ def test_MPR_matches_MPT_v1150(testdata_dir, basename_v1150):
mpr = MPRfile(binpath)
mpt, comments = MPTfile(txtpath, encoding="latin1")
assert_MPR_matches_MPT_v2(mpr, mpt, comments)
def test_loop_from_file(testdata_dir):
"""Check if the loop_index is correctly extracted from the _LOOP.txt file
"""
mpr = MPRfile(os.path.join(testdata_dir, "running", "running_OCV.mpr"))
if mpr.loop_index is None:
raise AssertionError("No loop_index found")
elif not len(mpr.loop_index) == 4:
raise AssertionError("loop_index is not the right size")
elif not (mpr.loop_index == [0, 4, 8, 11]).all():
raise AssertionError("loop_index values are wrong")
def test_timestamp_from_file(testdata_dir):
"""Check if the loop_index is correctly extracted from the _LOOP.txt file
"""
mpr = MPRfile(os.path.join(testdata_dir, "running", "running_OCV.mpr"))
if not hasattr(mpr, "timestamp"):
raise AssertionError("No timestamp found")
elif not mpr.timestamp.timestamp() == 1707299985.908:
raise AssertionError("timestamp value is wrong")