From 251ac98e46068b27d5a3359d3b70a17a86cd46ec Mon Sep 17 00:00:00 2001 From: Azeem Bande-Ali Date: Sat, 11 Jul 2020 10:07:30 -0400 Subject: [PATCH] Example unit test should load the example bot A match config was not being set on the excercise, resulting in Simple Bot being initialized instead of the bot in the project. --- training/hello_world_training.py | 16 ++++++++++++---- training/unit_tests.py | 8 +++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/training/hello_world_training.py b/training/hello_world_training.py index c1ea9e3..00b77b1 100644 --- a/training/hello_world_training.py +++ b/training/hello_world_training.py @@ -26,6 +26,17 @@ def make_match_config_with_my_bot() -> MatchConfig: ] return match_config + +def add_my_bot_to_playlist(exercises: Playlist) -> Playlist: + """ + Updates the match config for each excercise to include + the bot from this project + """ + for exercise in exercises: + exercise.match_config = make_match_config_with_my_bot() + return exercises + + @dataclass class StrikerPatience(StrikerExercise): """ @@ -90,7 +101,4 @@ def make_default_playlist() -> Playlist: DrivesToBallExercise('Get close to ball'), DrivesToBallExercise('Get close-ish to ball', grader=DriveToBallGrader(min_dist_to_pass=1000)) ] - for exercise in exercises: - exercise.match_config = make_match_config_with_my_bot() - - return exercises + return add_my_bot_to_playlist(exercises) diff --git a/training/unit_tests.py b/training/unit_tests.py index a147c35..9326280 100644 --- a/training/unit_tests.py +++ b/training/unit_tests.py @@ -3,7 +3,7 @@ from rlbot.training.training import Pass, Fail from rlbottraining.exercise_runner import run_playlist -from hello_world_training import StrikerPatience +from hello_world_training import StrikerPatience, add_my_bot_to_playlist class PatienceTest(unittest.TestCase): """ @@ -18,7 +18,8 @@ class PatienceTest(unittest.TestCase): """ def test_patience_required(self): - result_iter = run_playlist([StrikerPatience(name='patience required')]) + playlist = [StrikerPatience(name='patience required')] + result_iter = run_playlist(add_my_bot_to_playlist(playlist)) results = list(result_iter) self.assertEqual(len(results), 1) result = results[0] @@ -26,7 +27,8 @@ def test_patience_required(self): self.assertIsInstance(result.grade, Fail) # If you make the bot is smarter, update this assert that we pass. def test_no_patience_required(self): - result_iter = run_playlist([StrikerPatience(name='no patience required', car_start_x=-1000)]) + playlist = [StrikerPatience(name='no patience required', car_start_x=-1000)] + result_iter = run_playlist(add_my_bot_to_playlist(playlist)) results = list(result_iter) self.assertEqual(len(results), 1) result = results[0]