diff options
Diffstat (limited to 'fastimport/tests/test_filter_processor.py')
-rw-r--r-- | fastimport/tests/test_filter_processor.py | 179 |
1 files changed, 98 insertions, 81 deletions
diff --git a/fastimport/tests/test_filter_processor.py b/fastimport/tests/test_filter_processor.py index 809bdc8..7659db1 100644 --- a/fastimport/tests/test_filter_processor.py +++ b/fastimport/tests/test_filter_processor.py @@ -28,8 +28,8 @@ from fastimport.processors import ( # A sample input stream containing all (top level) import commands -_SAMPLE_ALL = \ -b"""blob +_SAMPLE_ALL = b"""\ +blob mark :1 data 4 foo @@ -56,8 +56,8 @@ release v0.1 # NEWS # doc/README.txt # doc/index.txt -_SAMPLE_WITH_DIR = \ -b"""blob +_SAMPLE_WITH_DIR = b"""\ +blob mark :1 data 9 Welcome! @@ -101,6 +101,7 @@ M 644 :3 doc/README.txt M 644 :4 doc/index.txt """ + class TestCaseWithFiltering(TestCase): def assertFiltering(self, input_stream, params, expected): @@ -114,6 +115,7 @@ class TestCaseWithFiltering(TestCase): out = outf.getvalue() self.assertEqual(expected, out) + class TestNoFiltering(TestCaseWithFiltering): def test_params_not_given(self): @@ -131,8 +133,8 @@ class TestIncludePaths(TestCaseWithFiltering): # * only referenced blobs are retained # * from clause is dropped from the first command params = {b'include_paths': [b'NEWS']} - self.assertFiltering(_SAMPLE_WITH_DIR, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\ +blob mark :2 data 17 Life @@ -152,8 +154,8 @@ M 644 :2 NEWS # * new root: path is now index.txt, not doc/index.txt # * other files changed in matching commits are excluded params = {b'include_paths': [b'doc/index.txt']} - self.assertFiltering(_SAMPLE_WITH_DIR, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\ +blob mark :4 data 11 == Docs == @@ -170,8 +172,8 @@ M 644 :4 index.txt # Additional things to note: # * from updated to reference parents in the output params = {b'include_paths': [b'doc/README.txt']} - self.assertFiltering(_SAMPLE_WITH_DIR, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\ +blob mark :1 data 9 Welcome! @@ -198,8 +200,8 @@ M 644 :3 README.txt def test_subdir(self): params = {b'include_paths': [b'doc/']} - self.assertFiltering(_SAMPLE_WITH_DIR, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\ +blob mark :1 data 9 Welcome! @@ -232,8 +234,8 @@ M 644 :4 index.txt def test_multiple_files_in_subdir(self): # The new root should be the subdrectory params = {b'include_paths': [b'doc/README.txt', b'doc/index.txt']} - self.assertFiltering(_SAMPLE_WITH_DIR, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\ +blob mark :1 data 9 Welcome! @@ -268,8 +270,8 @@ class TestExcludePaths(TestCaseWithFiltering): def test_file_in_root(self): params = {b'exclude_paths': [b'NEWS']} - self.assertFiltering(_SAMPLE_WITH_DIR, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\ +blob mark :1 data 9 Welcome! @@ -301,8 +303,8 @@ M 644 :4 doc/index.txt def test_file_in_subdir(self): params = {b'exclude_paths': [b'doc/README.txt']} - self.assertFiltering(_SAMPLE_WITH_DIR, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\ +blob mark :2 data 17 Life @@ -331,8 +333,8 @@ M 644 :4 doc/index.txt def test_subdir(self): params = {b'exclude_paths': [b'doc/']} - self.assertFiltering(_SAMPLE_WITH_DIR, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\ +blob mark :2 data 17 Life @@ -349,8 +351,8 @@ M 644 :2 NEWS def test_multple_files(self): params = {b'exclude_paths': [b'doc/index.txt', b'NEWS']} - self.assertFiltering(_SAMPLE_WITH_DIR, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\ +blob mark :1 data 9 Welcome! @@ -379,9 +381,11 @@ M 644 :3 doc/README.txt class TestIncludeAndExcludePaths(TestCaseWithFiltering): def test_included_dir_and_excluded_file(self): - params = {b'include_paths': [b'doc/'], b'exclude_paths': [b'doc/index.txt']} - self.assertFiltering(_SAMPLE_WITH_DIR, params, \ -b"""blob + params = { + b'include_paths': [b'doc/'], + b'exclude_paths': [b'doc/index.txt']} + self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\ +blob mark :1 data 9 Welcome! @@ -414,8 +418,8 @@ M 644 :3 README.txt # doc/index.txt # # It then renames doc/README.txt => doc/README -_SAMPLE_WITH_RENAME_INSIDE = _SAMPLE_WITH_DIR + \ -b"""commit refs/heads/master +_SAMPLE_WITH_RENAME_INSIDE = _SAMPLE_WITH_DIR + b"""\ +commit refs/heads/master mark :103 committer d <b@c> 1234798653 +0000 data 10 @@ -431,8 +435,8 @@ R doc/README.txt doc/README # doc/index.txt # # It then renames doc/README.txt => README -_SAMPLE_WITH_RENAME_TO_OUTSIDE = _SAMPLE_WITH_DIR + \ -b"""commit refs/heads/master +_SAMPLE_WITH_RENAME_TO_OUTSIDE = _SAMPLE_WITH_DIR + b"""\ +commit refs/heads/master mark :103 committer d <b@c> 1234798653 +0000 data 10 @@ -448,8 +452,8 @@ R doc/README.txt README # doc/index.txt # # It then renames NEWS => doc/NEWS -_SAMPLE_WITH_RENAME_TO_INSIDE = _SAMPLE_WITH_DIR + \ -b"""commit refs/heads/master +_SAMPLE_WITH_RENAME_TO_INSIDE = _SAMPLE_WITH_DIR + b"""\ +commit refs/heads/master mark :103 committer d <b@c> 1234798653 +0000 data 10 @@ -458,13 +462,14 @@ from :102 R NEWS doc/NEWS """ + class TestIncludePathsWithRenames(TestCaseWithFiltering): def test_rename_all_inside(self): # These rename commands ought to be kept but adjusted for the new root params = {b'include_paths': [b'doc/']} - self.assertFiltering(_SAMPLE_WITH_RENAME_INSIDE, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_RENAME_INSIDE, params, b"""\ +blob mark :1 data 9 Welcome! @@ -504,8 +509,8 @@ R README.txt README def test_rename_to_outside(self): # These rename commands become deletes params = {b'include_paths': [b'doc/']} - self.assertFiltering(_SAMPLE_WITH_RENAME_TO_OUTSIDE, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_RENAME_TO_OUTSIDE, params, b"""\ +blob mark :1 data 9 Welcome! @@ -545,8 +550,8 @@ D README.txt def test_rename_to_inside(self): # This ought to create a new file but doesn't yet params = {b'include_paths': [b'doc/']} - self.assertFiltering(_SAMPLE_WITH_RENAME_TO_INSIDE, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_RENAME_TO_INSIDE, params, b"""\ +blob mark :1 data 9 Welcome! @@ -584,8 +589,8 @@ M 644 :4 index.txt # doc/index.txt # # It then copies doc/README.txt => doc/README -_SAMPLE_WITH_COPY_INSIDE = _SAMPLE_WITH_DIR + \ -b"""commit refs/heads/master +_SAMPLE_WITH_COPY_INSIDE = _SAMPLE_WITH_DIR + b"""\ +commit refs/heads/master mark :103 committer d <b@c> 1234798653 +0000 data 10 @@ -601,8 +606,8 @@ C doc/README.txt doc/README # doc/index.txt # # It then copies doc/README.txt => README -_SAMPLE_WITH_COPY_TO_OUTSIDE = _SAMPLE_WITH_DIR + \ -b"""commit refs/heads/master +_SAMPLE_WITH_COPY_TO_OUTSIDE = _SAMPLE_WITH_DIR + b"""\ +commit refs/heads/master mark :103 committer d <b@c> 1234798653 +0000 data 10 @@ -618,8 +623,8 @@ C doc/README.txt README # doc/index.txt # # It then copies NEWS => doc/NEWS -_SAMPLE_WITH_COPY_TO_INSIDE = _SAMPLE_WITH_DIR + \ -b"""commit refs/heads/master +_SAMPLE_WITH_COPY_TO_INSIDE = _SAMPLE_WITH_DIR + b"""\ +commit refs/heads/master mark :103 committer d <b@c> 1234798653 +0000 data 10 @@ -634,8 +639,8 @@ class TestIncludePathsWithCopies(TestCaseWithFiltering): def test_copy_all_inside(self): # These copy commands ought to be kept but adjusted for the new root params = {b'include_paths': [b'doc/']} - self.assertFiltering(_SAMPLE_WITH_COPY_INSIDE, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_COPY_INSIDE, params, b"""\ +blob mark :1 data 9 Welcome! @@ -675,8 +680,8 @@ C README.txt README def test_copy_to_outside(self): # This can be ignored params = {b'include_paths': [b'doc/']} - self.assertFiltering(_SAMPLE_WITH_COPY_TO_OUTSIDE, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_COPY_TO_OUTSIDE, params, b"""\ +blob mark :1 data 9 Welcome! @@ -709,8 +714,8 @@ M 644 :4 index.txt def test_copy_to_inside(self): # This ought to create a new file but doesn't yet params = {b'include_paths': [b'doc/']} - self.assertFiltering(_SAMPLE_WITH_COPY_TO_INSIDE, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_COPY_TO_INSIDE, params, b"""\ +blob mark :1 data 9 Welcome! @@ -746,8 +751,8 @@ M 644 :4 index.txt # NEWS # doc/README.txt # doc/index.txt -_SAMPLE_WITH_DELETEALL = \ -b"""blob +_SAMPLE_WITH_DELETEALL = b"""\ +blob mark :1 data 9 Welcome! @@ -784,8 +789,8 @@ class TestIncludePathsWithDeleteAll(TestCaseWithFiltering): def test_deleteall(self): params = {b'include_paths': [b'doc/index.txt']} - self.assertFiltering(_SAMPLE_WITH_DELETEALL, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_DELETEALL, params, b"""\ +blob mark :4 data 11 == Docs == @@ -801,8 +806,8 @@ M 644 :4 index.txt """) -_SAMPLE_WITH_TAGS = _SAMPLE_WITH_DIR + \ -b"""tag v0.1 +_SAMPLE_WITH_TAGS = _SAMPLE_WITH_DIR + b"""\ +tag v0.1 from :100 tagger d <b@c> 1234798653 +0000 data 12 @@ -814,6 +819,7 @@ data 12 release v0.2 """ + class TestIncludePathsWithTags(TestCaseWithFiltering): def test_tag_retention(self): @@ -821,8 +827,8 @@ class TestIncludePathsWithTags(TestCaseWithFiltering): # keep the tag but adjust 'from' accordingly. # Otherwise, delete the tag command. params = {b'include_paths': [b'NEWS']} - self.assertFiltering(_SAMPLE_WITH_TAGS, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_TAGS, params, b"""\ +blob mark :2 data 17 Life @@ -843,12 +849,13 @@ release v0.2 """) -_SAMPLE_WITH_RESETS = _SAMPLE_WITH_DIR + \ -b"""reset refs/heads/foo +_SAMPLE_WITH_RESETS = _SAMPLE_WITH_DIR + b"""\ +reset refs/heads/foo reset refs/heads/bar from :102 """ + class TestIncludePathsWithResets(TestCaseWithFiltering): def test_reset_retention(self): @@ -856,8 +863,8 @@ class TestIncludePathsWithResets(TestCaseWithFiltering): # If a reset references a commit with a parent we kept, # keep the reset but adjust 'from' accordingly. params = {b'include_paths': [b'NEWS']} - self.assertFiltering(_SAMPLE_WITH_RESETS, params, \ -b"""blob + self.assertFiltering(_SAMPLE_WITH_RESETS, params, b"""\ +blob mark :2 data 17 Life @@ -877,8 +884,8 @@ from :101 # A sample input stream containing empty commit -_SAMPLE_EMPTY_COMMIT = \ -b"""blob +_SAMPLE_EMPTY_COMMIT = b"""\ +blob mark :1 data 4 foo @@ -896,8 +903,8 @@ empty commit """ # A sample input stream containing unresolved from and merge references -_SAMPLE_FROM_MERGE_COMMIT = \ -b"""blob +_SAMPLE_FROM_MERGE_COMMIT = b"""\ +blob mark :1 data 4 foo @@ -933,12 +940,13 @@ merge :1001 M 644 :99 data/DATA2 """ + class TestSquashEmptyCommitsFlag(TestCaseWithFiltering): def test_squash_empty_commit(self): params = {b'include_paths': None, b'exclude_paths': None} - self.assertFiltering(_SAMPLE_EMPTY_COMMIT, params, \ -b"""blob + self.assertFiltering(_SAMPLE_EMPTY_COMMIT, params, b"""\ +blob mark :1 data 4 foo @@ -951,13 +959,18 @@ M 644 :1 COPYING """) def test_keep_empty_commit(self): - params = {b'include_paths': None, b'exclude_paths': None, b'squash_empty_commits': False} - self.assertFiltering(_SAMPLE_EMPTY_COMMIT, params, _SAMPLE_EMPTY_COMMIT) + params = { + b'include_paths': None, + b'exclude_paths': None, + b'squash_empty_commits': False, + } + self.assertFiltering( + _SAMPLE_EMPTY_COMMIT, params, _SAMPLE_EMPTY_COMMIT) def test_squash_unresolved_references(self): params = {b'include_paths': None, b'exclude_paths': None} - self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \ -b"""blob + self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, b"""\ +blob mark :1 data 4 foo @@ -994,15 +1007,20 @@ M 644 :99 data/DATA2 """) def test_keep_unresolved_from_and_merge(self): - params = {b'include_paths': None, b'exclude_paths': None, b'squash_empty_commits': False} - self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, _SAMPLE_FROM_MERGE_COMMIT) + params = { + b'include_paths': None, + b'exclude_paths': None, + b'squash_empty_commits': False, + } + self.assertFiltering( + _SAMPLE_FROM_MERGE_COMMIT, params, _SAMPLE_FROM_MERGE_COMMIT) def test_with_excludes(self): params = {b'include_paths': None, b'exclude_paths': [b'data/DATA'], b'squash_empty_commits': False} - self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \ -b"""blob + self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, b"""\ +blob mark :1 data 4 foo @@ -1037,8 +1055,8 @@ M 644 :99 data/DATA2 params = {b'include_paths': [b'COPYING', b'data/DATA2'], b'exclude_paths': None, b'squash_empty_commits': False} - self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \ -b"""blob + self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, b"""\ +blob mark :1 data 4 foo @@ -1067,15 +1085,14 @@ from :3 merge :4 merge :1001 M 644 :99 data/DATA2 -""" -) +""") def test_with_directory_includes(self): params = {b'include_paths': [b'data/'], b'exclude_paths': None, b'squash_empty_commits': False} - self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \ -b"""commit refs/heads/master + self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, b"""\ +commit refs/heads/master mark :3 committer Joe <joe@example.com> 1234567890 +1000 data 6 |