From 739dfcb4ab36be77e3e0bbf12468f4ab5fd78b69 Mon Sep 17 00:00:00 2001 From: Sebastian Castro <4603398+sea-bass@users.noreply.github.com> Date: Mon, 13 Jan 2025 12:42:46 -0500 Subject: [PATCH] Unit test friendly folder structure for Python examples (#237) --- .../generate_parameter_module_example/__init__.py | 0 example_python/test/test_load_modules.py | 12 ++++++++++++ .../generate_python_module.py | 4 ++++ 3 files changed, 16 insertions(+) delete mode 100644 example_python/generate_parameter_module_example/__init__.py create mode 100644 example_python/test/test_load_modules.py diff --git a/example_python/generate_parameter_module_example/__init__.py b/example_python/generate_parameter_module_example/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/example_python/test/test_load_modules.py b/example_python/test/test_load_modules.py new file mode 100644 index 0000000..0d0bdf4 --- /dev/null +++ b/example_python/test/test_load_modules.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +import generate_parameter_module_example + +print(f'Imported module from: {generate_parameter_module_example.__file__}') + +import generate_parameter_module_example.admittance_parameters # noqa: E402 + +print('Imported generated parameter module') + +import generate_parameter_module_example.minimal_publisher # noqa: E402 + +print('Imported minimal publisher module') diff --git a/generate_parameter_library_py/generate_parameter_library_py/generate_python_module.py b/generate_parameter_library_py/generate_parameter_library_py/generate_python_module.py index 8ba867f..e0c899d 100755 --- a/generate_parameter_library_py/generate_parameter_library_py/generate_python_module.py +++ b/generate_parameter_library_py/generate_parameter_library_py/generate_python_module.py @@ -48,6 +48,10 @@ def run(output_file, yaml_file, validation_module=''): with open(output_file, 'w') as f: f.write(code) + # Put an __init__.py file if one does not yet exist. + init_file = os.path.join(os.path.dirname(output_file), '__init__.py') + open(init_file, 'a').close() + def parse_args(): parser = argparse.ArgumentParser()