Skip to content

Commit c939d8c

Browse files
Merge pull request #79 from MatthewSZhang/test-print
TST test printed message
2 parents 55f6e35 + 594a660 commit c939d8c

File tree

7 files changed

+1301
-1081
lines changed

7 files changed

+1301
-1081
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
steps:
2323
- uses: actions/checkout@v4
2424
- name: Build wheels
25-
uses: pypa/[email protected].2
25+
uses: pypa/[email protected].3
2626
env:
2727
CIBW_BUILD: cp3*-*
2828
CIBW_SKIP: pp* *i686* *musllinux* *-macosx_universal2 *-manylinux_ppc64le *-manylinux_s390x
@@ -31,8 +31,6 @@ jobs:
3131
CIBW_ARCHS_MACOS: x86_64 arm64
3232
CIBW_ARCHS_WINDOWS: auto64
3333
CIBW_BEFORE_ALL_LINUX: yum install -y ninja-build python3-devel
34-
CIBW_BEFORE_ALL_WINDOWS: choco install ninja
35-
CIBW_BEFORE_ALL_MACOS: brew install ninja
3634
# Needed on Windows CI to compile with Visual Studio compiler
3735
# otherwise Meson detects a MINGW64 platform and use MINGW64
3836
# toolchain

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
- name: Re-install local
1818
run: |
19-
pixi reinstall --frozen fastcan
19+
pixi reinstall -e lint --frozen fastcan
2020
2121
- name: Lint with ruff
2222
run: |

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ jobs:
2828

2929
- name: Re-install local
3030
run: |
31-
pixi reinstall --frozen fastcan
31+
# Needed on Windows CI to compile with Visual Studio compiler
32+
# otherwise Meson detects a MINGW64 platform and use MINGW64
33+
# toolchain
34+
pixi reinstall -e dev --frozen fastcan -- -Csetup-args=--vsenv
3235
3336
- name: Test with pytest
3437
run: |

pixi.lock

Lines changed: 1247 additions & 1074 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ mypy = "*"
7575

7676
[tool.pixi.feature.build.dependencies]
7777
python-build = "*"
78+
pip = "*"
7879

7980
[tool.pixi.feature.nogil.dependencies]
8081
python-freethreading = "*"
@@ -104,6 +105,13 @@ test-coverage = { cmd = "rm -rf .coverage && pytest --cov-report $FMT --cov=$PAC
104105
[tool.pixi.feature.build.tasks]
105106
build-wheel = "rm -rf dist && python -m build -wnx -Cinstall-args=--tags=runtime,python-runtime,devel"
106107
build-sdist = "rm -rf dist && python -m build --sdist"
108+
rebuild = "rm -rf build && pip install --no-deps --force-reinstall -e ."
109+
110+
# Needed on Windows CI to compile with Visual Studio compiler
111+
# otherwise Meson detects a MINGW64 platform and use MINGW64
112+
# toolchain
113+
[tool.pixi.feature.build.target.win-64.tasks]
114+
rebuild = "rm -rf build && pip install --no-deps --force-reinstall -e . -Csetup-args=--vsenv"
107115

108116
[tool.pixi.feature.fmt.tasks]
109117
fmt = { cmd = "black .", cwd = "fastcan" }

tests/__init__.py

Whitespace-only changes.

tests/test_narx.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ def test_narx(nan, multi_output):
178178
y_hat = narx_array_init_msa.predict(X, y_init=y_init)
179179
assert_array_equal(y_hat[:narx_array_init_msa.max_delay_], y_init)
180180

181-
print_narx(narx_array_init_msa)
182-
183181
with pytest.raises(ValueError, match=r"`coef_init` should have the shape of .*"):
184182
narx_array_init_msa.fit(X, y, coef_init=np.zeros(narx_osa_msa_coef.size))
185183

@@ -492,3 +490,43 @@ def test_tp2fd():
492490
poly_ids[-1][-1] = 5
493491
with pytest.raises(ValueError, match=r"The element x of poly_ids should.*"):
494492
_, _ = tp2fd(time_shift_ids, poly_ids)
493+
494+
def test_print_narx(capsys):
495+
X = np.random.rand(10, 2)
496+
y = np.random.rand(10, 2)
497+
feat_ids = np.array([[0, 1], [1, 2]])
498+
delay_ids = np.array([[1, 0], [2, 2]])
499+
500+
narx = NARX(
501+
feat_ids=feat_ids,
502+
delay_ids=delay_ids,
503+
output_ids=[0, 1],
504+
)
505+
narx.fit(X, y)
506+
print_narx(narx)
507+
captured = capsys.readouterr()
508+
# Check if the header is present in the output
509+
assert "| yid | Term | Coef |" in captured.out
510+
# Check if the intercept line for yid 0 is present
511+
assert "| 0 | Intercept |" in captured.out
512+
# Check if the intercept line for yid 1 is present
513+
assert "| 1 | Intercept |" in captured.out
514+
# Check if the term line for yid 0 is present
515+
assert "| 0 | X[k-1,0]*X[k,1] |" in captured.out
516+
# Check if the term line for yid 1 is present
517+
assert "| 1 |X[k-2,1]*y_hat[k-2,0]|" in captured.out
518+
519+
520+
def test_make_narx_refine_print(capsys):
521+
X = np.random.rand(10, 2)
522+
y = np.random.rand(10, 2)
523+
_ = make_narx(
524+
X,
525+
y,
526+
n_terms_to_select=2,
527+
max_delay=2,
528+
poly_degree=2,
529+
refine_drop=1,
530+
)
531+
captured = capsys.readouterr()
532+
assert "No. of iterations: " in captured.out

0 commit comments

Comments
 (0)