Skip to content

Commit

Permalink
ENH: Catch warning when loaded text file contains no data in test
Browse files Browse the repository at this point in the history
Catch warning when loaded text file contains no data in test.

Fixes:
```
nireports/tests/test_reportlets.py::test_plot_melodic_components
  /home/runner/work/nireports/nireports/nireports/reportlets/xca.py:128:
   UserWarning: loadtxt: input contained no data:
    "/tmp/pytest-of-runner/pytest-0/popen-gw0/test_plot_melodic_components0/noise_none.csv"
    noise_components = np.loadtxt(noise_components_file, dtype=int, delimiter=",", ndmin=1)
```

raised for example in:
https://github.com/nipreps/nireports/actions/runs/12681153218/job/35344304375#step:12:347
  • Loading branch information
jhlegarreta committed Jan 11, 2025
1 parent eb3832c commit 4c7735b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions nireports/tests/test_reportlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import contextlib
import os
import warnings
from itertools import permutations
from pathlib import Path

Expand Down Expand Up @@ -237,14 +238,20 @@ def test_plot_melodic_components(tmp_path, outdir):
out_file=all_noise,
)
# run command with no noise components
plot_melodic_components(
str(melodic_dir),
in_fname,
tr=2.0,
report_mask=report_fname,
noise_components_file=nocomps_file,
out_file=no_noise,
)
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
message="loadtxt: input contained no data",
category=UserWarning,
)
plot_melodic_components(
str(melodic_dir),
in_fname,
tr=2.0,
report_mask=report_fname,
noise_components_file=nocomps_file,
out_file=no_noise,
)

# run command without noise components file
plot_melodic_components(
Expand Down

0 comments on commit 4c7735b

Please sign in to comment.