11import os
2+ import sys
23from unittest .mock import ANY
34
45import pytest
5- import tests_app .core .scripts
66
77from lightning_app .utilities .exceptions import MisconfigurationException
88from lightning_app .utilities .load_app import extract_metadata_from_app , load_app_from_file
99
1010
11- def test_load_app_from_file ():
12- test_script_dir = os .path .join (os .path .dirname (tests_app . core . __file__ ), "scripts" )
11+ def test_load_app_from_file_errors ():
12+ test_script_dir = os .path .join (os .path .dirname (os . path . dirname ( __file__ )), "core" , "scripts" )
1313 with pytest .raises (MisconfigurationException , match = "There should not be multiple apps instantiated within a file" ):
1414 load_app_from_file (os .path .join (test_script_dir , "two_apps.py" ))
1515
@@ -20,8 +20,19 @@ def test_load_app_from_file():
2020 load_app_from_file (os .path .join (test_script_dir , "script_with_error.py" ))
2121
2222
23+ @pytest .mark .parametrize ("app_path" , ["app_metadata.py" , "app_with_local_import.py" ])
24+ def test_load_app_from_file (app_path ):
25+ """Test that apps load without error and that sys.path and main module are set."""
26+ original_main = sys .modules ["__main__" ]
27+ test_script_dir = os .path .join (os .path .dirname (os .path .dirname (__file__ )), "core" , "scripts" )
28+ load_app_from_file (os .path .join (test_script_dir , app_path ), raise_exception = True )
29+
30+ assert test_script_dir in sys .path
31+ assert sys .modules ["__main__" ] != original_main
32+
33+
2334def test_extract_metadata_from_component ():
24- test_script_dir = os .path .join (os .path .dirname (tests_app . core . __file__ ), "scripts" )
35+ test_script_dir = os .path .join (os .path .dirname (os . path . dirname ( __file__ )), "core" , "scripts" )
2536 app = load_app_from_file (os .path .join (test_script_dir , "app_metadata.py" ))
2637 metadata = extract_metadata_from_app (app )
2738 assert metadata == [
0 commit comments