diff --git a/tests/modules/tools.py b/src/bootstraparse/modules/tools.py similarity index 86% rename from tests/modules/tools.py rename to src/bootstraparse/modules/tools.py index 8b308ec..34fe94c 100644 --- a/tests/modules/tools.py +++ b/src/bootstraparse/modules/tools.py @@ -9,6 +9,7 @@ import re ############################################################################### # Paths ######################################## +import rich def __base(): @@ -17,7 +18,7 @@ def __base(): :return: Path of the main module :rtype: str """ - return "../../src/bootstraparse/" + return "." def __module_path(module_name): @@ -28,15 +29,38 @@ def __module_path(module_name): :return: Path of the module :rtype: str """ - return os.path.normpath(os.path.join(os.path.dirname(__file__), __base(), "modules", module_name)) + return os.path.normpath(os.path.join(os.path.dirname(__file__), __base(), module_name)) ############################################################################### # Frame inspection ######################################## # Cursed frame inspection +def __prev_stack(nb=0): + """ + Return the nth previous stack + :return: Previous stack + :rtype: inspect.Traceback + """ + for frame in inspect.stack()[1 + nb:]: + return frame + return inspect.getframeinfo(inspect.currentframe().f_back) + + def __GL(): - return inspect.getframeinfo(inspect.currentframe().f_back).lineno + return __prev_stack().lineno + + +def __GFu(): + return __prev_stack().function + + +def __GFi(): + return __prev_stack().filename + + +def __GLk(): + return f' File "{__prev_stack(2).filename}", line {max(__prev_stack(2).lineno, 1)}'.replace("\\", "/") ############################################################################### diff --git a/tests/modules/test_syntax.py b/tests/modules/test_syntax.py index 4a99231..5ede5f9 100644 --- a/tests/modules/test_syntax.py +++ b/tests/modules/test_syntax.py @@ -4,7 +4,7 @@ import pyparsing import pytest import bootstraparse.modules.syntax as sy -from tools import __GL, __module_path, find_variables_in_file # , find_functions_in_file, find_classes_in_file +from bootstraparse.modules.tools import __GL, __module_path, find_variables_in_file # , find_functions_in_file, find_classes_in_file ptp = pytest.param __XF = pytest.mark.xfail