File tree Expand file tree Collapse file tree 3 files changed +28
-7
lines changed
Expand file tree Collapse file tree 3 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,8 @@ def __init__(
8686 should_save = not self .__operator .disabled ,
8787 version = get_package_version (),
8888 )
89- self .__public = SwanLabPublicConfig (self .__project_name , self .__settings )
89+ self .__mode = get_mode ()
90+ self .__public = SwanLabPublicConfig (self .__project_name , self .__settings , self .__mode )
9091 self .__operator .before_run (self .__settings )
9192 # ---------------------------------- 初始化日志记录器 ----------------------------------
9293 swanlog .level = check_log_level (log_level )
@@ -216,7 +217,7 @@ def public(self):
216217
217218 @property
218219 def mode (self ) -> str :
219- return get_mode ()
220+ return self . __mode
220221
221222 @property
222223 def state (self ) -> SwanLabRunState :
Original file line number Diff line number Diff line change 44from swanlab .package import get_project_url , get_experiment_url
55
66
7- class SwanlabCloudConfig :
7+ class SwanlabModeConfig :
88 """
9- public data for the SwanLab project when running in cloud mode.
9+ public data for the SwanLab project when running in different modes.
10+ Only available in cloud mode.
1011 """
1112
12- def __init__ (self ):
13+ def __init__ (self , mode : str ):
1314 self .__http = None
15+ self .__mode = mode
1416
1517 def __get_property_from_http (self , name : str ):
1618 """
@@ -27,6 +29,8 @@ def available(self):
2729 """
2830 Whether the SwanLab is running in cloud mode.
2931 """
32+ if self .__mode != "cloud" :
33+ return False
3034 try :
3135 if self .__http is None :
3236 self .__http = get_http ()
@@ -79,9 +83,9 @@ class SwanLabPublicConfig:
7983 Public data for the SwanLab project.
8084 """
8185
82- def __init__ (self , project_name : str , settings : SwanLabSharedSettings ):
86+ def __init__ (self , project_name : str , settings : SwanLabSharedSettings , mode : str ):
8387 self .__project_name = project_name
84- self .__cloud = SwanlabCloudConfig ( )
88+ self .__cloud = SwanlabModeConfig ( mode )
8589 self .__settings = settings
8690
8791 def json (self ):
Original file line number Diff line number Diff line change @@ -26,6 +26,9 @@ def setup_function():
2626 在当前测试文件下的每个测试函数执行前后执行
2727 """
2828 swanlog .disable_log ()
29+ run = get_run ()
30+ if run is not None :
31+ run .finish ()
2932 yield
3033 run = get_run ()
3134 if run is not None :
@@ -153,6 +156,8 @@ def test_init_local(self):
153156 run = S .init (mode = "local" )
154157 assert os .environ [MODE ] == "local"
155158 run .log ({"TestInitMode" : 1 }) # 不会报错
159+ assert run .mode == "local"
160+ assert run .public .cloud .available is False
156161 assert get_run () is not None
157162 assert run .public .cloud .project_name is None
158163
@@ -181,6 +186,17 @@ def test_init_error(self):
181186 S .init (mode = "123456" ) # noqa
182187 assert get_run () is None
183188
189+ @pytest .mark .skipif (T .is_skip_cloud_test , reason = "skip cloud test" )
190+ def test_init_multiple (self ):
191+ # 先初始化cloud
192+ self .test_init_cloud ()
193+ get_run ().finish ()
194+ # 再初始化local
195+ self .test_init_local ()
196+ get_run ().finish ()
197+ # 再初始化disabled
198+ self .test_init_disabled ()
199+
184200 # ---------------------------------- 测试环境变量输入 ----------------------------------
185201
186202 def test_init_disabled_env (self ):
You can’t perform that action at this time.
0 commit comments