How to use the pyfrc.test_support.fake_time.FakeTime function in pyfrc

To help you get started, we’ve selected a few pyfrc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github robotpy / pyfrc / tests / test_faketime.py View on Github external
def test_faketime_3():
    """Test calling the step function with varying lengths"""

    wpilib.DriverStation._reset()

    ft = FakeTime()
    ft.initialize()
    ft.set_time_limit(5)

    sc = StepChecker()
    ft.ds_cond._on_step = sc.on_step

    ft.increment_time_by(0.005)
    ft.increment_time_by(0.01)
    ft.increment_time_by(0.02)
    ft.increment_time_by(0.03)
    ft.increment_time_by(0.04)
    ft.increment_time_by(0.05)

    tm = 0.005 + 0.01 + 0.02 + 0.03 + 0.04 + 0.05
    assert_float(ft.get(), tm)
    assert_float(sc.expected, 0.16)
github robotpy / pyfrc / tests / test_faketime.py View on Github external
def test_faketime_2():
    """Test calling the step function """

    wpilib.DriverStation._reset()

    ft = FakeTime()
    ft.initialize()
    ft.set_time_limit(5)

    sc = StepChecker()
    ft.ds_cond._on_step = sc.on_step

    ft.increment_new_packet()
    ft.increment_new_packet()
    ft.increment_new_packet()

    assert_float(ft.get(), 0.06)
    assert_float(sc.expected, 0.06 + 0.02)
github robotpy / pyfrc / tests / test_faketime.py View on Github external
def test_faketime_1():
    """Test expiration"""

    wpilib.DriverStation._reset()

    ft = FakeTime()
    ft.initialize()
    ft.set_time_limit(5)

    with pytest.raises(TestRanTooLong):
        ft.increment_time_by(10)
github robotpy / pyfrc / pyfrc / test_support / pytest_plugin.py View on Github external
def __init__(self, robot_class, robot_file, robot_path):
        self.robot_class = robot_class

        self._robot_file = robot_file
        self._robot_path = robot_path

        # Setup fake time
        self._fake_time = fake_time.FakeTime()

        # Setup control instance
        self._control = None

        self._started = False

        # Setup the hal hooks so we can control time
        # -> The hook doesn't have any state, so we initialize it only once
        hal_impl.functions.hooks = pyfrc_fake_hooks.PyFrcFakeHooks(self._fake_time)
github robotpy / pyfrc / tests / test_faketime.py View on Github external
def test_faketime_threading():
    """Test that threads are being caught and paused correctly."""

    wpilib.DriverStation._reset()

    ft = FakeTime()
    ft.initialize()
    incr_thread100hz = IncrementingThread(0.01, ft)
    incr_thread20hz = IncrementingThread(0.05, ft)
    incr_thread100hz.start()
    incr_thread20hz.start()

    for _ in range(4):
        ft.increment_new_packet()

    assert incr_thread100hz.counter == 8
    assert incr_thread20hz.counter == 1

    ft.teardown()
    incr_thread100hz.cancel()
    incr_thread20hz.cancel()
github robotpy / pyfrc / tests / test_faketime.py View on Github external
def test_faketime_dying_thread():
    """Test that dying threads are handled properly"""

    wpilib.DriverStation._reset()

    ft = FakeTime()
    ft.initialize()

    dt = DyingThread(ft)
    dt.start()

    for _ in range(4):
        ft.increment_new_packet()

    assert dt._died == True
github robotpy / pyfrc / tests / test_faketime.py View on Github external
def test_faketime_infinite_loop_thread():
    """Test that infinite loops are detected"""

    wpilib.DriverStation._reset()

    ft = FakeTime()
    ft._freeze_detect_threshold = 5
    ft.initialize()

    it = InfiniteLoopThread(ft)
    it.start()

    with pytest.raises(TestFroze):
        ft.increment_new_packet()
        ft.increment_new_packet()

    with it.cond:
        it.cond.notify_all()