-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_generate_patch.py
53 lines (39 loc) · 1.54 KB
/
test_generate_patch.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
#!/bin/python3
# SPDX-License-Identifier: LGPL-2.1-or-later
import diff_match_patch
import unittest
from unittest.mock import MagicMock, patch, mock_open
import generate_patch
""" Developer tests for the generate_patch module. """
class TestGeneratePatch(unittest.TestCase):
def setUp(self):
super().setUp()
def tearDown(self):
super().tearDown()
@patch("sys.argv", ["exe", "old", "new", "patch"])
def test_command_line_options_count_is_correct(self):
generate_patch.parse_args()
@patch("sys.argv", ["exe"])
def test_command_line_args_missing_is_error(self):
with self.assertRaises(SystemExit):
generate_patch.parse_args()
def test_patch_generated(self):
# Arrange
old = "Line1\nLine2\nLine4\n"
new = "Line1\nLine2\nLine3\n"
dmp = diff_match_patch.diff_match_patch()
difference = dmp.patch_toText(dmp.patch_make(old, new))
# Act
result = generate_patch.generate_patch(old, new)
# Assert
self.assertEqual(result, difference)
def test_run_loads_all_files(self):
with patch("builtins.open", mock_open()) as open_mock:
generate_patch.run("old", "new", "patch")
expected_calls = [
unittest.mock.call("old", "r", encoding="utf-8"),
unittest.mock.call("new", "r", encoding="utf-8"),
unittest.mock.call("patch", "w", encoding="utf-8"),
]
for call in expected_calls:
self.assertIn(call, open_mock.mock_calls)