-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_markdown_writer.py
68 lines (59 loc) · 2.62 KB
/
test_markdown_writer.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
""" Unit tests for the write_to_markdown function in markdown_writer.py """
import unittest
from unittest.mock import call, mock_open, patch
from markdown_writer import write_to_markdown
class TestWriteToMarkdown(unittest.TestCase):
"""Test the write_to_markdown function"""
def test_write_with_all_counts_and_no_users_to_remove(self):
"""Test that the function writes the correct markdown when there are no users to remove"""
mock_file = mock_open()
with patch("builtins.open", mock_file):
write_to_markdown(0, 0, 2, 3, {})
mock_file().write.assert_called_once_with(
"# Cleanowners Report\n\n"
"## Overall Stats\n"
"0 Users to Remove\n"
"0 Pull Requests created\n"
"2 Repositories with no CODEOWNERS file\n"
"3 Repositories with CODEOWNERS file\n"
)
def test_write_with_repos_and_users_with_users_to_remove(self):
"""Test that the function writes the correct markdown when there are users to remove"""
mock_file = mock_open()
repo_users = {"repo1": ["user1", "user2"], "repo2": ["user3"]}
with patch("builtins.open", mock_file):
write_to_markdown(1, 2, 3, 4, repo_users)
calls = [
call(
"# Cleanowners Report\n\n"
"## Overall Stats\n"
"1 Users to Remove\n"
"2 Pull Requests created\n"
"3 Repositories with no CODEOWNERS file\n"
"4 Repositories with CODEOWNERS file\n"
),
call("## Repositories and Users to Remove\n"),
call("repo1\n"),
call("- user1\n"),
call("- user2\n"),
call("\n"),
call("repo2\n"),
call("- user3\n"),
call("\n"),
]
mock_file().write.assert_has_calls(calls, any_order=False)
def test_write_with_empty_inputs(self):
"""Test that the function writes the correct markdown when all inputs are 0"""
mock_file = mock_open()
with patch("builtins.open", mock_file):
write_to_markdown(0, 0, 0, 0, {})
mock_file().write.assert_called_once_with(
"# Cleanowners Report\n\n"
"## Overall Stats\n"
"0 Users to Remove\n"
"0 Pull Requests created\n"
"0 Repositories with no CODEOWNERS file\n"
"0 Repositories with CODEOWNERS file\n"
)
if __name__ == "__main__":
unittest.main()