Skip to content

Commit 4cd8be6

Browse files
committed
Run black, add to test requirements.
Signed-off-by: Mike Stitt <mike@stitt.cc>
1 parent 9872329 commit 4cd8be6

File tree

2 files changed

+85
-30
lines changed

2 files changed

+85
-30
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pytest
2+
pytest-reraise

subprojects/robotpy-wpilib/tests/test_poc_timedrobot.py

Lines changed: 84 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ def test_iterative_again(self, getTestController, robot_with_sim_setup_teardown)
414414
assert robot_with_sim_setup_teardown.robotInitialized == True
415415
assert robot_with_sim_setup_teardown.robotPeriodicCount > 0
416416

417+
417418
class TimedRobotPyExpectsException(TimedRobotPy):
418419
def startCompetition(self) -> None:
419420
hasAssertionError = False
@@ -424,6 +425,7 @@ def startCompetition(self) -> None:
424425
print(f"TimedRobotPyExpectsException hasAssertionError={hasAssertionError}")
425426
assert hasAssertionError
426427

428+
427429
class TimedRobotPyDoNotExpectException(TimedRobotPy):
428430
def startCompetition(self) -> None:
429431
hasAssertionError = False
@@ -437,17 +439,20 @@ def startCompetition(self) -> None:
437439

438440
from wpilib import RobotController
439441

442+
440443
def printEntryAndExit(func):
441444
def wrapper(*args, **kwargs):
442-
#name = inspect.currentframe().f_code.co_name
445+
# name = inspect.currentframe().f_code.co_name
443446
name = func.__name__
444447
print(f"Enter:{name} at {RobotController.getFPGATime()/1000_000.0:.3f}")
445448
result = func(*args, **kwargs)
446449
print(f"Exit_:{name} at {RobotController.getFPGATime()/1000_000.0:.3f}")
447450
return result
451+
448452
return wrapper
449453

450-
class MyRobotRobotDefaultPass():
454+
455+
class MyRobotRobotDefaultPass:
451456

452457
@printEntryAndExit
453458
def robotInit(self):
@@ -490,65 +495,88 @@ def _simulationPeriodic(self):
490495
pass
491496

492497

493-
494-
class MyRobotRobotInitFails():
498+
class MyRobotRobotInitFails:
495499
def robotInit(self):
496500
assert False
497501

498-
class MyRobotRobotPeriodicFails():
502+
503+
class MyRobotRobotPeriodicFails:
499504
def robotPeriodic(self):
500505
assert False
501506

502-
class MyRobotAutonomousInitFails():
507+
508+
class MyRobotAutonomousInitFails:
503509
def autonomousInit(self):
504510
assert False
505511

506-
class MyRobotAutonomousPeriodicFails():
512+
513+
class MyRobotAutonomousPeriodicFails:
507514
def autonomousPeriodic(self):
508515
assert False
509516

510-
class MyRobotAutonomousExitFails():
517+
518+
class MyRobotAutonomousExitFails:
511519
def autonomousExit(self):
512520
assert False
513521

514-
class MyRobotTeleopInitFails():
522+
523+
class MyRobotTeleopInitFails:
515524
def teleopInit(self):
516525
assert False
517526

518-
class MyRobotTeleopPeriodicFails():
527+
528+
class MyRobotTeleopPeriodicFails:
519529
def teleopPeriodic(self):
520530
assert False
521531

522-
class MyRobotDisabledPeriodicFails():
532+
533+
class MyRobotDisabledPeriodicFails:
523534
def disabledPeriodic(self):
524535
assert False
525536

526-
class MyRobotDisabledInitFails():
537+
538+
class MyRobotDisabledInitFails:
527539
def disabledInit(self):
528540
assert False
529541

530-
class MyRobotTestInitFails():
542+
543+
class MyRobotTestInitFails:
531544
def testInit(self):
532545
assert False
533546

534-
class MyRobotTestPeriodicFails():
547+
548+
class MyRobotTestPeriodicFails:
535549
def testPeriodic(self):
536550
assert False
537551

538552

539-
540-
@pytest.mark.parametrize("myRobotAddMethods, timedRobotExpectation, _expectFinished, _autonomous, _test", [
553+
@pytest.mark.parametrize(
554+
"myRobotAddMethods, timedRobotExpectation, _expectFinished, _autonomous, _test",
555+
[
541556
(MyRobotRobotDefaultPass, TimedRobotPyDoNotExpectException, True, True, False),
542557
(MyRobotRobotInitFails, TimedRobotPyExpectsException, False, True, False),
543558
(MyRobotAutonomousInitFails, TimedRobotPyExpectsException, False, True, False),
544-
(MyRobotAutonomousPeriodicFails, TimedRobotPyExpectsException, False, True, False),
545-
(MyRobotAutonomousExitFails, TimedRobotPyExpectsException, False, True, False)
546-
]
559+
(
560+
MyRobotAutonomousPeriodicFails,
561+
TimedRobotPyExpectsException,
562+
False,
563+
True,
564+
False,
565+
),
566+
(MyRobotAutonomousExitFails, TimedRobotPyExpectsException, False, True, False),
567+
],
547568
)
548569
class TestCanThrowExceptions:
549570
@classmethod
550571
@pytest.fixture(scope="function", autouse=False)
551-
def myrobot_class(cls, myRobotAddMethods, timedRobotExpectation, _expectFinished, _autonomous, _test) -> type[TimedRobotPy]:
572+
def myrobot_class(
573+
cls,
574+
myRobotAddMethods,
575+
timedRobotExpectation,
576+
_expectFinished,
577+
_autonomous,
578+
_test,
579+
) -> type[TimedRobotPy]:
552580
class MyRobot(myRobotAddMethods, timedRobotExpectation):
553581

554582
@printEntryAndExit
@@ -563,31 +591,57 @@ def endCompetition(self):
563591

564592
@classmethod
565593
@pytest.fixture(scope="function", autouse=False)
566-
def expectFinished(cls, myRobotAddMethods, timedRobotExpectation, _expectFinished, _autonomous, _test) -> bool:
594+
def expectFinished(
595+
cls,
596+
myRobotAddMethods,
597+
timedRobotExpectation,
598+
_expectFinished,
599+
_autonomous,
600+
_test,
601+
) -> bool:
567602
return _expectFinished
568603

569604
@classmethod
570605
@pytest.fixture(scope="function", autouse=False)
571-
def autonomous(cls, myRobotAddMethods, timedRobotExpectation, _expectFinished, _autonomous, _test) -> bool:
606+
def autonomous(
607+
cls,
608+
myRobotAddMethods,
609+
timedRobotExpectation,
610+
_expectFinished,
611+
_autonomous,
612+
_test,
613+
) -> bool:
572614
return _autonomous
573615

574616
@classmethod
575617
@pytest.fixture(scope="function", autouse=False)
576-
def test(cls, myRobotAddMethods, timedRobotExpectation, _expectFinished, _autonomous, _test) -> bool:
618+
def test(
619+
cls,
620+
myRobotAddMethods,
621+
timedRobotExpectation,
622+
_expectFinished,
623+
_autonomous,
624+
_test,
625+
) -> bool:
577626
return _test
578627

579-
580-
def test_robot_mode_with_exceptions(self, getTestController, robot_with_sim_setup_teardown, autonomous, test):
628+
def test_robot_mode_with_exceptions(
629+
self, getTestController, robot_with_sim_setup_teardown, autonomous, test
630+
):
581631
with getTestController.run_robot():
582632
periodS = robot_with_sim_setup_teardown.getPeriod()
583633
# Run disabled for a short period
584634
print(f"periodS={periodS} or {periodS*1.5}")
585-
getTestController.step_timing(seconds=periodS*1.5, autonomous=autonomous, test=test, enabled=False)
635+
getTestController.step_timing(
636+
seconds=periodS * 1.5, autonomous=autonomous, test=test, enabled=False
637+
)
586638

587639
# Run in desired mode for 1 period
588-
getTestController.step_timing(seconds=periodS, autonomous=autonomous, test=test, enabled=True)
640+
getTestController.step_timing(
641+
seconds=periodS, autonomous=autonomous, test=test, enabled=True
642+
)
589643

590644
# Disabled for 1 period
591-
getTestController.step_timing(seconds=periodS, autonomous=autonomous, test=test, enabled=False)
592-
593-
645+
getTestController.step_timing(
646+
seconds=periodS, autonomous=autonomous, test=test, enabled=False
647+
)

0 commit comments

Comments
 (0)