Skip to content

Commit af0ab37

Browse files
committed
feat(tests): enhance integration tests and add cleanup fixture for compiled themes
1 parent 0c28171 commit af0ab37

File tree

3 files changed

+91
-7
lines changed

3 files changed

+91
-7
lines changed

plugins/tutor-contrib-paragon/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ unittest: ## Run code tests cases
2525
pytest tests --ignore=tests/integration
2626

2727
integration-test: ## Run integration tests cases
28-
pytest tests/integration
28+
pytest tests/integration --order-scope=module
2929

3030
dev-requirements: ## Install dev requirements
3131
pip install -e .[dev]

plugins/tutor-contrib-paragon/tests/integration/plugin_functionality_test.py

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"""
88

99
import os
10+
import shutil
11+
import pytest
12+
import re
1013

1114
from .helpers import (
1215
execute_tutor_command,
@@ -16,6 +19,19 @@
1619
)
1720

1821

22+
@pytest.fixture(autouse=True)
23+
def clear_compiled_themes_folder():
24+
"""
25+
Fixture to clear the PARAGON_COMPILED_THEMES_FOLDER after each test.
26+
"""
27+
yield
28+
tutor_root = get_tutor_root_path()
29+
compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER)
30+
if os.path.exists(compiled_path):
31+
shutil.rmtree(compiled_path)
32+
33+
34+
@pytest.mark.order(1)
1935
def test_build_tokens_without_options():
2036
"""
2137
Verify that running the build-tokens job without additional options
@@ -32,6 +48,7 @@ def test_build_tokens_without_options():
3248
assert contents, f"No files were generated in {compiled_path}."
3349

3450

51+
@pytest.mark.order(2)
3552
def test_build_tokens_with_specific_theme():
3653
"""
3754
Verify that running the build-tokens job with the --themes option
@@ -53,12 +70,78 @@ def test_build_tokens_with_specific_theme():
5370
assert os.listdir(theme_path), f"No files were generated inside {theme_path}."
5471

5572

56-
def test_build_tokens_with_invalid_flag_or_parameter():
73+
@pytest.mark.order(3)
74+
def test_build_tokens_excluding_core():
75+
"""
76+
Verify that running the build-tokens job with the --exclude-core option
77+
excludes the core theme from the output.
78+
"""
79+
result = execute_tutor_command(["local", "do", PARAGON_JOB, "--exclude-core"])
80+
assert result.returncode == 0, f"Error excluding core theme: {result.stderr}"
81+
82+
tutor_root = get_tutor_root_path()
83+
compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER)
84+
85+
entries = os.listdir(compiled_path)
86+
assert "core" not in entries, "Core theme should be excluded but was found."
87+
88+
89+
@pytest.mark.order(4)
90+
def test_build_tokens_without_output_token_references():
91+
"""
92+
Ensure that when the build-tokens job is run with --output-references=false,
93+
the generated variables.css file does not contain any CSS variable references (var(--...)).
94+
"""
95+
result = execute_tutor_command(
96+
["local", "do", PARAGON_JOB, "--output-references=false"]
97+
)
98+
assert (
99+
result.returncode == 0
100+
), f"Error running build-tokens with --output-references=false: {result.stderr}"
101+
102+
tutor_root = get_tutor_root_path()
103+
compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER)
104+
105+
core_variables_css = os.path.join(compiled_path, "core", "variables.css")
106+
theme_variables_css = os.path.join(compiled_path, "themes", "light", "variables.css")
107+
108+
assert os.path.exists(core_variables_css), f"{core_variables_css} does not exist."
109+
assert os.path.exists(theme_variables_css), f"{theme_variables_css} does not exist."
110+
111+
with open(core_variables_css, "r", encoding="utf-8") as f:
112+
core_content = f.read()
113+
with open(theme_variables_css, "r", encoding="utf-8") as f:
114+
theme_content = f.read()
115+
116+
token_reference_pattern = re.compile(r"var\(--.*?\)")
117+
core_references = token_reference_pattern.findall(core_content)
118+
theme_references = token_reference_pattern.findall(theme_content)
119+
120+
assert (
121+
not core_references
122+
), f"{core_variables_css} should not contain token references, but found: {core_references}"
123+
assert (
124+
not theme_references
125+
), f"{theme_variables_css} should not contain token references, but found: {theme_references}"
126+
127+
128+
@pytest.mark.order(5)
129+
def test_build_tokens_with_source_tokens_only():
57130
"""
58-
Verify that running the build-tokens job with an invalid flag or parameter
59-
returns a non-zero exit code.
131+
Ensure that when the build-tokens job is run with --source-tokens-only,
132+
the utility-classes.css file is not generated.
60133
"""
61-
result = execute_tutor_command(["local", "do", PARAGON_JOB, "--invalid-flag"])
134+
result = execute_tutor_command(["local", "do", PARAGON_JOB, "--source-tokens-only"])
62135
assert (
63-
result.returncode != 0
64-
), "Expected non-zero return code when using an invalid flag."
136+
result.returncode == 0
137+
), f"Error running build-tokens with --source-tokens-only: {result.stderr}"
138+
139+
tutor_root = get_tutor_root_path()
140+
light_theme_path = os.path.join(
141+
tutor_root, PARAGON_COMPILED_THEMES_FOLDER, "themes", "light"
142+
)
143+
utility_classes_css = os.path.join(light_theme_path, "utility-classes.css")
144+
145+
assert not os.path.exists(
146+
utility_classes_css
147+
), f"{utility_classes_css} should not exist when --source-tokens-only is used."

plugins/tutor-contrib-paragon/tutorparagon/templates/paragon/build/paragon-builder/entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ npx paragon build-tokens \
5353
# Moves the built themes to the final volume directory.
5454
mkdir -p "$FINAL_BUILD_DIR"
5555
cp -a "$TMP_BUILD_DIR/." "$FINAL_BUILD_DIR/"
56+
chmod -R a+rw "$FINAL_BUILD_DIR"
5657

5758
# Clean up
5859
rm -rf "$TMP_BUILD_DIR"

0 commit comments

Comments
 (0)