Skip to content

Commit

Permalink
Create a lite test suite which uses less memory
Browse files Browse the repository at this point in the history
  • Loading branch information
jagdeepsb committed Jun 13, 2024
1 parent 2c3c727 commit 0f73848
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
- name: Install evolution gym
run: pip install -e .
- name: Run test
run: xvfb-run python -m pytest -s -v tests/screen_free/test_img_render_modes.py
run: xvfb-run python -m pytest -s -v -n auto -m lite
4 changes: 3 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[pytest]
addopts = --ignore=examples/externals --ignore=evogym/simulator/externals --ignore=evogym/examples/gym_test.py
addopts = --ignore=examples/externals --ignore=evogym/simulator/externals --ignore=evogym/examples/gym_test.py
markers =
lite: mark as part of the lite test suite
19 changes: 16 additions & 3 deletions tests/requires_screen/test_screen_render_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
import evogym.envs
from evogym import sample_robot

LITE_TEST_ENV_NAMES = [
"Pusher-v0",
"Walker-v0",
"Traverser-v0",
]

@pytest.mark.lite
@pytest.mark.parametrize(
"render_mode, add_options",
list(product(
Expand Down Expand Up @@ -41,9 +48,15 @@ def test_render_modes(render_mode, add_options):
ob, reward, terminated, truncated, info = env.step(action)

env.close()

# @pytest.mark.parametrize("env_name", evogym.BASELINE_ENV_NAMES)
@pytest.mark.parametrize("env_name", ["ObstacleTraverser-v1", "Traverser-v0"])

def get_all_env_render_params():
return [
env_name if env_name not in LITE_TEST_ENV_NAMES
else pytest.param(env_name, marks=pytest.mark.lite)
for env_name in evogym.BASELINE_ENV_NAMES
]

@pytest.mark.parametrize("env_name", get_all_env_render_params())
def test_all_env_render(env_name):
"""
- Env can render to screen
Expand Down
15 changes: 14 additions & 1 deletion tests/screen_free/test_baseline_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@
import evogym.envs
from evogym import sample_robot

@pytest.mark.parametrize("env_name", evogym.BASELINE_ENV_NAMES)
LITE_TEST_ENV_NAMES = [
"Pusher-v0",
"Walker-v0",
"Traverser-v0",
]

def get_params():
return [
env_name if env_name not in LITE_TEST_ENV_NAMES
else pytest.param(env_name, marks=pytest.mark.lite)
for env_name in evogym.BASELINE_ENV_NAMES
]

@pytest.mark.parametrize("env_name", get_params())
def test_env_creatable_and_has_correct_api(env_name):
"""
- Env is creatable
Expand Down
31 changes: 18 additions & 13 deletions tests/screen_free/test_img_render_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
import evogym.envs
from evogym import sample_robot

# @pytest.mark.parametrize(
# "env_name, render_mode",
# list(product(
# evogym.BASELINE_ENV_NAMES,
# [None, "img", "rgb_array"],
# ))
# )
@pytest.mark.parametrize(
"env_name, render_mode",
list(product(
["ObstacleTraverser-v1", "Traverser-v0"],
LITE_TEST_ENV_NAMES = [
"Pusher-v0",
"Walker-v0",
"Traverser-v0",
]

def get_params():
params = product(
evogym.BASELINE_ENV_NAMES,
[None, "img", "rgb_array"],
))
)
)
return [
param if param[0] not in LITE_TEST_ENV_NAMES
else pytest.param(*param, marks=pytest.mark.lite)
for param in params
]


@pytest.mark.parametrize("env_name, render_mode", get_params())
def test_render(env_name, render_mode):
"""
- Env can render to none and to image
Expand Down
13 changes: 9 additions & 4 deletions tests/screen_free/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest
from pytest import raises
from typing import List, Tuple

Expand All @@ -8,6 +9,7 @@
is_connected, has_actuator, get_full_connectivity
)

@pytest.mark.lite
def test_get_uniform():
ones = get_uniform(1)
assert np.allclose(ones, np.ones(1)), (
Expand All @@ -18,7 +20,8 @@ def test_get_uniform():
assert np.allclose(one_thirds, np.ones(3) / 3), (
f"Expected {np.ones(3) / 3}, got {one_thirds}"
)


@pytest.mark.lite
def test_draw():
result = draw([0.2])
assert result == 0, f"Expected 0, got {result}"
Expand All @@ -38,7 +41,8 @@ def test_draw():
for i in range(10):
result = draw(pd)
assert result in list(range(10)), f"Expected result to be between 0 and 9, got {result}"


@pytest.mark.lite
def test_has_actuator():
h_act, v_act = VOXEL_TYPES['H_ACT'], VOXEL_TYPES['V_ACT']
others = [
Expand Down Expand Up @@ -109,7 +113,8 @@ def test_is_connected():
[empty, others[1], others[0]]
])
assert not is_connected(robot), "Expected not connected"


@pytest.mark.lite
def test_get_full_connectivity():
empty = VOXEL_TYPES['EMPTY']
others = [
Expand Down Expand Up @@ -157,7 +162,7 @@ def connections_contains_all(connections: np.ndarray, expected: List[Tuple[int,
assert connections.shape[0] == 2, "Expected 2"
connections_contains_all(connections, [(0, 1), (1, 4), (4, 5)])


@pytest.mark.lite
def test_sample_robot():

h_act, v_act, empty = VOXEL_TYPES['H_ACT'], VOXEL_TYPES['V_ACT'], VOXEL_TYPES['EMPTY']
Expand Down
5 changes: 5 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LITE_TEST_ENV_NAMES = [
"Pusher-v0",
"Walker-v0",
"Traverser-v0",
]

0 comments on commit 0f73848

Please sign in to comment.