Skip to content

Commit 69d697b

Browse files
authored
Example unit test should load the example bot (#45)
A match config was not being set on the excercise, resulting in Simple Bot being initialized instead of the bot in the project.
1 parent 98f266b commit 69d697b

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

training/hello_world_training.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ def make_match_config_with_my_bot() -> MatchConfig:
2626
]
2727
return match_config
2828

29+
30+
def add_my_bot_to_playlist(exercises: Playlist) -> Playlist:
31+
"""
32+
Updates the match config for each excercise to include
33+
the bot from this project
34+
"""
35+
for exercise in exercises:
36+
exercise.match_config = make_match_config_with_my_bot()
37+
return exercises
38+
39+
2940
@dataclass
3041
class StrikerPatience(StrikerExercise):
3142
"""
@@ -90,7 +101,4 @@ def make_default_playlist() -> Playlist:
90101
DrivesToBallExercise('Get close to ball'),
91102
DrivesToBallExercise('Get close-ish to ball', grader=DriveToBallGrader(min_dist_to_pass=1000))
92103
]
93-
for exercise in exercises:
94-
exercise.match_config = make_match_config_with_my_bot()
95-
96-
return exercises
104+
return add_my_bot_to_playlist(exercises)

training/unit_tests.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from rlbot.training.training import Pass, Fail
44
from rlbottraining.exercise_runner import run_playlist
55

6-
from hello_world_training import StrikerPatience
6+
from hello_world_training import StrikerPatience, add_my_bot_to_playlist
77

88
class PatienceTest(unittest.TestCase):
99
"""
@@ -18,15 +18,17 @@ class PatienceTest(unittest.TestCase):
1818
"""
1919

2020
def test_patience_required(self):
21-
result_iter = run_playlist([StrikerPatience(name='patience required')])
21+
playlist = [StrikerPatience(name='patience required')]
22+
result_iter = run_playlist(add_my_bot_to_playlist(playlist))
2223
results = list(result_iter)
2324
self.assertEqual(len(results), 1)
2425
result = results[0]
2526
self.assertEqual(result.exercise.name, 'patience required')
2627
self.assertIsInstance(result.grade, Fail) # If you make the bot is smarter, update this assert that we pass.
2728

2829
def test_no_patience_required(self):
29-
result_iter = run_playlist([StrikerPatience(name='no patience required', car_start_x=-1000)])
30+
playlist = [StrikerPatience(name='no patience required', car_start_x=-1000)]
31+
result_iter = run_playlist(add_my_bot_to_playlist(playlist))
3032
results = list(result_iter)
3133
self.assertEqual(len(results), 1)
3234
result = results[0]

0 commit comments

Comments
 (0)