Total Complexity | 4 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | #!/usr/bin/env python3 |
||
2 | |||
3 | # -*- coding: utf-8 -*- |
||
4 | |||
5 | # Hold custom jinja2 tests |
||
6 | # https://jinja.palletsprojects.com/en/2.11.x/api/#custom-tests |
||
7 | # https://jinja.palletsprojects.com/en/2.11.x/templates/#list-of-builtin-tests |
||
8 | |||
9 | 1 | from jinja2 import is_undefined |
|
10 | 1 | import re |
|
11 | 1 | import sys |
|
12 | 1 | import math |
|
13 | 1 | import os |
|
14 | |||
15 | 1 | def _is_prime(n): |
|
16 | 1 | if n == 2: |
|
17 | 1 | return True |
|
18 | 1 | for i in range(2, int(math.ceil(math.sqrt(n))) + 1): |
|
19 | 1 | if n % i == 0: |
|
20 | 1 | return False |
|
21 | 1 | return True |
|
22 | |||
23 | 1 | tests = dict( |
|
24 | |||
25 | is_prime = ( """ Tests if a number is prime """, |
||
26 | lambda v: _is_prime(v) |
||
27 | ), |
||
28 | |||
29 | ) |
||
30 | |||
31 | 1 | if 'USE_ANSIBLE_SUPPORT' in os.environ.keys(): |
|
32 | 1 | from .ansible import TestModule |
|
33 | 1 | tests.update(TestModule().tests()) |
|
34 | |||
35 | 1 | for k,v in tests.items(): |
|
36 | setattr(sys.modules[__name__], k, v[1]) |
||
37 |