from pathlib import Path import unittest ROOT = Path(__file__).resolve().parents[1] def read_text(relative_path: str) -> str: return (ROOT / relative_path).read_text(encoding="utf-8") class EnhanceStageContractTest(unittest.TestCase): def test_enhance_modes_match_product_contract(self): app = read_text("app.py") self.assertIn('ENHANCE_MODE_OFF = "Off"', app) self.assertIn('ENHANCE_MODE_UPSCALE = "Upscale"', app) self.assertIn('ENHANCE_MODE_CLEAN = "Clean"', app) self.assertIn('ENHANCE_MODE_MAX_DETAIL = "Max Detail"', app) self.assertIn( "ENHANCE_MODE_CHOICES = [ENHANCE_MODE_OFF, ENHANCE_MODE_UPSCALE, ENHANCE_MODE_CLEAN, ENHANCE_MODE_MAX_DETAIL]", app, ) self.assertIn("enhance_mode = gr.Radio", app) self.assertIn("apply_enhancement", app) def test_upscaler_is_lazy_and_configurable(self): app = read_text("app.py") self.assertIn("load_upscaler_model", app) self.assertIn("UPSCALER_MODEL_ID", app) self.assertIn("UPSCALER_MODEL_FILENAME", app) self.assertIn("hf_hub_download(", app) self.assertIn("spandrel", app) self.assertIn("tile_upscale", app) def test_upscaler_dependencies_are_declared(self): requirements = read_text("requirements.txt") self.assertIn("spandrel", requirements) self.assertIn("spandrel_extra_arches", requirements) if __name__ == "__main__": unittest.main()