diff --git a/apriltag/src/main/python/pyproject.toml b/apriltag/src/main/python/pyproject.toml index 90e6ba7be5..0aefca734b 100644 --- a/apriltag/src/main/python/pyproject.toml +++ b/apriltag/src/main/python/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "semiwrap~=0.3.0", - "hatch-meson~=0.1.0", + "hatch-meson~=0.1.2", "hatch-robotpy~=0.2.1", "hatchling", "robotpy-native-apriltag==0.0.0", diff --git a/datalog/src/main/python/pyproject.toml b/datalog/src/main/python/pyproject.toml index 7539b28214..065fb70b76 100644 --- a/datalog/src/main/python/pyproject.toml +++ b/datalog/src/main/python/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "semiwrap~=0.3.0", - "hatch-meson~=0.1.0", + "hatch-meson~=0.1.2", "hatchling", "robotpy-native-datalog==0.0.0", "robotpy-wpiutil==0.0.0" diff --git a/hal/src/main/python/pyproject.toml b/hal/src/main/python/pyproject.toml index 9658a67bcd..3171e17fe2 100644 --- a/hal/src/main/python/pyproject.toml +++ b/hal/src/main/python/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "semiwrap~=0.3.0", - "hatch-meson~=0.1.0", + "hatch-meson~=0.1.2", "hatchling", "pyntcore==0.0.0", "robotpy-native-wpihal==0.0.0", diff --git a/ntcore/src/main/python/devtools/gen-pubsub.py b/ntcore/src/main/python/devtools/gen-pubsub.py index dff317d1c5..753b56eeea 100755 --- a/ntcore/src/main/python/devtools/gen-pubsub.py +++ b/ntcore/src/main/python/devtools/gen-pubsub.py @@ -43,8 +43,7 @@ if __name__ == "__main__": sphinxify.process_raw("\n".join(docs)).lstrip().splitlines() ) - print( - f""" + print(f""" // autogenerated by gen-pubsub.py .def(py::init([]( {paramstr} @@ -59,7 +58,4 @@ if __name__ == "__main__": {doc} )" ) - """.removeprefix( - "\n" - ).rstrip() - ) + """.removeprefix("\n").rstrip()) diff --git a/ntcore/src/main/python/pyproject.toml b/ntcore/src/main/python/pyproject.toml index 7f8db55348..75283e5ca8 100644 --- a/ntcore/src/main/python/pyproject.toml +++ b/ntcore/src/main/python/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "semiwrap~=0.3.0", - "hatch-meson~=0.1.0", + "hatch-meson~=0.1.2", "hatch-robotpy~=0.2.1", "hatchling", "robotpy-native-ntcore==0.0.0", diff --git a/robotpyExamples/I2CCommunication/robot.py b/robotpyExamples/I2CCommunication/robot.py index ed902c5157..a118d785a0 100755 --- a/robotpyExamples/I2CCommunication/robot.py +++ b/robotpyExamples/I2CCommunication/robot.py @@ -43,9 +43,7 @@ class MyRobot(wpilib.TimedRobot): allianceString = "U" alliance = wpilib.MatchState.getAlliance() if alliance is not None: - allianceString = ( - "R" if alliance == wpilib.Alliance.RED else "B" - ) + allianceString = "R" if alliance == wpilib.Alliance.RED else "B" enabledString = "E" if wpilib.RobotState.isEnabled() else "D" autoString = "A" if wpilib.RobotState.isAutonomous() else "T" diff --git a/romiVendordep/src/main/python/pyproject.toml b/romiVendordep/src/main/python/pyproject.toml index d87ff43461..586b4fedd3 100644 --- a/romiVendordep/src/main/python/pyproject.toml +++ b/romiVendordep/src/main/python/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "semiwrap~=0.3.0", - "hatch-meson~=0.1.0", + "hatch-meson~=0.1.2", "hatch-robotpy~=0.2.1", "hatchling", "robotpy-native-romi==0.0.0", diff --git a/simulation/halsim_gui/src/main/python/pyproject.toml b/simulation/halsim_gui/src/main/python/pyproject.toml index a373952404..4f425830d2 100644 --- a/simulation/halsim_gui/src/main/python/pyproject.toml +++ b/simulation/halsim_gui/src/main/python/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "semiwrap~=0.3.0", - "hatch-meson~=0.1.0", + "hatch-meson~=0.1.2", "hatch-robotpy~=0.2.1", "hatchling", "robotpy-wpiutil==0.0.0", diff --git a/wpilibc/src/main/python/pyproject.toml b/wpilibc/src/main/python/pyproject.toml index b82e07fcc7..62baa9eb9f 100644 --- a/wpilibc/src/main/python/pyproject.toml +++ b/wpilibc/src/main/python/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "semiwrap~=0.3.0", - "hatch-meson~=0.1.0", + "hatch-meson~=0.1.2", "hatch-robotpy~=0.2.1", "hatchling", "robotpy-native-wpilib==0.0.0", diff --git a/wpilibc/src/main/python/wpilib/_impl/cli_test.py b/wpilibc/src/main/python/wpilib/_impl/cli_test.py index 883d44d447..3fe3f634b1 100644 --- a/wpilibc/src/main/python/wpilib/_impl/cli_test.py +++ b/wpilibc/src/main/python/wpilib/_impl/cli_test.py @@ -90,7 +90,11 @@ class RobotTest: pyproject_path = project_path / "pyproject.toml" if pyproject_path.exists(): with open(pyproject_path, "rb") as fp: - d = tomllib.load(fp) + try: + d = tomllib.load(fp) + except tomllib.TOMLDecodeError as e: + print(f"ERROR: {pyproject_path}: {e}", file=sys.stderr) + return 1 try: v = d["tool"]["robotpy"]["testing"]["isolated"] @@ -98,9 +102,12 @@ class RobotTest: pass else: if not isinstance(v, bool): - raise ValueError( - f"tool.robotpy.testing.isolated must be a boolean value (got {v})" + print( + f"ERROR: {pyproject_path}: tool.robotpy.testing.isolated " + f"must be a boolean value (got {v!r})", + file=sys.stderr, ) + return 1 isolated = v @@ -162,7 +169,10 @@ class RobotTest: break else: if not builtin: - print("ERROR: Cannot run robot tests, as test directory was not found!") + print( + "ERROR: Cannot run robot tests, as test directory was not found!", + file=sys.stderr, + ) retv = self._no_tests(main_file, project_path) return 1 @@ -194,8 +204,11 @@ class RobotTest: # requires pytest 2.8.x if retv == 5: - print() - print("ERROR: a tests directory was found, but no tests were defined") + print(file=sys.stderr) + print( + "ERROR: a tests directory was found, but no tests were defined", + file=sys.stderr, + ) retv = self._no_tests(main_file, project_path, retv) return retv diff --git a/wpilibc/src/test/python/test_alert.py b/wpilibc/src/test/python/test_alert.py index 7c791a5700..7b8c61dd60 100644 --- a/wpilibc/src/test/python/test_alert.py +++ b/wpilibc/src/test/python/test_alert.py @@ -18,11 +18,7 @@ def group_name(request): def get_active_alerts(level: Alert.Level) -> T.List[str]: - return [ - a.text - for a in AlertSim.getAll() - if a.level == level and a.isActive() - ] + return [a.text for a in AlertSim.getAll() if a.level == level and a.isActive()] def is_alert_active(text: str, level: Alert.Level): @@ -144,6 +140,7 @@ def test_set_text_while_set(group_name): assert not is_alert_active("BEFORE", Alert.Level.LOW) assert is_alert_active("AFTER", Alert.Level.LOW) + def test_get_active(group_name): with ( Alert(group_name, "A", Alert.Level.HIGH) as a, @@ -154,10 +151,10 @@ def test_get_active(group_name): a.set(True) b.set(True) c.set(False) - + active = AlertSim.getActive() allAlerts = AlertSim.getAll() - + assert len(active) == 2 assert len(allAlerts) == 3 @@ -169,4 +166,4 @@ def test_get_active(group_name): allAlerts = AlertSim.getAll() assert len(active) == 1 assert len(allAlerts) == 3 - assert active[0].text == "B" \ No newline at end of file + assert active[0].text == "B" diff --git a/wpilibc/src/test/python/test_opmode_robot.py b/wpilibc/src/test/python/test_opmode_robot.py index db3debbf76..1498ea1161 100644 --- a/wpilibc/src/test/python/test_opmode_robot.py +++ b/wpilibc/src/test/python/test_opmode_robot.py @@ -41,6 +41,7 @@ class MockRobot(OpModeRobot): super().__init__() self.driver_station_connected_count = 0 self.none_periodic_count = 0 + self.periodic_count = 0 def driverStationConnected(self): self.driver_station_connected_count += 1 @@ -48,6 +49,9 @@ class MockRobot(OpModeRobot): def nonePeriodic(self): self.none_periodic_count += 1 + def robotPeriodic(self): + self.periodic_count += 1 + @pytest.fixture(autouse=True) def sim_timing_setup(): @@ -135,8 +139,8 @@ def test_remove_op_mode(): assert options[0].name == "OneArgOpMode" -@pytest.mark.xfail(reason="wpilib bug") -def test_none_periodic(): +@pytest.fixture +def periodic_robot_test_fixture(): class MyMockRobot(MockRobot): def __init__(self): super().__init__() @@ -146,14 +150,40 @@ def test_none_periodic(): robot = MyMockRobot() robot_thread = threading.Thread(target=robot.startCompetition) - robot_thread.daemon = True # Make thread daemon so it doesn't block test exit robot_thread.start() + yield robot + + robot.endCompetition() + robot_thread.join() + + +# @pytest.mark.xfail(reason="wpilib bug") +def test_none_periodic(periodic_robot_test_fixture): + robot = periodic_robot_test_fixture + wsim.waitForProgramStart() + # Time step to get periodic calls on 20 ms robot loop wsim.stepTiming(0.110) - assert robot.none_periodic_count == 2 + assert robot.none_periodic_count == 5 - robot.endCompetition() - robot_thread.join(timeout=1.0) # Add timeout to prevent hanging + +def test_robot_periodic(periodic_robot_test_fixture): + kPeriod = 0.020 # 20 ms + + robot = periodic_robot_test_fixture + + wsim.waitForProgramStart() + + # RobotPeriodic should be called regardless of state + assert robot.periodic_count == 0 + + # Time step to get periodic calls on 20 ms robot loop + wsim.stepTiming(kPeriod) + assert robot.periodic_count == 1 + + # Additional time steps should continue calling RobotPeriodic + wsim.stepTiming(kPeriod) + assert robot.periodic_count == 2 diff --git a/wpimath/src/main/python/pyproject.toml b/wpimath/src/main/python/pyproject.toml index 083ed401ff..c8d62ce5ed 100644 --- a/wpimath/src/main/python/pyproject.toml +++ b/wpimath/src/main/python/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "semiwrap~=0.3.0", - "hatch-meson~=0.1.0", + "hatch-meson~=0.1.2", "hatch-robotpy~=0.2.1", "hatchling", "robotpy-native-wpimath==0.0.0", diff --git a/wpinet/src/main/python/pyproject.toml b/wpinet/src/main/python/pyproject.toml index e3989e65d3..182a508c16 100644 --- a/wpinet/src/main/python/pyproject.toml +++ b/wpinet/src/main/python/pyproject.toml @@ -2,9 +2,9 @@ build-backend = "hatchling.build" requires = [ "semiwrap~=0.3.0", - "hatch-meson~=0.1.0", + "hatch-meson~=0.1.2", "semiwrap~=0.3.0", - "hatch-meson~=0.1.0", + "hatch-meson~=0.1.2", "hatchling", "robotpy-native-wpinet==0.0.0", "robotpy-wpiutil==0.0.0" diff --git a/wpiutil/src/main/python/pyproject.toml b/wpiutil/src/main/python/pyproject.toml index 2a06d0ff18..027183000a 100644 --- a/wpiutil/src/main/python/pyproject.toml +++ b/wpiutil/src/main/python/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "semiwrap~=0.3.0", - "hatch-meson~=0.1.0", + "hatch-meson~=0.1.2", "hatch-robotpy~=0.2.1", "hatchling", "robotpy-native-wpiutil==0.0.0", diff --git a/xrpVendordep/src/main/python/pyproject.toml b/xrpVendordep/src/main/python/pyproject.toml index 933afffc1a..9d710f3764 100644 --- a/xrpVendordep/src/main/python/pyproject.toml +++ b/xrpVendordep/src/main/python/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "semiwrap~=0.3.0", - "hatch-meson~=0.1.0", + "hatch-meson~=0.1.2", "hatch-robotpy~=0.2.1", "hatchling", "robotpy-native-xrp==0.0.0",