-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·70 lines (52 loc) · 2.37 KB
/
test.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Define tests for jinja2-python-version."""
import platform
import unittest
from jinja2 import Environment
class TestPackagePath(unittest.TestCase):
"""Define test case for extension importing paths."""
def test_package_path(self):
"""Test PythonVersionExtensions can be loaded at package level."""
try:
Environment(extensions=['jinja2_python_version.PythonVersionExtension'])
except AttributeError:
self.fail("AttributeError raised unexpectedly.")
class TestGlobalIsLoaded(unittest.TestCase):
"""Define test case for template global variable."""
def setUp(self):
"""Set up test case."""
self.environment = Environment(extensions=['jinja2_python_version.PythonVersionExtension'])
def test_global_is_set(self):
"""Test global variable is loaded."""
self.assertIn('python_version', self.environment.globals)
class TestVersionOutput(unittest.TestCase):
"""Define test case for version output."""
def setUp(self):
"""Set up test case."""
self.environment = Environment(extensions=['jinja2_python_version.PythonVersionExtension'])
self.version = [str(x) for x in platform.python_version_tuple()]
def test_micro_versions(self):
"""Test micro version output."""
template = self.environment.from_string('{{ python_version.micro }}')
output = template.render()
minor_version = '.'.join(self.version[:3])
self.assertEqual(minor_version, output)
def test_minor_versions(self):
"""Test minor version output."""
template = self.environment.from_string('{{ python_version.minor }}')
output = template.render()
minor_version = '.'.join(self.version[:2])
self.assertEqual(minor_version, output)
def test_major_versions(self):
"""Test major version output."""
template = self.environment.from_string('{{ python_version.major }}')
output = template.render()
minor_version = '.'.join(self.version[:1])
self.assertEqual(minor_version, output)
def test_versions(self):
"""Test version output."""
template = self.environment.from_string('{{ python_version }}')
output = template.render()
minor_version = '.'.join(self.version[:2])
self.assertEqual(minor_version, output)
if __name__ == '__main__':
unittest.main()