Skip to content

Commit 0936907

Browse files
committed
Add rendering integration tests and related infrastructure
PiperOrigin-RevId: 182205862
1 parent e2242b0 commit 0936907

46 files changed

Lines changed: 393 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dm_control/mujoco/render_test.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2017 The dm_control Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ============================================================================
15+
16+
"""Integration tests for rendering."""
17+
18+
from __future__ import absolute_import
19+
from __future__ import division
20+
from __future__ import print_function
21+
22+
import os
23+
24+
# Internal dependencies.
25+
from absl.testing import absltest
26+
from absl.testing import parameterized
27+
from dm_control.mujoco.testing import decorators
28+
from dm_control.mujoco.testing import image_utils
29+
from six.moves import zip # pylint: disable=redefined-builtin
30+
31+
32+
DEBUG_IMAGE_DIR = os.environ.get('TEST_UNDECLARED_OUTPUTS_DIR',
33+
absltest.get_default_test_tmpdir())
34+
35+
NUM_THREADS = 4
36+
CALLS_PER_THREAD = 1
37+
38+
39+
class RenderTest(parameterized.TestCase):
40+
41+
@parameterized.named_parameters(image_utils.SEQUENCES.items())
42+
@image_utils.save_images_on_failure(output_dir=DEBUG_IMAGE_DIR)
43+
@decorators.run_threaded(num_threads=NUM_THREADS,
44+
calls_per_thread=CALLS_PER_THREAD)
45+
def test_render(self, sequence):
46+
for expected, actual in zip(sequence.iter_load(), sequence.iter_render()):
47+
image_utils.assert_images_close(expected, actual)
48+
49+
@decorators.run_threaded(num_threads=NUM_THREADS,
50+
calls_per_thread=CALLS_PER_THREAD)
51+
@image_utils.save_images_on_failure(output_dir=DEBUG_IMAGE_DIR)
52+
def test_render_multiple_physics_per_thread(self):
53+
cartpole = image_utils.cartpole
54+
humanoid = image_utils.humanoid
55+
cartpole_frames = []
56+
humanoid_frames = []
57+
for cartpole_frame, humanoid_frame in zip(cartpole.iter_render(),
58+
humanoid.iter_render()):
59+
cartpole_frames.append(cartpole_frame)
60+
humanoid_frames.append(humanoid_frame)
61+
62+
for expected, actual in zip(cartpole.iter_load(), cartpole_frames):
63+
image_utils.assert_images_close(expected, actual)
64+
65+
for expected, actual in zip(humanoid.iter_load(), humanoid_frames):
66+
image_utils.assert_images_close(expected, actual)
67+
68+
69+
if __name__ == '__main__':
70+
absltest.main()
5.67 KB
5.82 KB
5.95 KB
6.06 KB
6.08 KB
6.13 KB
6.21 KB
6.37 KB
6.37 KB

0 commit comments

Comments
 (0)