Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion templates
Submodule templates updated 1 files
+0 −1 profile_template.py
77 changes: 77 additions & 0 deletions tests/unit/templates/test_temp_main.py
Original file line number Diff line number Diff line change
@@ -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,
)