Skip to content

Commit 46f2f72

Browse files
Use context manager pattern in test
1 parent d6fe01e commit 46f2f72

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

tests/run_match.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010
RLBOT_SERVER_FOLDER = DIR / "../../core/RLBotCS/bin/Release/"
1111

1212
if __name__ == "__main__":
13-
match_manager = MatchManager(RLBOT_SERVER_FOLDER)
13+
with MatchManager(RLBOT_SERVER_FOLDER) as man:
14+
man.start_match(MATCH_CONFIG_PATH)
15+
assert man.packet is not None
1416

15-
match_manager.start_match(MATCH_CONFIG_PATH)
16-
assert match_manager.packet is not None
17-
18-
try:
1917
# wait for the match to end
20-
while match_manager.packet.match_info.match_phase != flat.MatchPhase.Ended:
18+
while man.packet.match_info.match_phase != flat.MatchPhase.Ended:
2119
sleep(1.0)
22-
finally:
23-
match_manager.shut_down()

tests/run_only.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
match_config_path = Path(sys.argv[1])
1515
assert match_config_path.exists(), f"Match config not found: {match_config_path}"
1616

17-
# start the match
18-
match_manager = MatchManager(RLBOT_SERVER_FOLDER)
19-
match_manager.start_match(match_config_path, False)
17+
with MatchManager(RLBOT_SERVER_FOLDER) as man:
18+
man.start_match(match_config_path, False)
2019

21-
# wait
22-
input("\nPress enter to end the match: ")
20+
# Wait for input
21+
input("\nPress enter to end the match: ")
2322

24-
# end the match and disconnect
25-
match_manager.stop_match()
26-
match_manager.disconnect()
23+
# End the match
24+
man.stop_match()

0 commit comments

Comments
 (0)