nodeslicer/tests/test_profiles.py

61 lines
2.5 KiB
Python

import os
import sys
import unittest
from pathlib import Path
# Add the project root to sys.path
PROJECT_ROOT = Path(__file__).resolve().parent.parent
sys.path.append(str(PROJECT_ROOT))
from infra.prusaslicer_profiles.cache import LocalCache
from infra.prusaslicer_profiles.fields import search_in_db
class TestPrusaSlicerProfiles(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.cache = LocalCache()
cls.test_dir = PROJECT_ROOT / "tests"
cls.ini_file = cls.test_dir / "2.4.5.ini"
if not cls.ini_file.exists():
raise FileNotFoundError(f"Test baseline {cls.ini_file} not found.")
cls.cache.load([cls.test_dir])
def test_profile_counts(self):
"""Verify that a large number of profiles are loaded from the baseline INI."""
self.assertGreater(len(self.cache.profiles), 6000)
self.assertGreater(len(self.cache.printer_profiles), 200)
self.assertGreater(len(self.cache.print_profiles), 500)
self.assertGreater(len(self.cache.filament_profiles), 5000)
def test_inheritance_and_vendor(self):
"""Verify that inheritance is resolved and vendor information is extracted."""
# Find a known filament profile
filament_keys = [k for k in self.cache.display_profiles.keys() if k.startswith("filament:")]
self.assertGreater(len(filament_keys), 0)
profile = self.cache.profiles[filament_keys[0]]
self.assertTrue(len(profile.all_conf_dict) > 0)
self.assertTrue(profile.vendor or profile.all_conf_dict.get('filament_vendor') is None)
def test_fields_database(self):
"""Verify that the fields database is accessible and searchable."""
res = search_in_db("bed shape")
self.assertIn("bed_shape", res)
self.assertEqual(res["bed_shape"].get("label"), "Bed shape")
def test_compatibility(self):
"""Verify that compatibility evaluation runs without errors."""
printer_keys = set(self.cache.printer_profiles.keys())
vendors = set(self.cache.vendors)
# This should not raise any exceptions
self.cache.evaluate_compatibility(printer_keys, vendors)
# Check if at least one printer has compatible profiles
has_compatible = any(p.compatible_profiles for p in self.cache.printer_profiles.values())
self.assertTrue(has_compatible, "No compatible profiles found for any printer.")
if __name__ == "__main__":
unittest.main()