feat(examples): enhance bug_checkand full_test with detailed verification and summary
- New Features: - Added comprehensive test runner that cleans up temporary directories, verifies generated files, and prints a pass/fail summary. - Introduced specific validation for pytest configuration, Vite integration, and Dockerfile dependencies based on selected metadata. - Implemented clear pass/fail reporting with overall success metrics. - Enhancements: - Refactored bug_check.py to use explicit data structures and consistent double‑quote quoting for path construction. - Improved formatting and readability of metadata definitions and context preparation. - Fixed Windows‑specific path handling regression by switching to double‑quoted string interpolation. - Bug Fixes: - Corrected path building to use double‑quoted strings, preventing potential path parsing issues on Windows.
This commit is contained in:
5 files changed
+427
-113
No files matched your search
+33
-21
@@ -6,10 +6,11 @@ Comprehensive test for all djinit features.
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
|
||||
|
||||
from djinit.creators.setup import SetupCreator
|
||||
|
||||
|
||||
def create_project(name, metadata):
|
||||
"""Create a test project."""
|
||||
test_dir = "/tmp/djinit_full_test"
|
||||
@@ -36,15 +37,11 @@ def create_project(name, metadata):
|
||||
"unified_structure": False,
|
||||
"single_structure": False,
|
||||
"project_module_name": "config",
|
||||
**metadata
|
||||
**metadata,
|
||||
}
|
||||
|
||||
creator = SetupCreator(
|
||||
project_dir=name,
|
||||
project_name=name,
|
||||
primary_app="users",
|
||||
app_names=["users"],
|
||||
metadata=full_metadata
|
||||
project_dir=name, project_name=name, primary_app="users", app_names=["users"], metadata=full_metadata
|
||||
)
|
||||
success = creator.create()
|
||||
return success, test_dir
|
||||
@@ -79,8 +76,22 @@ def run_tests():
|
||||
("vite", {"use_vite": True}, ["vite.config.js", "package.json", "frontend/index.html"]),
|
||||
("tailwind", {"use_tailwind": True}, ["requirements.txt"]),
|
||||
("htmx", {"use_htmx": True}, ["requirements.txt"]),
|
||||
("all_postgres", {"use_docker": True, "use_vite": True, "use_tailwind": True, "use_htmx": True, "database_type": "postgresql"}, ["Dockerfile", "docker-compose.yml", "vite.config.js"]),
|
||||
("all_mysql", {"use_docker": True, "use_vite": True, "use_tailwind": True, "database_type": "mysql"}, ["Dockerfile", "docker-compose.yml", "vite.config.js"]),
|
||||
(
|
||||
"all_postgres",
|
||||
{
|
||||
"use_docker": True,
|
||||
"use_vite": True,
|
||||
"use_tailwind": True,
|
||||
"use_htmx": True,
|
||||
"database_type": "postgresql",
|
||||
},
|
||||
["Dockerfile", "docker-compose.yml", "vite.config.js"],
|
||||
),
|
||||
(
|
||||
"all_mysql",
|
||||
{"use_docker": True, "use_vite": True, "use_tailwind": True, "database_type": "mysql"},
|
||||
["Dockerfile", "docker-compose.yml", "vite.config.js"],
|
||||
),
|
||||
]
|
||||
|
||||
results = []
|
||||
@@ -92,6 +103,7 @@ def run_tests():
|
||||
|
||||
# Clean up
|
||||
import shutil
|
||||
|
||||
test_dir = "/tmp/djinit_full_test"
|
||||
if os.path.exists(test_dir):
|
||||
shutil.rmtree(test_dir)
|
||||
@@ -101,7 +113,7 @@ def run_tests():
|
||||
|
||||
if not success:
|
||||
results.append((name, False, "Project creation failed"))
|
||||
print(f" ✗ Failed to create project")
|
||||
print(" ✗ Failed to create project")
|
||||
continue
|
||||
|
||||
# Verify files
|
||||
@@ -126,18 +138,18 @@ def run_tests():
|
||||
if not exists:
|
||||
all_passed = False
|
||||
errors.append("django_vite not in settings")
|
||||
print(f" ✗ django_vite not in settings")
|
||||
print(" ✗ django_vite not in settings")
|
||||
else:
|
||||
print(f" ✓ django_vite in settings")
|
||||
print(" ✓ django_vite in settings")
|
||||
|
||||
req_path = os.path.join(project_dir, "requirements.txt")
|
||||
exists, msg = verify_file(req_path, "django-vite")
|
||||
if not exists:
|
||||
all_passed = False
|
||||
errors.append("django-vite not in requirements")
|
||||
print(f" ✗ django-vite not in requirements")
|
||||
print(" ✗ django-vite not in requirements")
|
||||
else:
|
||||
print(f" ✓ django-vite in requirements")
|
||||
print(" ✓ django-vite in requirements")
|
||||
|
||||
# Special checks for docker
|
||||
if metadata.get("use_docker"):
|
||||
@@ -147,23 +159,23 @@ def run_tests():
|
||||
exists, msg = verify_file(dockerfile_path, "default-libmysqlclient-dev")
|
||||
if not exists:
|
||||
all_passed = False
|
||||
print(f" ✗ MySQL client not in Dockerfile")
|
||||
print(" ✗ MySQL client not in Dockerfile")
|
||||
else:
|
||||
print(f" ✓ MySQL client in Dockerfile")
|
||||
print(" ✓ MySQL client in Dockerfile")
|
||||
else:
|
||||
exists, msg = verify_file(dockerfile_path, "libpq-dev")
|
||||
if not exists:
|
||||
all_passed = False
|
||||
print(f" ✗ PostgreSQL client not in Dockerfile")
|
||||
print(" ✗ PostgreSQL client not in Dockerfile")
|
||||
else:
|
||||
print(f" ✓ PostgreSQL client in Dockerfile")
|
||||
print(" ✓ PostgreSQL client in Dockerfile")
|
||||
|
||||
if all_passed:
|
||||
results.append((name, True, "All checks passed"))
|
||||
print(f" ✓ ALL CHECKS PASSED")
|
||||
print(" ✓ ALL CHECKS PASSED")
|
||||
else:
|
||||
results.append((name, False, "; ".join(errors)))
|
||||
print(f" ✗ SOME CHECKS FAILED")
|
||||
print(" ✗ SOME CHECKS FAILED")
|
||||
|
||||
# Summary
|
||||
print("\n" + "=" * 70)
|
||||
@@ -186,4 +198,4 @@ def run_tests():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
run_tests()
|
||||
Reference in new issue
Block a user