diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d8639f8..ad32607 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,6 +21,7 @@ jobs: uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: persist-credentials: false + submodules: true - name: Set up Python uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0 @@ -69,6 +70,7 @@ jobs: uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: persist-credentials: false + submodules: true - name: Set up Python uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0 diff --git a/templates b/templates index d0f2652..8a4f5c2 160000 --- a/templates +++ b/templates @@ -1 +1 @@ -Subproject commit d0f265288f713754d814a5928d51b3ce46c3df9a +Subproject commit 8a4f5c244c0fbc3cf2d684c14d6ccb0831467906 diff --git a/tests/unit/templates/test_temp_main.py b/tests/unit/templates/test_temp_main.py new file mode 100644 index 0000000..e593a8e --- /dev/null +++ b/tests/unit/templates/test_temp_main.py @@ -0,0 +1,77 @@ +import os +import subprocess +import sys + +import pytest + +TEST_DIR = os.path.dirname(os.path.abspath(__file__)) +TEMPLATE_DIR = os.path.abspath(os.path.join(TEST_DIR, "..", "templates")) + +TEMPLATES_LIST = [ + "chatbot", + "cnn", + "empty", + "lora-cls", + "lstm-cls", + "lstm-gen", + "mlp-binary", + "mlp-multiclass", + "mlp-regression", + "timm-cls", + "vae", + "yolo", +] + + +def get_template_directories(): + if not os.path.exists(TEMPLATE_DIR): + return [] + return [ + d + for d in os.listdir(TEMPLATE_DIR) + if d not in [".git", ".gitignore", "__init__.py", "LICENSE"] + ] + + +def test_templates_dir_exists(): + assert os.path.exists(TEMPLATE_DIR), ( + f"Templates directory not found at {TEMPLATE_DIR}. Did you pull the submodule?" + ) + + +@pytest.mark.parametrize("template_name", get_template_directories()) +def test_template_structure_and_execution(template_name): + assert template_name in TEMPLATES_LIST, ( + f"Unexpected directory found in templates: {template_name}" + ) + + template_path = os.path.join(TEMPLATE_DIR, template_name) + main_path = os.path.join(template_path, "main.py") + requirement_path = os.path.join(template_path, "requirements.txt") + + assert os.path.exists(main_path), f"Missing main.py in {template_name}" + assert os.path.exists(requirement_path), ( + f"Missing requirements.txt in {template_name}" + ) + + try: + subprocess.run( + [sys.executable, "-m", "pip", "install", "-r", requirement_path], + check=True, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + subprocess.run( + [sys.executable, main_path], + check=True, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + except subprocess.CalledProcessError as e: + raise AssertionError(f"Template '{template_name}' execution failed: {e}") + finally: + subprocess.run( + [sys.executable, "-m", "pip", "uninstall", "-y", "-r", requirement_path], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + )