From 838f0c53eb4d21d3c91fe2f2302e5023ae30bb99 Mon Sep 17 00:00:00 2001 From: why-not-try-calmer Date: Tue, 14 Feb 2023 08:53:26 +0100 Subject: [PATCH] Added test to plugin manager --- pytransifex/config-plugins/opengis-mkdocs/main.py | 2 +- pytransifex/plugins_manager.py | 6 ++++-- tests/test_config-plugins.py | 8 ++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pytransifex/config-plugins/opengis-mkdocs/main.py b/pytransifex/config-plugins/opengis-mkdocs/main.py index 609a6b2..fff3eb3 100644 --- a/pytransifex/config-plugins/opengis-mkdocs/main.py +++ b/pytransifex/config-plugins/opengis-mkdocs/main.py @@ -14,7 +14,7 @@ class TxProjectConfig(NamedTuple): TX_TYPE = "GITHUBMARKDOWN" -def create_transifex_config(config: TxProjectConfig): +def create_tx_config(config: TxProjectConfig): """Parse all source documentation files and add the ones with tx_slug metadata defined to transifex config file. """ diff --git a/pytransifex/plugins_manager.py b/pytransifex/plugins_manager.py index ef4054f..3ec428a 100644 --- a/pytransifex/plugins_manager.py +++ b/pytransifex/plugins_manager.py @@ -6,7 +6,7 @@ class PluginManager: - # list of path_to_ subdir, path_to_ main.py + # list of path to subdir, path to main.py discovered_subdir_main: list[tuple[Path, Path]] = [] # successfully imported modules imported_modules: dict[str, Any] = {} @@ -17,7 +17,8 @@ def discover(): Expecting directory structure: pytransifex/ config-plugins/{plugins} - main.py + main.py:create_tx_config + main.py:TxProjectConfig """ plugins_dir = Path.cwd().joinpath("pytransifex", "config-plugins") subdirs = [f for f in plugins_dir.iterdir() if f.is_dir()] @@ -58,6 +59,7 @@ def load_plugin(target_plugin_dir: str): if spec.loader: spec.loader.exec_module(module) PluginManager.imported_modules[name] = module + print( f"Successfully imported and loaded {module}! Imported modules read: {PluginManager.imported_modules}" ) diff --git a/tests/test_config-plugins.py b/tests/test_config-plugins.py index 720a7fc..7e9f484 100644 --- a/tests/test_config-plugins.py +++ b/tests/test_config-plugins.py @@ -14,3 +14,11 @@ def test2_plugin_import(self): def test3_imported_plugin(self): assert PluginManager.imported_modules["opengis-mkdocs"].TxProjectConfig + + def test4_create_config(self): + imported = PluginManager.imported_modules["opengis-mkdocs"] + config_class = imported.TxProjectConfig + create_config = imported.create_tx_config + assert create_config.__name__ == "create_tx_config" + assert all(hasattr(config_class, k) for k in ["TX_ORGANIZATION", "TX_PROJECT", "TX_SOURCE_LANG", "TX_TYPE"]) + \ No newline at end of file