mirror of
https://github.com/gryf/coach.git
synced 2025-12-18 11:40:18 +01:00
enumerate each preset as its own test
This commit is contained in:
@@ -12,45 +12,55 @@ from subprocess import Popen, DEVNULL
|
|||||||
from rl_coach.logger import screen
|
from rl_coach.logger import screen
|
||||||
|
|
||||||
|
|
||||||
|
def all_presets():
|
||||||
|
result = []
|
||||||
|
for f in sorted(os.listdir('rl_coach/presets')):
|
||||||
|
if f.endswith('.py') and f != '__init__.py':
|
||||||
|
result.append(f.split('.')[0])
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(params=all_presets())
|
||||||
|
def preset(request):
|
||||||
|
return request.param
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration_test
|
@pytest.mark.integration_test
|
||||||
def test_all_presets_are_running():
|
def test_preset_runs(preset):
|
||||||
# os.chdir("../../")
|
|
||||||
test_failed = False
|
test_failed = False
|
||||||
all_presets = sorted([f.split('.')[0] for f in os.listdir('rl_coach/presets') if f.endswith('.py') and f != '__init__.py'])
|
|
||||||
for preset in all_presets:
|
|
||||||
print("Testing preset {}".format(preset))
|
|
||||||
|
|
||||||
# TODO: this is a temporary workaround for presets which define more than a single available level.
|
print("Testing preset {}".format(preset))
|
||||||
# we should probably do this in a more robust way
|
|
||||||
level = ""
|
|
||||||
if "Atari" in preset:
|
|
||||||
level = "breakout"
|
|
||||||
elif "Mujoco" in preset:
|
|
||||||
level = "inverted_pendulum"
|
|
||||||
elif "ControlSuite" in preset:
|
|
||||||
level = "pendulum:swingup"
|
|
||||||
params = ["python3", "rl_coach/coach.py", "-p", preset, "-ns", "-e", ".test"]
|
|
||||||
if level != "":
|
|
||||||
params += ["-lvl", level]
|
|
||||||
|
|
||||||
p = Popen(params, stdout=DEVNULL)
|
# TODO: this is a temporary workaround for presets which define more than a single available level.
|
||||||
|
# we should probably do this in a more robust way
|
||||||
|
level = ""
|
||||||
|
if "Atari" in preset:
|
||||||
|
level = "breakout"
|
||||||
|
elif "Mujoco" in preset:
|
||||||
|
level = "inverted_pendulum"
|
||||||
|
elif "ControlSuite" in preset:
|
||||||
|
level = "pendulum:swingup"
|
||||||
|
|
||||||
# wait 10 seconds overhead of initialization etc.
|
experiment_name = ".test-" + preset
|
||||||
time.sleep(10)
|
|
||||||
return_value = p.poll()
|
|
||||||
|
|
||||||
if return_value is None:
|
params = ["python3", "rl_coach/coach.py", "-p", preset, "-ns", "-e", experiment_name]
|
||||||
screen.success("{} passed successfully".format(preset))
|
if level != "":
|
||||||
else:
|
params += ["-lvl", level]
|
||||||
test_failed = True
|
|
||||||
screen.error("{} failed".format(preset), crash=False)
|
|
||||||
|
|
||||||
p.kill()
|
p = Popen(params, stdout=DEVNULL)
|
||||||
if os.path.exists("experiments/.test"):
|
|
||||||
shutil.rmtree("experiments/.test")
|
# wait 10 seconds overhead of initialization etc.
|
||||||
|
time.sleep(10)
|
||||||
|
return_value = p.poll()
|
||||||
|
|
||||||
|
if return_value is None:
|
||||||
|
screen.success("{} passed successfully".format(preset))
|
||||||
|
else:
|
||||||
|
test_failed = True
|
||||||
|
screen.error("{} failed".format(preset), crash=False)
|
||||||
|
|
||||||
|
p.kill()
|
||||||
|
if os.path.exists("experiments/" + experiment_name):
|
||||||
|
shutil.rmtree("experiments/" + experiment_name)
|
||||||
|
|
||||||
assert not test_failed
|
assert not test_failed
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
test_all_presets_are_running()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user