diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-02-05 12:27:32 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-02-05 12:27:32 +0100 |
| commit | 904a033ae738e1c351f8fef71e2ec2418fc4db3d (patch) | |
| tree | 3de4980582c109c4f0d19111a2b88eafec9b9b36 /minishell_test/suite/decorator.py | |
| parent | a3e983f78dc4cbcf6f75f78fa2b3c57e09cd1b2b (diff) | |
| download | minishell_test-904a033ae738e1c351f8fef71e2ec2418fc4db3d.tar.gz minishell_test-904a033ae738e1c351f8fef71e2ec2418fc4db3d.tar.bz2 minishell_test-904a033ae738e1c351f8fef71e2ec2418fc4db3d.zip | |
Renaming src -> minishell_test for package name, Renaming main.py -> __main__.py for package execution with python -m
Diffstat (limited to 'minishell_test/suite/decorator.py')
| -rw-r--r-- | minishell_test/suite/decorator.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/minishell_test/suite/decorator.py b/minishell_test/suite/decorator.py new file mode 100644 index 0000000..fdc7fb6 --- /dev/null +++ b/minishell_test/suite/decorator.py @@ -0,0 +1,47 @@ +# ############################################################################ # +# # +# ::: :::::::: # +# decorator.py :+: :+: :+: # +# +:+ +:+ +:+ # +# By: charles <me@cacharle.xyz> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2020/09/11 12:28:00 by charles #+# #+# # +# Updated: 2021/02/04 16:18:11 by charles ### ########.fr # +# # +# ############################################################################ # + +import inspect +from typing import List + +from suite import Suite +from test import Test + + +def suite(groups: List[str] = [], bonus: bool = False): # type: ignore + """Decorator generator for suites arguments""" + + def suite_wrapper(origin): + """Decorator for a suite function (fmt: suite_[name]) """ + + mod = inspect.getmodule(origin) + if mod is None: + raise NotImplementedError + mod_name = mod.__name__[len("suites."):] + name = "{}/{}".format(mod_name, origin.__name__[len("suite_"):]) + description = origin.__doc__ + if description is None: + print("You should had a doc string to the {} suite".format(name)) + description = "no description" + description = description.split("\n")[0].strip() + s = Suite(name, groups + [mod_name], bonus, description) + + def test_generator(): + def test(*args, **kwargs): + s.add(Test(*args, **kwargs)) + origin(test) + + s.generator_func = test_generator + Suite.available.append(s) + return test_generator + + return suite_wrapper |
