Skip to content

Commit

Permalink
adds test for ziped tdm
Browse files Browse the repository at this point in the history
  • Loading branch information
domna committed Feb 4, 2022
1 parent 152e05f commit 1234aa5
Show file tree
Hide file tree
Showing 9 changed files with 33,999 additions and 4 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ url = https://github.com/domna/tdm_loader
project_urls =
Source = https://github.com/domna/tdm_loader
Download = https://github.com/domna/tdm_loader/releases
Documentation = https://tdm-loader.readthedocs.io/en/latest/
Changelog = https://github.com/domna/tdm_loader/blob/master/CHANGELOG.md
Tracker = https://github.com/domna/tdm_loader/issues
platforms = any
Expand Down
6 changes: 3 additions & 3 deletions tdm_loader/tdm_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ def __init__(self, tdm_path, tdx_path="", encoding="utf-8"):

if zipfile.is_zipfile(tdm_path):
with zipfile.ZipFile(tdm_path) as zipf:
if len(zipf.nameslist()) == 0:
if len(zipf.namelist()) == 0:
raise zipfile.BadZipFile(
f"The compressed file {tdm_path} does not contain any readable files."
)
with zipf.open(zip.namelist()[0]).read().decode(encoding) as file:
self._root = ElementTree.parse(io.StringIO(file)).getroot()
with zipf.open(zipf.namelist()[0]) as file:
self._root = ElementTree.parse(file).getroot()
else:
with open(tdm_path, "r", encoding=encoding) as file:
self._root = ElementTree.parse(file).getroot()
Expand Down
1 change: 0 additions & 1 deletion tdm_loader/tests/test_non_zip_tdm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Unittests for tdm_loader"""
import os
from distutils import dir_util
import pytest
import numpy as np

Expand Down
49 changes: 49 additions & 0 deletions tdm_loader/tests/test_zip_tdm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Tests zip based tdm files to work with tdm_loader"""
import os
import pytest
import numpy as np
from numpy.testing import assert_array_equal

import tdm_loader as tdm


@pytest.fixture(scope="module")
def get_file_dir(request):
"""Fixture for loading the supplementary test files directory"""
filename = request.module.__file__
test_dir, _ = os.path.splitext(filename)
return test_dir


@pytest.fixture(scope="module")
def tdm_file(get_file_dir):
"""Fixture for loading a test tdm file"""
path = f"{get_file_dir}/2021-02-26_07-55-01.TDM"
data = tdm.OpenFile(str(path))
return data


def test_explicit_sequence_representation(get_file_dir, tdm_file):
"""Handles explicit sequence representation channels correctly"""
print(f"{get_file_dir}/channel15.txt")
assert_array_equal(
tdm_file.channel(1, 5), np.loadtxt(f"{get_file_dir}/channel15.txt")
)
assert tdm_file.channel_name(1, 5) == "eps_HAC_RE_CIT_UN_c_Offset"


def test_linear_implicit_repr(get_file_dir, tdm_file):
"""Handles linear_implicit sequence representation correctly"""
assert_array_equal(
tdm_file.channel(0, 1), np.loadtxt(f"{get_file_dir}/channel01.txt")
)
assert tdm_file.channel_name(0, 1) == "Zeit_[200Hz]-abs"
assert tdm_file.channel(0, 1).shape == (11316,)


def test_raw_linear_repr(get_file_dir, tdm_file):
"""Handles linear_implicit sequence representation correctly"""
assert tdm_file.channel_name(0, 15) == "F___Zylinder_02"
assert_array_equal(
tdm_file.channel(0, 15), np.loadtxt(f"{get_file_dir}/channel015.txt")
)
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 1234aa5

Please sign in to comment.