@@ -414,6 +414,7 @@ def test_iterative_again(self, getTestController, robot_with_sim_setup_teardown)
414
414
assert robot_with_sim_setup_teardown .robotInitialized == True
415
415
assert robot_with_sim_setup_teardown .robotPeriodicCount > 0
416
416
417
+
417
418
class TimedRobotPyExpectsException (TimedRobotPy ):
418
419
def startCompetition (self ) -> None :
419
420
hasAssertionError = False
@@ -424,6 +425,7 @@ def startCompetition(self) -> None:
424
425
print (f"TimedRobotPyExpectsException hasAssertionError={ hasAssertionError } " )
425
426
assert hasAssertionError
426
427
428
+
427
429
class TimedRobotPyDoNotExpectException (TimedRobotPy ):
428
430
def startCompetition (self ) -> None :
429
431
hasAssertionError = False
@@ -437,17 +439,20 @@ def startCompetition(self) -> None:
437
439
438
440
from wpilib import RobotController
439
441
442
+
440
443
def printEntryAndExit (func ):
441
444
def wrapper (* args , ** kwargs ):
442
- #name = inspect.currentframe().f_code.co_name
445
+ # name = inspect.currentframe().f_code.co_name
443
446
name = func .__name__
444
447
print (f"Enter:{ name } at { RobotController .getFPGATime ()/ 1000_000.0 :.3f} " )
445
448
result = func (* args , ** kwargs )
446
449
print (f"Exit_:{ name } at { RobotController .getFPGATime ()/ 1000_000.0 :.3f} " )
447
450
return result
451
+
448
452
return wrapper
449
453
450
- class MyRobotRobotDefaultPass ():
454
+
455
+ class MyRobotRobotDefaultPass :
451
456
452
457
@printEntryAndExit
453
458
def robotInit (self ):
@@ -490,65 +495,88 @@ def _simulationPeriodic(self):
490
495
pass
491
496
492
497
493
-
494
- class MyRobotRobotInitFails ():
498
+ class MyRobotRobotInitFails :
495
499
def robotInit (self ):
496
500
assert False
497
501
498
- class MyRobotRobotPeriodicFails ():
502
+
503
+ class MyRobotRobotPeriodicFails :
499
504
def robotPeriodic (self ):
500
505
assert False
501
506
502
- class MyRobotAutonomousInitFails ():
507
+
508
+ class MyRobotAutonomousInitFails :
503
509
def autonomousInit (self ):
504
510
assert False
505
511
506
- class MyRobotAutonomousPeriodicFails ():
512
+
513
+ class MyRobotAutonomousPeriodicFails :
507
514
def autonomousPeriodic (self ):
508
515
assert False
509
516
510
- class MyRobotAutonomousExitFails ():
517
+
518
+ class MyRobotAutonomousExitFails :
511
519
def autonomousExit (self ):
512
520
assert False
513
521
514
- class MyRobotTeleopInitFails ():
522
+
523
+ class MyRobotTeleopInitFails :
515
524
def teleopInit (self ):
516
525
assert False
517
526
518
- class MyRobotTeleopPeriodicFails ():
527
+
528
+ class MyRobotTeleopPeriodicFails :
519
529
def teleopPeriodic (self ):
520
530
assert False
521
531
522
- class MyRobotDisabledPeriodicFails ():
532
+
533
+ class MyRobotDisabledPeriodicFails :
523
534
def disabledPeriodic (self ):
524
535
assert False
525
536
526
- class MyRobotDisabledInitFails ():
537
+
538
+ class MyRobotDisabledInitFails :
527
539
def disabledInit (self ):
528
540
assert False
529
541
530
- class MyRobotTestInitFails ():
542
+
543
+ class MyRobotTestInitFails :
531
544
def testInit (self ):
532
545
assert False
533
546
534
- class MyRobotTestPeriodicFails ():
547
+
548
+ class MyRobotTestPeriodicFails :
535
549
def testPeriodic (self ):
536
550
assert False
537
551
538
552
539
-
540
- @pytest .mark .parametrize ("myRobotAddMethods, timedRobotExpectation, _expectFinished, _autonomous, _test" , [
553
+ @pytest .mark .parametrize (
554
+ "myRobotAddMethods, timedRobotExpectation, _expectFinished, _autonomous, _test" ,
555
+ [
541
556
(MyRobotRobotDefaultPass , TimedRobotPyDoNotExpectException , True , True , False ),
542
557
(MyRobotRobotInitFails , TimedRobotPyExpectsException , False , True , False ),
543
558
(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
+ ],
547
568
)
548
569
class TestCanThrowExceptions :
549
570
@classmethod
550
571
@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 ]:
552
580
class MyRobot (myRobotAddMethods , timedRobotExpectation ):
553
581
554
582
@printEntryAndExit
@@ -563,31 +591,57 @@ def endCompetition(self):
563
591
564
592
@classmethod
565
593
@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 :
567
602
return _expectFinished
568
603
569
604
@classmethod
570
605
@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 :
572
614
return _autonomous
573
615
574
616
@classmethod
575
617
@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 :
577
626
return _test
578
627
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
+ ):
581
631
with getTestController .run_robot ():
582
632
periodS = robot_with_sim_setup_teardown .getPeriod ()
583
633
# Run disabled for a short period
584
634
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
+ )
586
638
587
639
# 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
+ )
589
643
590
644
# 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