Branch data Line data Source code
1 : : #!/usr/bin/env python3
2 : :
3 : : # Copyright 2026 Garena Online Private Limited
4 : : #
5 : : # Licensed under the Apache License, Version 2.0 (the "License");
6 : : # you may not use this file except in compliance with the License.
7 : : # You may obtain a copy of the License at
8 : : #
9 : : # http://www.apache.org/licenses/LICENSE-2.0
10 : : #
11 : : # Unless required by applicable law or agreed to in writing, software
12 : : # distributed under the License is distributed on an "AS IS" BASIS,
13 : : # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : : # See the License for the specific language governing permissions and
15 : : # limitations under the License.
16 : : """Exercise Playground's documentation renderer against the native images."""
17 : :
18 : 1 : import os
19 : 1 : import sys
20 : 1 : import tempfile
21 : 1 : import unittest
22 : 1 : from pathlib import Path
23 : 1 : from unittest import mock
24 : :
25 : 1 : from scripts import render_compare
26 : :
27 : :
28 : 1 : class PlaygroundRenderCompareTest(unittest.TestCase):
29 : : """Keep documentation generation on the tested all-task oracle path."""
30 : :
31 : 1 : def test_all_playground_tasks(self) -> None:
32 : : """Generate the documented comparison image with every registered task."""
33 : 1 : with tempfile.TemporaryDirectory() as temp:
34 : 1 : output = Path(os.environ.get("TEST_UNDECLARED_OUTPUTS_DIR", temp))
35 : 1 : output /= "mujoco_playground_official_compare.png"
36 : : # Use the documented generation command and its image budgets.
37 : 1 : with mock.patch.object(
38 : : sys,
39 : : "argv",
40 : : [
41 : : "render_compare",
42 : : "--family=mujoco_playground",
43 : : f"--output={output}",
44 : : "--columns=4",
45 : : "--source-width=480",
46 : : "--source-height=360",
47 : : "--tile-width=144",
48 : : "--tile-height=108",
49 : : "--max-mean-abs-diff=4.2",
50 : : "--max-mismatch-ratio=0.15",
51 : : "--max-ignored-abs-diff=3",
52 : : ],
53 : : ):
54 : 1 : render_compare.main()
55 : 1 : self.assertTrue(output.is_file())
56 : :
57 : :
58 [ + - ]: 1 : if __name__ == "__main__":
59 : 1 : unittest.main()
|