Total Complexity | 10 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | #!/usr/bin/env python3 |
||
2 | |||
3 | # -*- coding: utf-8 -*- |
||
4 | |||
5 | 1 | import importlib |
|
6 | 1 | import inspect |
|
7 | 1 | import sys |
|
8 | |||
9 | # mixin for ansible.plugins.filters.* |
||
10 | |||
11 | 1 | class FilterModule(object): |
|
12 | |||
13 | 1 | def __init__(self): |
|
14 | 1 | self._filters = {} |
|
15 | |||
16 | 1 | def filters(self): |
|
17 | |||
18 | 1 | for spec in [ |
|
19 | 'ansible.plugins.filter.core', |
||
20 | 'ansible.plugins.filter.mathstuff', |
||
21 | 'ansible.plugins.filter.urls', |
||
22 | 'ansible.plugins.filter.urlsplit', |
||
23 | ]: |
||
24 | |||
25 | 1 | mod = importlib.import_module(spec) |
|
26 | |||
27 | 1 | if hasattr(mod, 'FilterModule'): |
|
28 | 1 | _filters = mod.FilterModule().filters() |
|
29 | 1 | for k,v in _filters.items(): |
|
30 | 1 | self._filters.update( { |
|
31 | k: [ "{}.{}".format(spec, k), v ] |
||
32 | } ) |
||
33 | |||
34 | 1 | del mod |
|
35 | 1 | return self._filters |
|
36 | |||
37 | 1 | class TestModule(object): |
|
38 | |||
39 | 1 | def __init__(self): |
|
40 | 1 | self._tests = {} |
|
41 | |||
42 | 1 | def tests(self): |
|
43 | |||
44 | 1 | for spec in [ |
|
45 | 'ansible.plugins.test.core', |
||
46 | 'ansible.plugins.test.files', |
||
47 | 'ansible.plugins.test.mathstuff', |
||
48 | ]: |
||
49 | |||
50 | 1 | mod = importlib.import_module(spec) |
|
51 | |||
52 | 1 | if hasattr(mod, 'TestModule'): |
|
53 | 1 | _tests = mod.TestModule().tests() |
|
54 | 1 | for k,v in _tests.items(): |
|
55 | 1 | self._tests.update( { |
|
56 | k: [ "{}.{}".format(spec, k), v ] |
||
57 | } ) |
||
58 | |||
59 | 1 | del mod |
|
60 | return self._tests |
||
61 |