-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_unit.py
108 lines (88 loc) · 4.3 KB
/
test_unit.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""
Create unit tests for the function fetch_ccc_paragraph()
in skill_fetch_catechism_of_the_catholic_church_paragraph.py
To run the unit tests
python3 test_unit.py
pytest -k test_fetch_ccc_paragraph_invalid_9999
pytest
"""
import unittest
from unittest.mock import patch
from skill_fetch_catechism_of_the_catholic_church_paragraph import fetch_ccc_paragraph
class TestFetchCatechismOfTheCatholicChurchParagraph(unittest.TestCase):
"""
Test the function fetch_ccc_paragraph() in skill_fetch_catechism_of_the_catholic_church_paragraph.py
"""
def test_fetch_ccc_paragraph_first(self):
"""
Test fetch_ccc_paragraph() with a valid paragraph number
"""
paragraphs = [1]
expected = "God, infinitely perfect and blessed in himself,"
results = fetch_ccc_paragraph(paragraphs)
self.assertIn(expected, results[0], msg=f"Paragraph {paragraphs} should contain '{expected}', \nReceived {results}")
def test_fetch_ccc_paragraph_1111(self):
"""
Test fetch_ccc_paragraph() with a valid paragraph number
"""
paragraphs = [1111]
expected = "Christ's work in the liturgy is sacramental:"
results = fetch_ccc_paragraph(paragraphs)
self.assertIn(expected, results[0], msg=f"Paragraph {paragraphs} should contain '{expected}', \nReceived {results}")
def test_fetch_ccc_paragraph_2222(self):
"""
Test fetch_ccc_paragraph() with a valid paragraph number
"""
paragraphs = [2222]
expected = "Parents must regard their children as children of God"
results = fetch_ccc_paragraph(paragraphs)
self.assertIn(expected, results[0], msg=f"Paragraph {paragraphs} should contain '{expected}', \nReceived {results}")
def test_fetch_ccc_paragraph_last(self):
"""
Test fetch_ccc_paragraph() with a valid paragraph number
"""
paragraphs = [2865]
expected = 'By the final "Amen," we express our "fiat" concerning the seven petitions: "So be it".'
results = fetch_ccc_paragraph(paragraphs)
self.assertIn(expected, results[0], msg=f"Paragraph {paragraphs} should contain '{expected}, \nReceived {results}'")
def test_fetch_ccc_paragraph_invalid_2866(self):
"""
Test fetch_ccc_paragraph() with an invalid paragraph number
"""
paragraphs = [2866]
expected = "Paragraph 2866 not found."
results = fetch_ccc_paragraph(paragraphs)
self.assertEqual( results[0], expected, msg=f"Paragraph {paragraphs} should not be found.")
# test with multiple paragraphs
def test_fetch_ccc_paragraph_multiple(self):
"""
Test fetch_ccc_paragraph() with a valid paragraph number
"""
paragraphs = [1, 1111, 2222, 2865]
expecteds = []
expecteds.append("God, infinitely perfect and blessed in himself,")
expecteds.append("Christ's work in the liturgy is sacramental:")
expecteds.append("Parents must regard their children as children of God")
expecteds.append('By the final "Amen," we express our "fiat" concerning the seven petitions: "So be it".')
results = fetch_ccc_paragraph(paragraphs)
print(f"results: {results}\n\n")
# loop over each of the paragraphs and get the paragraph number, and check that the expected text is in the results
# if not found, print the paragraph number and the results expected and received
for paragraph, expected in zip(paragraphs, expecteds):
result = results[paragraphs.index(paragraph)]
self.assertIn(expected, result, msg=f"Paragraph {paragraph} should contain '{expected}', INSTEAD, RECEIVED: '{results}'")
def test_fetch_ccc_paragraph_invalid_9999(self):
"""
Test fetch_ccc_paragraph() with an invalid paragraph number
"""
paragraphs = [9999]
expected = "Paragraph 9999 not found."
results = fetch_ccc_paragraph(paragraphs)
self.assertEqual( results[0], expected, msg=f"Paragraph {paragraphs} should not be found.")
def test_fetch_ccc_paragraph_not_integer(self):
"""
Test fetch_ccc_paragraph() with a non-integer
"""
self.assertRaises(TypeError, fetch_ccc_paragraph, ["abc"])
if __name__ == '__main__':
unittest.main()