Skip to content

Commit 53b12e0

Browse files
committed
Add test that _load_robot_class handles incorrectly-cased filenames
1 parent 7653506 commit 53b12e0

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

.github/workflows/dist.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,41 @@ jobs:
5757
name: dist
5858
path: dist
5959

60+
test:
61+
runs-on: ${{ matrix.os }}
62+
strategy:
63+
matrix:
64+
os: ["ubuntu-22.04", "macos-14", "windows-2022"]
65+
66+
steps:
67+
- uses: actions/checkout@v5
68+
69+
- uses: actions/setup-python@v5
70+
with:
71+
python-version: "3.13"
72+
73+
- name: Download build artifacts
74+
uses: actions/download-artifact@v4
75+
with:
76+
name: dist
77+
path: dist
78+
79+
- name: Install
80+
shell: bash
81+
working-directory: dist
82+
run: python -m pip --disable-pip-version-check install *.whl
83+
84+
- name: Install test dependencies
85+
working-directory: tests
86+
run: python -m pip --disable-pip-version-check install -r requirements.txt
87+
88+
- name: Test wheel
89+
working-directory: tests
90+
run: python run_tests.py
91+
6092
publish:
6193
runs-on: ubuntu-latest
62-
needs: [check, check-mypy, build]
94+
needs: [check, check-mypy, build, test]
6395
permissions:
6496
id-token: write
6597
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')

tests/requirements.txt

Whitespace-only changes.

tests/run_tests.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
from os.path import abspath, dirname, join
5+
import sys
6+
import subprocess
7+
8+
if __name__ == "__main__":
9+
root = abspath(dirname(__file__))
10+
os.chdir(root)
11+
12+
# Run pytest
13+
subprocess.check_call([sys.executable, "-m", "pytest"])

tests/test_robot_case.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import sys
2+
import textwrap
3+
4+
import pytest
5+
6+
from robotpy import main
7+
8+
9+
class DummyWpilib:
10+
class RobotBase:
11+
pass
12+
13+
14+
@pytest.fixture(autouse=True)
15+
def mock_wpilib(monkeypatch):
16+
monkeypatch.setitem(sys.modules, "wpilib", DummyWpilib)
17+
18+
19+
def test_load_robot_class_exact_case(tmp_path, monkeypatch, capsys):
20+
# create correct-case file
21+
robot_py = tmp_path / "robot.py"
22+
robot_py.write_text(
23+
textwrap.dedent(
24+
"""
25+
import wpilib
26+
class MyRobot(wpilib.RobotBase):
27+
pass
28+
"""
29+
)
30+
)
31+
32+
monkeypatch.setattr(main, "robot_py_path", robot_py)
33+
34+
# Should pass (exact case)
35+
main._load_robot_class()
36+
37+
# Should fail if incorrect case
38+
wrong_case = tmp_path / "ROBOT.py"
39+
monkeypatch.setattr(main, "robot_py_path", wrong_case)
40+
41+
with pytest.raises(SystemExit):
42+
main._load_robot_class()
43+
err = capsys.readouterr().err
44+
assert "exact case" in err or "does not exist" in err

0 commit comments

Comments
 (0)