Skip to content

Commit a078a4b

Browse files
committed
Refactor I/O tests to handle warnings and remove redundant print statements
1 parent ae8edfb commit a078a4b

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

cdl/tests/sigima_tests/common/io1_unit_test.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from __future__ import annotations
1010

11+
import warnings
12+
1113
import numpy as np
1214
import pytest
1315
from guidata.qthelpers import qt_app_context
@@ -28,15 +30,18 @@ def __read_objs(fname: str) -> list[ImageObj] | list[SignalObj]:
2830
for obj in objs:
2931
if np.all(np.isnan(obj.data)):
3032
raise ValueError("Data is all NaNs")
33+
for obj in objs:
34+
# Ignore warnings for complex numbers (workaround for guidata)
35+
with np.errstate(all="ignore"), warnings.catch_warnings():
36+
warnings.simplefilter("ignore", category=RuntimeWarning)
37+
execenv.print(obj)
3138
return objs
3239

3340

3441
@helpers.try_open_test_data("Testing TXT file reader", "*.txt")
3542
def open_txt(fname: str | None = None) -> None:
3643
"""Testing TXT files"""
3744
objs = __read_objs(fname)
38-
for obj in objs:
39-
execenv.print(obj)
4045
if guiutils.is_gui_enabled():
4146
from sigima_.tests import vistools # pylint: disable=import-outside-toplevel
4247

@@ -47,8 +52,6 @@ def open_txt(fname: str | None = None) -> None:
4752
def open_csv(fname: str | None = None) -> None:
4853
"""Testing CSV files"""
4954
objs = __read_objs(fname)
50-
for obj in objs:
51-
execenv.print(obj)
5255
if guiutils.is_gui_enabled():
5356
from sigima_.tests import vistools # pylint: disable=import-outside-toplevel
5457

@@ -59,8 +62,6 @@ def open_csv(fname: str | None = None) -> None:
5962
def open_mat(fname: str | None = None) -> None:
6063
"""Testing MAT files"""
6164
objs = __read_objs(fname)
62-
for obj in objs:
63-
execenv.print(obj)
6465
if guiutils.is_gui_enabled():
6566
from sigima_.tests import vistools # pylint: disable=import-outside-toplevel
6667

0 commit comments

Comments
 (0)