Skip to content

Commit

Permalink
Merge pull request #178 from diegoferigo/refactor/pytest
Browse files Browse the repository at this point in the history
Improve testing suite
  • Loading branch information
diegoferigo authored Apr 20, 2020
2 parents 424d295 + c82f660 commit c42ceec
Show file tree
Hide file tree
Showing 62 changed files with 130 additions and 46 deletions.
40 changes: 32 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,27 @@ jobs:

- name: Python Tests [ScenarI/O]
run: |
cd tests/scenario
pytest -v
cd tests
pytest -m "scenario"
- name: Python Tests with Valgrind [ScenarI/O]
if: failure()
run: |
pip3 install colour-valgrind
cd tests/scenario
valgrind --log-file=/tmp/valgrind.log pytest -v -s || colour-valgrind -t /tmp/valgrind.log
cd tests
valgrind --log-file=/tmp/valgrind.log pytest -s -m "scenario" || colour-valgrind -t /tmp/valgrind.log
- name: Python Tests [gym_ignition]
run: |
cd tests
pytest -m "gym_ignition"
- name: Python Tests with Valgrind [gym_ignition]
if: failure()
run: |
pip3 install colour-valgrind
cd tests
valgrind --log-file=/tmp/valgrind.log pytest -s -m "gym_ignition" || colour-valgrind -t /tmp/valgrind.log
user:
name: User installation
Expand Down Expand Up @@ -112,12 +124,24 @@ jobs:
- name: Python Tests [ScenarI/O]
run: |
cd tests/scenario
pytest -v
cd tests
pytest -m "scenario"
- name: Python Tests with Valgrind [ScenarI/O]
if: failure()
run: |
pip3 install colour-valgrind
cd tests/scenario
valgrind --log-file=/tmp/valgrind.log pytest -v -s || colour-valgrind -t /tmp/valgrind.log
cd tests
valgrind --log-file=/tmp/valgrind.log pytest -s -m "scenario" || colour-valgrind -t /tmp/valgrind.log
- name: Python Tests [gym_ignition]
run: |
cd tests
pytest -m "gym_ignition"
- name: Python Tests with Valgrind [gym_ignition]
if: failure()
run: |
pip3 install colour-valgrind
cd tests
valgrind --log-file=/tmp/valgrind.log pytest -s -m "gym_ignition" || colour-valgrind -t /tmp/valgrind.log
10 changes: 5 additions & 5 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ jobs:
cd dist
pip install *.tar.gz
- name: Python Tests [ScenarI/O]
- name: Python Tests
run: |
cd tests/scenario
pytest -v
cd tests
pytest
# ========================
# TEST BDIST_WHEEL PACKAGE
Expand Down Expand Up @@ -114,8 +114,8 @@ jobs:
- name: Install bdist
run: docker exec -i -w /dist test sh -c 'pip install *.whl'

- name: Python Tests [ScenarI/O]
run: docker exec -i -w /tests/scenario test sh -c 'pytest -v'
- name: Python Tests
run: docker exec -i -w /tests/scenario test sh -c 'pytest'

# =============
# PUSH PACKAGES
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def build_extension(self, ext):
'numpy',
'gym_ignition_models',
],
packages=find_packages(),
packages=find_packages("python"),
package_dir={'': "python"},
ext_modules=[CMakeExtension(name='InstallAllTargets', cmake_configuration='PyPI')],
cmdclass={
'build_ext': BuildExtension,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved.
# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.

from . import common
5 changes: 5 additions & 0 deletions tests/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved.
# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.

from . import utils
42 changes: 27 additions & 15 deletions tests/scenario/utils.py → tests/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# GNU Lesser General Public License v2.1 or any later version.

import pytest
import tempfile
from typing import Tuple
from gym_ignition.utils import misc
from gym_ignition import scenario_bindings as bindings


Expand All @@ -15,6 +15,29 @@ def id_gazebo_fn(val: Tuple[float, float, float]):

@pytest.fixture(scope="function")
def gazebo_fixture(request):
"""
Return an instance of the GazeboSimulator ensuring that it
is closed even in case of failure.
Example:
@pytest.mark.parametrize("gazebo", [(0.001, 1.0, 1)], indirect=True)
def test_foo(gazebo: bindings.GazeboSimulator):
assert gazebo.initialize()
...
@pytest.mark.parametrize("gazebo, name",
[((0.001, 1.0, 1), "name_1"),
((0.001, 1.0, 1), "name_2"),
((0.001, 1.0, 1), "name_3")],
indirect="gazebo")
def test_foo(gazebo: bindings.GazeboSimulator, name: str):
model_name = name
assert gazebo.initialize()
...
"""

step_size, rtf, iterations = request.param
gazebo = bindings.GazeboSimulator(step_size, rtf, iterations)
Expand All @@ -35,11 +58,7 @@ def get_multi_world_sdf_file() -> str:
</world>
</sdf>"""

handle, multi_world_sdf = tempfile.mkstemp()

with open(handle, 'w') as f:
f.write(multi_world_sdf_string)

multi_world_sdf = misc.string_to_file(multi_world_sdf_string)
return multi_world_sdf


Expand Down Expand Up @@ -76,20 +95,13 @@ def get_cube_urdf_string() -> str:

def get_cube_urdf() -> str:

handle, model_file = tempfile.mkstemp()
with open(handle, 'w') as f:
f.write(get_cube_urdf_string())

model_file = misc.string_to_file(get_cube_urdf_string())
return model_file


def get_empty_world_sdf() -> str:

world_sdf_string = bindings.getEmptyWorld()

handle, world_file = tempfile.mkstemp()

with open(handle, 'w') as f:
f.write(world_sdf_string)

world_file = misc.string_to_file(world_sdf_string)
return world_file
6 changes: 6 additions & 0 deletions tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[pytest]
addopts = -rsxX -v
markers =
gympp: Select the tests in the 'gympp' folder
scenario: Select the tests in the 'scenario' folder
gym_ignition: Select the tests in the 'gym_ignition' folder
3 changes: 3 additions & 0 deletions tests/test_gym_ignition/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved.
# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.
12 changes: 12 additions & 0 deletions tests/test_gym_ignition/test_reproducibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved.
# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.

import pytest
pytestmark = pytest.mark.gym_ignition


@pytest.mark.xfail
def test_reproducibility():

assert False
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
# GNU Lesser General Public License v2.1 or any later version.

import pytest
pytestmark = pytest.mark.scenario

import numpy as np
from . import utils
import gym_ignition_models
from .utils import gazebo_fixture as gazebo
from ..common import utils
from ..common.utils import gazebo_fixture as gazebo
from gym_ignition import scenario_bindings as bindings
from gym_ignition.controllers.gazebo import computed_torque_fixed_base as context

Expand All @@ -27,7 +29,8 @@ def test_computed_torque_fixed_base(gazebo: bindings.GazeboSimulator):
world = gazebo.getWorld()

# Insert the physics
world.insertWorldPlugin("libPhysicsSystem.so", "scenario::plugins::gazebo::Physics")
assert world.insertWorldPlugin("libPhysicsSystem.so",
"scenario::plugins::gazebo::Physics")

# Get the panda urdf
panda_urdf = gym_ignition_models.get_model_file("panda")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# GNU Lesser General Public License v2.1 or any later version.

import pytest
from . import utils
from .utils import gazebo_fixture as gazebo
pytestmark = pytest.mark.scenario

from ..common import utils
from ..common.utils import gazebo_fixture as gazebo
from gym_ignition import scenario_bindings as bindings

# Set the verbosity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# GNU Lesser General Public License v2.1 or any later version.

import pytest
from . import utils
from .utils import gazebo_fixture as gazebo
pytestmark = pytest.mark.scenario

from ..common import utils
from ..common.utils import gazebo_fixture as gazebo
from gym_ignition import scenario_bindings as bindings

# Set the verbosity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# GNU Lesser General Public License v2.1 or any later version.

import pytest
from . import utils
pytestmark = pytest.mark.scenario

from ..common import utils
import gym_ignition_models
from .utils import gazebo_fixture as gazebo
from ..common.utils import gazebo_fixture as gazebo
from gym_ignition import scenario_bindings as bindings

# Set the verbosity
Expand All @@ -18,7 +20,8 @@ def get_model(gazebo: bindings.GazeboSimulator,
world = gazebo.getWorld()
# TODO: assert world

world.insertWorldPlugin("libPhysicsSystem.so", "scenario::plugins::gazebo::Physics")
assert world.insertWorldPlugin("libPhysicsSystem.so",
"scenario::plugins::gazebo::Physics")

model_urdf = gym_ignition_models.get_model_file(gym_ignition_model_name)
assert world.insertModel(model_urdf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# GNU Lesser General Public License v2.1 or any later version.

import pytest
from . import utils
from .utils import gazebo_fixture as gazebo
pytestmark = pytest.mark.scenario

from ..common import utils
from ..common.utils import gazebo_fixture as gazebo
from gym_ignition import scenario_bindings as bindings

# Set the verbosity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# GNU Lesser General Public License v2.1 or any later version.

import pytest
from . import utils
from .utils import gazebo_fixture as gazebo
pytestmark = pytest.mark.scenario

from ..common import utils
from ..common.utils import gazebo_fixture as gazebo
from gym_ignition import scenario_bindings as bindings

# Set the verbosity
Expand Down Expand Up @@ -32,7 +34,7 @@ def test_load_default_world(gazebo: bindings.GazeboSimulator):
def test_load_default_world_from_file(gazebo: bindings.GazeboSimulator):

empty_world_sdf = utils.get_empty_world_sdf()
print(empty_world_sdf)

assert gazebo.insertWorldFromSDF(empty_world_sdf)

assert gazebo.initialize()
Expand Down Expand Up @@ -162,7 +164,8 @@ def test_world_physics_plugin(gazebo: bindings.GazeboSimulator):
assert world.time() == 0

# Insert the Physics system
world.insertWorldPlugin("libPhysicsSystem.so", "scenario::plugins::gazebo::Physics")
assert world.insertWorldPlugin("libPhysicsSystem.so",
"scenario::plugins::gazebo::Physics")

# After the first step, the physics catches up with time
gazebo.run()
Expand Down Expand Up @@ -191,7 +194,8 @@ def test_sim_time_starts_from_zero(gazebo: bindings.GazeboSimulator):
dt = gazebo.stepSize()

assert world.time() == 0
world.insertWorldPlugin("libPhysicsSystem.so", "scenario::plugins::gazebo::Physics")
assert world.insertWorldPlugin("libPhysicsSystem.so",
"scenario::plugins::gazebo::Physics")
assert world.time() == 0

gazebo.run(paused=True)
Expand Down

0 comments on commit c42ceec

Please sign in to comment.