File size: 903 Bytes
aaf6dc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""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()