Spaces:
Sleeping
Sleeping
| """Quick test for load_app behavior. | |
| Creates a temporary 'space' directory with an app.py exposing different shapes | |
| and ensures load_app can find a launchable object. | |
| """ | |
| import tempfile | |
| import shutil | |
| from pathlib import Path | |
| import sys | |
| # Ensure we can import load_app from app.py in workspace | |
| sys.path.insert(0, str(Path(__file__).parent)) | |
| from app import load_app | |
| TEST_APP_TEMPLATE = ''' | |
| # dummy space app | |
| class MockApp: | |
| def launch(self): | |
| print("LAUNCHED MOCK APP") | |
| def create_secure_interface(): | |
| return MockApp() | |
| ''' | |
| def main(): | |
| tmpdir = Path(tempfile.mkdtemp()) | |
| try: | |
| app_py = tmpdir / "app.py" | |
| app_py.write_text(TEST_APP_TEMPLATE) | |
| demo = load_app(tmpdir) | |
| print("Found demo object:", type(demo)) | |
| # call launch to see it works | |
| demo.launch() | |
| finally: | |
| shutil.rmtree(tmpdir) | |
| if __name__ == '__main__': | |
| main() | |