Skip to content

Commit

Permalink
Merge pull request #83 from Geson-anko/BaseApp/set_config_attrs
Browse files Browse the repository at this point in the history
Base app/set config attrs
  • Loading branch information
Geson-anko committed May 7, 2022
2 parents 57f9933 + ef1296b commit dec9269
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
20 changes: 19 additions & 1 deletion JarvisEngine/apps/base_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,22 @@ def app_dir(self) -> str or None:

@property
def logger(self) -> logging_tool.Logger:
return self.__logger
return self.__logger

def set_config_attrs(self) -> None:
"""set config attrs to self.
- module_name: str
The import name of the application.
- is_thread: bool
Whether the App is thread or process.
- child_app_configs:
Child app configs of the application.
"""
self.module_name:str = self.config.path
self.is_thread:bool = self.config.thread

if hasattr(self.config, "apps"):
self.child_app_configs = self.config.apps
else:
self.child_app_configs = AttrDict()

23 changes: 22 additions & 1 deletion tests/apps/test_base_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,25 @@ def test_properties():
_check_property_override(app, "engine_config")
_check_property_override(app, "project_config")
_check_property_override(app, "app_dir")
_check_property_override(app, "logger")
_check_property_override(app, "logger")

def test_set_config_attrs():
name = "MAIN.App1"
config = project_config.App1
app_dir = "TestEngineProject/App1"
app = base_app.BaseApp(name, config, engine_config, project_config, app_dir)
app.set_config_attrs()

assert app.module_name == config.path
assert app.is_thread == config.thread
assert app.child_app_configs == config.apps

name = "MAIN.App0"
config = project_config.App0
app_dir = "TestEngineProject/App0"
app = base_app.BaseApp(name, config, engine_config, project_config, app_dir)
app.set_config_attrs()

assert app.module_name == config.path
assert app.is_thread == config.thread
assert app.child_app_configs == base_app.AttrDict()

0 comments on commit dec9269

Please sign in to comment.