Chromium Code Reviews| Index: scripts/slave/unittests/patch_path_filter_test.py |
| diff --git a/scripts/slave/unittests/patch_path_filter_test.py b/scripts/slave/unittests/patch_path_filter_test.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..a4ccb3ed250685820fec25f868e519e3a0efdf4d |
| --- /dev/null |
| +++ b/scripts/slave/unittests/patch_path_filter_test.py |
| @@ -0,0 +1,119 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import unittest |
| + |
| +import test_env # pylint: disable=W0403,W0611 |
| + |
| +import slave.patch_path_filter as patch_path_filter |
| + |
| +GIT_PATCH = """diff --git added_file.py added_file.py |
| +new file mode 100644 |
| +index 0000000..9fa5873 |
| +--- added_file.py |
| ++++ added_file.py |
| +@@ -0,0 +1,1 @@ |
| ++aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay |
| +diff --git some/path/path_file.py some/path/path_file.py |
| +new file mode 100644 |
| +index 0000000..9fa5873 |
| +--- some/path/path_file.py |
| ++++ some/path/path_file.py |
| +@@ -0,0 +1,1 @@ |
| ++bbbbbbbbbbbbbbbbbbbbbbbbbbbbbz |
| +diff --git modified_file.cc modified_file.cc |
| +index 5d48990..7d2479d 100644 |
| +--- modified_file.cc |
| ++++ modified_file.cc |
| +@@ -28,9 +28,11 @@ |
| + #include "c.h" |
| + |
| ++int counter; |
| + |
| +int last_line; |
| +diff --git removed_file.h removed_file.h |
| +deleted file mode 100644 |
| +index c99ded4..0000000 |
| +--- removed_file.h |
| ++++ /dev/null |
| +- line 1 |
| +- line 2 |
| +- line 3 |
| +""" |
| + |
| +SVN_PATCH = """Index: added_file.py |
| +=================================================================== |
| +--- added_file.py (revision 42354) |
| ++++ added_file.py (working copy) |
| +@@ -0,0 +1,1 @@ |
| ++aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay |
| +Index: some/path/path_file.py |
| +=================================================================== |
| +--- some/path/path_file.py (revision 42354) |
| ++++ some/path/path_file.py (working copy) |
| +@@ -0,0 +1,1 @@ |
| ++bbbbbbbbbbbbbbbbbbbbbbbbbbbbbz |
| +Index: modified_file.cc |
| +=================================================================== |
| +--- modified_file.cc (revision 42354) |
| ++++ modified_file.cc (working copy) |
| +@@ -28,9 +28,11 @@ |
| + #include "c.h" |
| + |
| ++int counter; |
| + |
| +int last_line; |
| +Index: removed_file.h |
| +=================================================================== |
| +--- removed_file.h (revision 42354) |
| ++++ removed_file.h (working copy) |
| +- line 1 |
| +- line 2 |
| +- line 3 |
| +""" |
| + |
| +class PatchPathFilterTest(unittest.TestCase): |
| + |
| + def testFilterEmpty(self): |
| + for prefix in patch_path_filter.ITEM_PREFIX_TYPES: |
| + entries = patch_path_filter.parse_entries(prefix, '') |
| + self.assertEqual(0, len(entries)) |
| + |
| + def testGitPatch(self): |
| + entries = patch_path_filter.parse_entries(patch_path_filter.GIT_REGEX, |
| + GIT_PATCH) |
| + self._verifyEntries(entries) |
| + |
| + def testGitPatchWithDataHeader(self): |
| + patch = "Chars before the patch.\n%s" % GIT_PATCH |
| + entries = patch_path_filter.parse_entries(patch_path_filter.GIT_REGEX, |
| + patch) |
| + self._verifyEntries(entries) |
| + |
| + def testSvnPatch(self): |
| + entries = patch_path_filter.parse_entries(patch_path_filter.SVN_REGEX, |
| + SVN_PATCH) |
| + self._verifyEntries(entries) |
| + |
| + def testSvnPatchWithDataHeader(self): |
| + patch = "Chars before the patch.\n%s" % SVN_PATCH |
| + entries = patch_path_filter.parse_entries(patch_path_filter.SVN_REGEX, |
| + patch) |
| + self._verifyEntries(entries) |
| + |
| + def _verifyEntries(self, entries): |
| + self.assertEqual(4, len(entries)) |
| + self.assertEqual('added_file.py', entries[0].file_path) |
| + self.assertEqual('aaaaay\n', entries[0].contents[-7:]) |
| + self.assertEqual('some/path/path_file.py', entries[1].file_path) |
| + self.assertEqual('bbbbbz\n', entries[1].contents[-7:]) |
| + self.assertEqual('modified_file.cc', entries[2].file_path) |
| + self.assertEqual('_line;\n', entries[2].contents[-7:]) |
| + self.assertEqual('removed_file.h', entries[3].file_path) |
| + self.assertEqual('line 3\n', entries[3].contents[-7:]) |
| + |
| + |
| +if __name__ == '__main__': |
| + unittest.main() |
|
iannucci
2013/10/29 17:15:02
I would definitely consider formulating the test a
kjellander_chromium
2013/11/26 22:11:25
That's a good idea, but as maruel@ said, it's bett
|