robotpy / robotpy-commands-v2

Python implementation of the WPILib Command Framework (2020+)
Other
2 stars 14 forks source link

Fix SelectCommand with enums #18

Closed auscompgeek closed 1 year ago

auscompgeek commented 1 year ago

I'm also seeing this nondeterministically fail on my Mac with Python 3.10.9 :confused:


=================================== FAILURES ===================================
___________________________ test_select_command_enum ___________________________

scheduler = <commands2._impl.CommandScheduler object at 0x11194ab70>

    def test_select_command_enum(scheduler: commands2.CommandScheduler):
        c = ConditionHolder()

        def _assert_false():
            assert False

        class Selector(enum.Enum):
            ONE = enum.auto()
            TWO = enum.auto()
            THREE = enum.auto()

        cmd1 = commands2.RunCommand(_assert_false)
        cmd2 = commands2.RunCommand(c.setTrue)
        cmd3 = commands2.RunCommand(_assert_false)

        sc = commands2.SelectCommand(lambda: Selector.TWO, [
            (Selector.ONE, cmd1),
            (Selector.TWO, cmd2),
            (Selector.THREE, cmd3),
        ])

        scheduler.schedule(sc)
        scheduler.run()

>       assert c.cond
E       assert False
E        +  where False = <util.ConditionHolder object at 0x11365e8f0>.cond

tests/test_select_command.py:66: AssertionError
=============================== warnings summary ===============================
tests/test_select_command.py::test_select_command_enum
  ~/dev/frc/robotpy/robotpy-commands-v2/tests/test_select_command.py:57: DeprecationWarning: NotImplemented should not be used in a boolean context
    sc = commands2.SelectCommand(lambda: Selector.TWO, [

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/test_select_command.py::test_select_command_enum - assert False
=================== 1 failed, 35 passed, 1 warning in 0.20s ====================
auscompgeek commented 1 year ago

Okay, the DeprecationWarning gave me a hint, turns out object.__eq__(a, b) returns NotImplemented if a is not b.

auscompgeek commented 1 year ago

This raises an important question though... why did the test not crash in the _assert_false?