| #!/usr/bin/python3 |
| |
| import unittest |
| import changed_lines |
| from io import StringIO |
| |
| |
| class GetChangedLinesTest(unittest.TestCase): |
| |
| def test_normal_output(self): |
| want_lines = { |
| 'file1.txt': [22, 23, 46, 47, 48], |
| 'file2.txt': [6] |
| } |
| |
| lines = changed_lines.from_diff(_TEST_FILE_DATA.strip()) |
| |
| self.assertEqual(lines, want_lines) |
| |
| def test_empty_input(self): |
| self.assertFalse(changed_lines.from_diff('')) |
| |
| def test_added_file(self): |
| want_lines = { |
| 'addedFile': [1,2,3,4] |
| } |
| |
| lines = changed_lines.from_diff(_TEST_FILE_DATA_ADDED.strip()) |
| |
| self.assertEqual(lines, want_lines) |
| |
| def test_removed_file(self): |
| lines = changed_lines.from_diff(_TEST_FILE_DATA_DELETED.strip()) |
| self.assertFalse(lines) |
| |
| |
| _TEST_FILE_DATA = """ |
| diff --git a/file1.txt b/file1.txt |
| index 170f11f..041325e 100755 |
| --- a/file1.txt |
| +++ b/file1.txt |
| @@ -19,10 +19,10 @@ |
| line 19 |
| line 20 |
| line 21 |
| -line 22 |
| +#line 22 |
| -line 23 |
| +#line 23 |
| |
| @@ -45,8 +45,15 @@ |
| |
| -echo |
| +#echo |
| +omg |
| +wow |
| diff --git a/file2.txt b/file2.txt |
| index 6675c3b..e69b66c 100644 |
| --- a/file2.txt |
| +++ b/file2.txt |
| @@ -4,25 +4,28 @@ |
| '''some comment went here''' |
| |
| -from typing import Dict |
| +from typing import Dict, Text, |
| """ |
| |
| _TEST_FILE_DATA_DELETED = """ |
| diff --git a/deletedFile b/deletedFile |
| deleted file mode 100644 |
| index 005304205482..000000000000 |
| --- a/deletedFile |
| +++ /dev/null |
| @@ -1,84 +0,0 @@ |
| -deleted |
| -lines |
| """ |
| |
| _TEST_FILE_DATA_ADDED = """ |
| diff --git a/addedFile b/addedFile |
| new file mode 100644 |
| index 000000000000..d906e785c4bd |
| --- /dev/null |
| +++ b/addedFile |
| @@ -0,0 +1,5 @@ |
| +extra |
| +lines |
| +are |
| +added |
| """ |
| |
| |
| if __name__ == '__main__': |
| unittest.main() |