-
Notifications
You must be signed in to change notification settings - Fork 29
/
unit-tests.py
69 lines (51 loc) · 1.82 KB
/
unit-tests.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
import os
import unittest
from enums import GitHubActionsInput
from main import Context
class TestContext(unittest.TestCase):
TEST_FILE = 'test_output'
def test_load_from_env(self):
env_vars = {
'foo': 'bar',
GitHubActionsInput.VARIABLES.value: 'name=John\nsurname=Doe'
}
context = Context(env_vars)
context.load_from_env()
expected = {'env': env_vars}
self.assertEqual(context._variables, expected)
def test_load_from_input(self):
context = Context({GitHubActionsInput.VARIABLES.value: 'name=John\nsurname=Doe'})
context.load_from_input()
expected = {
'name': 'John',
'surname': 'Doe',
}
self.assertEqual(context._variables, expected)
def test_load_from_data_file(self):
context = Context({
GitHubActionsInput.DATA_FILE.value: 'test/data-files/data.yml'
})
context.load_from_data_file()
expected = {
'foo': 'bar',
'baz': 'cux',
}
self.assertEqual(context._variables, expected)
def test_render_template(self):
context = Context({
GitHubActionsInput.DATA_FILE.value: 'test/data-files/data.json',
GitHubActionsInput.OUTPUT_FILE.value: self.TEST_FILE,
GitHubActionsInput.TEMPLATE.value: 'test/many-variables/template',
})
context.load_from_data_file()
context.render_template()
expected = "\nbar\ncux\n"
with open('test_output', 'r') as file:
result = file.read()
self.assertEqual(result, expected)
@classmethod
def tearDownClass(cls):
if os.path.exists(cls.TEST_FILE):
os.remove(cls.TEST_FILE)
if __name__ == '__main__':
unittest.main()