Skip to content

Commit

Permalink
Update tests and add new ones to CICD
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpalms committed Sep 27, 2023
1 parent 2585777 commit b869c8e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: "3.x"
- run: python3 -m pip install wheel==0.38.4
- run: python3 -m pip install .["tests"]
- run: pytest tests/test_gym_settings.py
- run: pytest tests/test_wrappers_settings.py
- run: pytest tests/test_recording_settings.py
- run: pytest tests/test_random.py
- run: pytest tests/test_examples.py
- run: pytest tests/test_speed.py
- run: pytest -k "test_random_gym_mock or test_random_wrappers_mock" tests/test_random.py # Run only mocked tests
1 change: 0 additions & 1 deletion diambra/arena/utils/engine_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from diambra.arena import Roles

class DiambraEngineMock:

def __init__(self, fps=1000, override_perfect_probability=None):

# Game features
Expand Down
2 changes: 1 addition & 1 deletion tests/env_exec_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def env_exec(settings, options_list, wrappers_settings, episode_recording_settin
if (no_action is True and (np.mean(cumulative_ep_rew_all) > -(max_continue + 1) * round_max_reward * n_rounds + 0.001)):
message = "NoAction policy and average reward different than {} ({})".format(
-(max_continue + 1) * round_max_reward * n_rounds, np.mean(cumulative_ep_rew_all))
warnings.warn(UserWarning(message))
raise RuntimeError(message)

env.close()

Expand Down
26 changes: 17 additions & 9 deletions tests/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# -k "expression" (filter tests using case-insensitive with parts of the test name and/or parameters values combined with boolean operators, e.g. "wrappers and doapp")

def func(game_id, n_players, action_space, frame_shape, wrappers_settings,
no_action_probability, use_mock_env, mocker):
no_action_probability, continue_games, use_mock_env, mocker):

# Args
args = {}
Expand All @@ -24,7 +24,10 @@ def func(game_id, n_players, action_space, frame_shape, wrappers_settings,
args["log_output"] = False

if use_mock_env is True:
load_mocker(mocker)
override_perfect_probability = None
if no_action_probability == 1.0:
override_perfect_probability = 0.0
load_mocker(mocker, override_perfect_probability=override_perfect_probability)

try:
# Settings
Expand All @@ -41,7 +44,6 @@ def func(game_id, n_players, action_space, frame_shape, wrappers_settings,
# Options (settings to change at reset)
options_list = []
roles = [[Roles.P1, Roles.P2], [Roles.P2, Roles.P1]]
continue_games = [-1.0, 0.0, 0.3]
for role in roles:
role_value = (role[0], role[1])
if settings.n_players == 1:
Expand All @@ -59,22 +61,26 @@ def func(game_id, n_players, action_space, frame_shape, wrappers_settings,
game_ids = ["doapp", "sfiii3n", "tektagt", "umk3", "samsh5sp", "kof98umh"]
n_players = [1, 2]
action_spaces = [SpaceTypes.DISCRETE, SpaceTypes.MULTI_DISCRETE]
no_action_probability = 0.25
no_action_probabilities = [0.0, 1.0]

@pytest.mark.parametrize("game_id", game_ids)
@pytest.mark.parametrize("n_players", n_players)
@pytest.mark.parametrize("action_space", action_spaces)
def test_random_gym_mock(game_id, n_players, action_space, mocker):
@pytest.mark.parametrize("no_action_probability", no_action_probabilities)
def test_random_gym_mock(game_id, n_players, action_space, no_action_probability, mocker):
frame_shape = random.choice([(128, 128, 1), (256, 256, 0)])
continue_games = [0.0]
use_mock_env = True
assert func(game_id, n_players, action_space, frame_shape, WrappersSettings(),
no_action_probability, use_mock_env, mocker) == 0
no_action_probability, continue_games, use_mock_env, mocker) == 0

@pytest.mark.parametrize("game_id", game_ids)
@pytest.mark.parametrize("n_players", n_players)
@pytest.mark.parametrize("action_space", action_spaces)
def test_random_wrappers_mock(game_id, n_players, action_space, mocker):
@pytest.mark.parametrize("no_action_probability", no_action_probabilities)
def test_random_wrappers_mock(game_id, n_players, action_space, no_action_probability, mocker):
frame_shape = random.choice([(128, 128, 1), (256, 256, 0)])
continue_games = [0.0]
use_mock_env = True

# Env wrappers settings
Expand All @@ -98,13 +104,15 @@ def test_random_wrappers_mock(game_id, n_players, action_space, mocker):
suffix + "opp_character", suffix + "action"]

assert func(game_id, n_players, action_space, frame_shape, wrappers_settings,
no_action_probability, use_mock_env, mocker) == 0
no_action_probability, continue_games, use_mock_env, mocker) == 0

@pytest.mark.parametrize("game_id", game_ids)
@pytest.mark.parametrize("n_players", n_players)
@pytest.mark.parametrize("action_space", action_spaces)
def test_random_integration(game_id, n_players, action_space, mocker):
@pytest.mark.parametrize("no_action_probability", [0.0])
def test_random_integration(game_id, n_players, action_space, no_action_probability, mocker):
frame_shape = random.choice([(128, 128, 1), (256, 256, 0)])
continue_games = [-1.0, 0.0, 0.3]
use_mock_env = False

# Env wrappers settings
Expand Down

0 comments on commit b869c8e

Please sign in to comment.