Buckets:
tahamajs/Sysmem2_in_AI / ComputerAssignments /CA4_visual_question_answering /tests /test_structure.py
| #!/usr/bin/env python3 | |
| import os | |
| import sys | |
| from pathlib import Path | |
| def test_basic_structure(): | |
| print("🔍 بررسی ساختار فایلها...") | |
| required_files = [ | |
| "main.py", | |
| "run.sh", | |
| "requirements.txt", | |
| "README.md", | |
| "src/__init__.py", | |
| "src/config/config.py", | |
| "src/config/default_config.yaml", | |
| "src/models/neural_module_networks.py", | |
| "src/models/scene_graph_models.py", | |
| "src/models/hybrid_vqa.py", | |
| "src/data/dataset.py", | |
| "src/evaluation/metrics.py", | |
| "src/visualization/visualizer.py", | |
| "src/demo/demo.py", | |
| "src/utils/base_classes.py", | |
| ] | |
| missing = [] | |
| for file_path in required_files: | |
| if os.path.exists(file_path): | |
| print(f"✅ {file_path}") | |
| else: | |
| print(f"❌ {file_path}") | |
| missing.append(file_path) | |
| return len(missing) == 0, missing | |
| def test_directory_structure(): | |
| print("\n📁 بررسی ساختار پوشهها...") | |
| required_dirs = [ | |
| "src", | |
| "src/config", | |
| "src/models", | |
| "src/data", | |
| "src/evaluation", | |
| "src/visualization", | |
| "src/demo", | |
| "src/utils", | |
| ] | |
| missing = [] | |
| for dir_path in required_dirs: | |
| if os.path.isdir(dir_path): | |
| print(f"✅ {dir_path}/") | |
| else: | |
| print(f"❌ {dir_path}/") | |
| missing.append(dir_path) | |
| return len(missing) == 0, missing | |
| def test_file_sizes(): | |
| print("\n📊 بررسی اندازه فایلها...") | |
| important_files = [ | |
| "main.py", | |
| "src/models/neural_module_networks.py", | |
| "src/models/scene_graph_models.py", | |
| "src/models/hybrid_vqa.py", | |
| "src/data/dataset.py", | |
| "src/evaluation/metrics.py", | |
| "src/visualization/visualizer.py", | |
| "src/demo/demo.py", | |
| ] | |
| for file_path in important_files: | |
| if os.path.exists(file_path): | |
| size = os.path.getsize(file_path) | |
| print(f"✅ {file_path}: {size:,} bytes") | |
| else: | |
| print(f"❌ {file_path}: فایل یافت نشد") | |
| def test_python_syntax(): | |
| print("\n🐍 بررسی syntax فایلهای Python...") | |
| python_files = [ | |
| "main.py", | |
| "src/config/config.py", | |
| "src/models/neural_module_networks.py", | |
| "src/models/scene_graph_models.py", | |
| "src/models/hybrid_vqa.py", | |
| "src/data/dataset.py", | |
| "src/evaluation/metrics.py", | |
| "src/visualization/visualizer.py", | |
| "src/demo/demo.py", | |
| "src/utils/base_classes.py", | |
| ] | |
| syntax_errors = [] | |
| for file_path in python_files: | |
| if os.path.exists(file_path): | |
| try: | |
| with open(file_path, "r", encoding="utf-8") as f: | |
| compile(f.read(), file_path, "exec") | |
| print(f"✅ {file_path}") | |
| except SyntaxError as e: | |
| print(f"❌ {file_path}: خطای syntax در خط {e.lineno}") | |
| syntax_errors.append(file_path) | |
| except Exception as e: | |
| print(f"⚠️ {file_path}: خطای دیگر - {e}") | |
| else: | |
| print(f"❌ {file_path}: فایل یافت نشد") | |
| return len(syntax_errors) == 0, syntax_errors | |
| def test_import_structure(): | |
| print("\n📦 بررسی ساختار import ها...") | |
| init_files = [ | |
| "src/__init__.py", | |
| "src/config/__init__.py", | |
| "src/models/__init__.py", | |
| "src/data/__init__.py", | |
| "src/evaluation/__init__.py", | |
| "src/visualization/__init__.py", | |
| "src/demo/__init__.py", | |
| "src/utils/__init__.py", | |
| ] | |
| for init_file in init_files: | |
| if os.path.exists(init_file): | |
| print(f"✅ {init_file}") | |
| else: | |
| print(f"❌ {init_file}") | |
| def test_readme_content(): | |
| print("\n📖 بررسی محتوای README...") | |
| if os.path.exists("README.md"): | |
| with open("README.md", "r", encoding="utf-8") as f: | |
| content = f.read() | |
| required_sections = [ | |
| "# سیستم VQA نوروسیمبولیک", | |
| "## 📋 معرفی", | |
| "## 🚀 ویژگیها", | |
| "## 📁 ساختار پروژه", | |
| "## 🛠️ نصب و راهاندازی", | |
| "## 🎮 استفاده", | |
| ] | |
| missing_sections = [] | |
| for section in required_sections: | |
| if section in content: | |
| print(f"✅ بخش: {section}") | |
| else: | |
| print(f"❌ بخش: {section}") | |
| missing_sections.append(section) | |
| return len(missing_sections) == 0, missing_sections | |
| else: | |
| print("❌ فایل README.md یافت نشد") | |
| return False, ["README.md"] | |
| def test_requirements(): | |
| print("\n📋 بررسی فایل requirements...") | |
| if os.path.exists("requirements.txt"): | |
| with open("requirements.txt", "r", encoding="utf-8") as f: | |
| content = f.read() | |
| required_packages = [ | |
| "torch", | |
| "torchvision", | |
| "numpy", | |
| "matplotlib", | |
| "seaborn", | |
| "networkx", | |
| "pillow", | |
| ] | |
| missing_packages = [] | |
| for package in required_packages: | |
| if package in content.lower(): | |
| print(f"✅ {package}") | |
| else: | |
| print(f"❌ {package}") | |
| missing_packages.append(package) | |
| return len(missing_packages) == 0, missing_packages | |
| else: | |
| print("❌ فایل requirements.txt یافت نشد") | |
| return False, ["requirements.txt"] | |
| def main(): | |
| print("🧪 تست ساختار سیستم VQA") | |
| print("=" * 50) | |
| tests = [ | |
| ("ساختار فایلها", test_basic_structure), | |
| ("ساختار پوشهها", test_directory_structure), | |
| ("اندازه فایلها", test_file_sizes), | |
| ("Syntax Python", test_python_syntax), | |
| ("ساختار Import", test_import_structure), | |
| ("محتوای README", test_readme_content), | |
| ("فایل Requirements", test_requirements), | |
| ] | |
| results = [] | |
| for test_name, test_func in tests: | |
| print(f"\n🔍 {test_name}:") | |
| print("-" * 30) | |
| try: | |
| if test_name in ["اندازه فایلها", "ساختار Import"]: | |
| test_func() | |
| results.append((test_name, True)) | |
| else: | |
| result, missing = test_func() | |
| results.append((test_name, result)) | |
| if not result and missing: | |
| print(f"⚠️ موارد مفقود: {missing}") | |
| except Exception as e: | |
| print(f"❌ خطا: {e}") | |
| results.append((test_name, False)) | |
| print("\n" + "=" * 50) | |
| print("📊 خلاصه نتایج:") | |
| print("=" * 50) | |
| passed = 0 | |
| for test_name, result in results: | |
| status = "✅ PASS" if result else "❌ FAIL" | |
| print(f"{status} {test_name}") | |
| if result: | |
| passed += 1 | |
| print(f"\n🎯 {passed}/{len(results)} تست موفق") | |
| if passed == len(results): | |
| print("🎉 همه تستها موفق! سیستم آماده است.") | |
| return True | |
| else: | |
| print("⚠️ برخی تستها ناموفق. لطفاً مشکلات را بررسی کنید.") | |
| return False | |
| if __name__ == "__main__": | |
| success = main() | |
| sys.exit(0 if success else 1) | |
Xet Storage Details
- Size:
- 7.54 kB
- Xet hash:
- 334479652eeef0c8e6a7e0772021d56c0d3cfd0068386e2a7bf9dc0ef445aeda
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.