Test Failed
Branch feature/user-customizations (24e3d3)
by Shalom
03:23
created

inji.tests._is_prime()   A

Complexity

Conditions 4

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 4
nop 1
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
from jinja2 import is_undefined
10
import re
11
import sys
12
import math
13
import os
14
15
def _is_prime(n):
16
  if n == 2:
17
    return True
18
  for i in range(2, int(math.ceil(math.sqrt(n))) + 1):
19
    if n % i == 0:
20
      return False
21
  return True
22
23
tests = dict(
24
25
  is_prime = ( """ Tests if a number is prime """,
26
    lambda v: _is_prime(v)
27
  ),
28
29
)
30
31
if 'USE_ANSIBLE_SUPPORT' in os.environ.keys():
32
  from .ansible import TestModule
33
  tests.update(TestModule().tests())
34
35
for k,v in tests.items():
36
  setattr(sys.modules[__name__], k, v[1])
37