From 9fd1954be304ec7691667b635f10eb61bd5e25d8 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 31 May 2023 11:36:49 +0200 Subject: Adding an importFromTestPackage function for testing purpose. --- src/argaze/utils/MiscFeatures.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src') diff --git a/src/argaze/utils/MiscFeatures.py b/src/argaze/utils/MiscFeatures.py index 46e0269..09c289d 100644 --- a/src/argaze/utils/MiscFeatures.py +++ b/src/argaze/utils/MiscFeatures.py @@ -30,6 +30,26 @@ def printProgressBar (iteration:int, total:int, prefix:str = '', suffix:str = '' if iteration == total: print() +def importFromTestPackage(module: str): + """Import module from ArGaze test package. + * **Returns:** + - a module named Test""" + + import argaze + import importlib.util + import sys + import os + + source_directory = os.path.dirname(os.path.dirname(os.path.abspath(argaze.__file__))) + module_directory = os.path.join(source_directory, 'argaze.test', f'{module}.py') + + spec = importlib.util.spec_from_file_location(f'{module}Test', module_directory) + TestModule = importlib.util.module_from_spec(spec) + sys.modules[f'{module}Test'] = TestModule + spec.loader.exec_module(TestModule) + + return TestModule + class ExitSignalHandler(): """Handle exit event""" def __init__(self): -- cgit v1.1