2022-01-18 16:52:29 +08:00
|
|
|
import importlib
|
2024-08-14 03:18:41 +08:00
|
|
|
import json
|
2022-01-18 16:52:29 +08:00
|
|
|
import os
|
|
|
|
import pkgutil
|
|
|
|
import shutil
|
|
|
|
from string import Template
|
|
|
|
|
2022-10-23 06:51:44 +08:00
|
|
|
import omnigibson
|
|
|
|
from omnigibson import examples
|
|
|
|
from omnigibson.utils.asset_utils import download_assets
|
2022-01-18 16:52:29 +08:00
|
|
|
|
|
|
|
download_assets()
|
|
|
|
|
2024-07-18 03:22:15 +08:00
|
|
|
EXAMPLES_TO_SKIP = [
|
|
|
|
"action_primitives.rs_int_example",
|
|
|
|
"action_primitives.solve_simple_task",
|
|
|
|
"action_primitives.wip_solve_behavior_task",
|
|
|
|
"learning.navigation_policy_demo",
|
|
|
|
"teleoperation.robot_teleoperate_demo",
|
2024-07-18 04:32:46 +08:00
|
|
|
# TODO: Temporarily skip the following examples
|
2024-07-19 05:14:39 +08:00
|
|
|
# "object_states.attachment_demo", # seg fualt??
|
|
|
|
# "environments.behavior_env_demo", # This only works with pre-sampled cached BEHAVIOR activity scene
|
2024-07-18 03:22:15 +08:00
|
|
|
]
|
|
|
|
|
2022-01-18 16:52:29 +08:00
|
|
|
|
|
|
|
def main():
|
|
|
|
examples_list = []
|
2024-07-18 03:22:15 +08:00
|
|
|
prefix = examples.__name__ + "."
|
|
|
|
for package in pkgutil.walk_packages(examples.__path__, prefix):
|
2024-08-07 07:48:18 +08:00
|
|
|
if not package.ispkg:
|
2024-07-18 03:22:15 +08:00
|
|
|
examples_list.append(package.name[len(prefix) :])
|
|
|
|
|
|
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
tests_of_examples_dir = os.path.join(current_dir, "tests_of_examples")
|
|
|
|
shutil.rmtree(tests_of_examples_dir, ignore_errors=True)
|
|
|
|
os.makedirs(tests_of_examples_dir, exist_ok=True)
|
2022-01-18 16:52:29 +08:00
|
|
|
|
2024-07-18 03:22:15 +08:00
|
|
|
examples_list = [example for example in examples_list if example not in EXAMPLES_TO_SKIP]
|
2022-01-18 16:52:29 +08:00
|
|
|
|
2024-08-14 03:18:41 +08:00
|
|
|
test_file_names = []
|
|
|
|
|
2022-01-18 16:52:29 +08:00
|
|
|
for example in examples_list:
|
2022-10-23 06:51:44 +08:00
|
|
|
template_file_name = os.path.join(omnigibson.__path__[0], "..", "tests", "test_of_example_template.txt")
|
2022-01-18 16:52:29 +08:00
|
|
|
with open(template_file_name, "r") as f:
|
|
|
|
substitutes = dict()
|
|
|
|
substitutes["module"] = example
|
|
|
|
name = example.rsplit(".", 1)[-1]
|
|
|
|
substitutes["name"] = name
|
|
|
|
src = Template(f.read())
|
|
|
|
dst = src.substitute(substitutes)
|
2024-08-14 03:18:41 +08:00
|
|
|
test_file_name = name + "_test.py"
|
|
|
|
test_file_path = os.path.join(tests_of_examples_dir, test_file_name)
|
|
|
|
with open(test_file_path, "w") as test_file:
|
|
|
|
test_file.write(dst)
|
|
|
|
# Add the test file name (without .py extension) to the list
|
|
|
|
test_file_names.append(name + "_test")
|
|
|
|
|
|
|
|
# Write the list of test file names to a JSON file
|
|
|
|
json_file_path = os.path.join(current_dir, "example_tests.json")
|
|
|
|
with open(json_file_path, "w") as json_file:
|
|
|
|
json.dump(test_file_names, json_file)
|
2022-01-18 16:52:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|