forked from pyinfra-dev/pyinfra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_global_arguments.py
55 lines (44 loc) · 1.66 KB
/
test_global_arguments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from glob import glob
from importlib import import_module
from inspect import getmembers
from os import path
from types import FunctionType
from unittest import TestCase
try:
from inspect import getfullargspec
except ImportError:
from inspect import signature as getfullargspec
from pyinfra import operations
from pyinfra.api.arguments import all_argument_meta
def _is_pyinfra_operation(module, key, value):
return (
isinstance(value, FunctionType)
and value.__module__ == module.__name__
and getattr(value, "_pyinfra_op", False)
and not value.__name__.startswith("_")
and not key.startswith("_")
)
def iter_operations():
module_filenames = glob(path.join(path.dirname(operations.__file__), "*.py"))
for module_name in sorted(module_filenames):
module = import_module(
"pyinfra.operations.{0}".format(
path.basename(module_name)[:-3],
),
)
for key, value in sorted(getmembers(module)):
if _is_pyinfra_operation(module, key, value):
yield module, value
class TestOperationGlobalArguments(TestCase):
def test_operations_do_not_use_global_arguments(self):
global_arg_keys = all_argument_meta.keys()
for op_module, op_func in iter_operations():
argspec = getfullargspec(op_func._pyinfra_op)
for arg in argspec.args:
assert (
arg not in global_arg_keys
), "`{0}` argument found in {1}.{2} operation function".format(
arg,
op_module.__name__,
op_func.__name__,
)