tests.py (2018B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\lib\jinja2\tests.py 2 import re 3 from jinja2.runtime import Undefined 4 try: 5 from collections import Mapping as MappingType 6 except ImportError: 7 import UserDict 8 MappingType = (UserDict.UserDict, UserDict.DictMixin, dict) 9 10 __test__ = False 11 number_re = re.compile('^-?\\d+(\\.\\d+)?$') 12 regex_type = type(number_re) 13 try: 14 test_callable = callable 15 except NameError: 16 17 def test_callable(x): 18 return hasattr(x, '__call__') 19 20 21 def test_odd(value): 22 return value % 2 == 1 23 24 25 def test_even(value): 26 return value % 2 == 0 27 28 29 def test_divisibleby(value, num): 30 return value % num == 0 31 32 33 def test_defined(value): 34 return not isinstance(value, Undefined) 35 36 37 def test_undefined(value): 38 return isinstance(value, Undefined) 39 40 41 def test_none(value): 42 return value is None 43 44 45 def test_lower(value): 46 return unicode(value).islower() 47 48 49 def test_upper(value): 50 return unicode(value).isupper() 51 52 53 def test_string(value): 54 return isinstance(value, basestring) 55 56 57 def test_mapping(value): 58 return isinstance(value, MappingType) 59 60 61 def test_number(value): 62 return isinstance(value, (int, 63 long, 64 float, 65 complex)) 66 67 68 def test_sequence(value): 69 try: 70 len(value) 71 value.__getitem__ 72 except: 73 return False 74 75 return True 76 77 78 def test_sameas(value, other): 79 return value is other 80 81 82 def test_iterable(value): 83 try: 84 iter(value) 85 except TypeError: 86 return False 87 88 return True 89 90 91 def test_escaped(value): 92 return hasattr(value, '__html__') 93 94 95 TESTS = {'odd': test_odd, 96 'even': test_even, 97 'divisibleby': test_divisibleby, 98 'defined': test_defined, 99 'undefined': test_undefined, 100 'none': test_none, 101 'lower': test_lower, 102 'upper': test_upper, 103 'string': test_string, 104 'mapping': test_mapping, 105 'number': test_number, 106 'sequence': test_sequence, 107 'iterable': test_iterable, 108 'callable': test_callable, 109 'sameas': test_sameas, 110 'escaped': test_escaped}