Update OriginalAdvancesForCharacterTreatedAsSpace to work correctly in the presence...
[WebKit-https.git] / Tools / Scripts / webkitpy / common / checkout / checkout_mock.py
1 # Copyright (C) 2011 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 #    * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 #    * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 #    * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 from webkitpy.common.checkout.commitinfo import CommitInfo
30
31 # FIXME: These imports are wrong, we should use a shared MockCommittersList.
32 from webkitpy.common.config.committers import CommitterList
33 from webkitpy.common.net.bugzilla.bugzilla_mock import _mock_reviewers
34 from webkitpy.common.system.filesystem_mock import MockFileSystem
35
36
37 class MockCommitMessage(object):
38     def message(self):
39         return "This is a fake commit message that is at least 50 characters."
40
41
42 committer_list = CommitterList()
43
44 mock_revisions = {
45     1: CommitInfo(852, "ap@apple.com", {
46         "bug_id": 50000,
47         "author_name": "Adam Barth",
48         "author_email": "abarth@webkit.org",
49         "author": committer_list.contributor_by_email("abarth@webkit.org"),
50         "reviewer_text": "Darin Adler",
51         "reviewer": committer_list.committer_by_name("Darin Adler"),
52         "changed_files": [
53             "path/to/file",
54             "another/file",
55         ],
56         "bug_description": "Example description of bug 50000.",
57     }),
58     963: CommitInfo(963, "ap@apple.com", {
59         "bug_id": 50005,
60         "author_name": "Carol Szabo",
61         "author_email": "carol.szabo@nokia.com",
62         "author": committer_list.contributor_by_email("carol.szabo@nokia.com"),
63         "reviewer_text": "Darin Adler",
64         "reviewer": committer_list.committer_by_name("Darin Adler"),
65         "changed_files": [
66             "path/to/file",
67             "another/file",
68         ],
69         "bug_description": "Example description of bug 50005.",
70     }),
71     987: CommitInfo(987, "ap@apple.com", {
72         "bug_id": 50006,
73         "author_name": "Adam Barth",
74         "author_email": "abarth@webkit.org",
75         "author": committer_list.contributor_by_email("abarth@webkit.org"),
76         "reviewer_text": "Darin Adler",
77         "reviewer": committer_list.committer_by_name("Darin Adler"),
78         "changed_files": [
79             "path/to/file",
80             "another/file",
81         ],
82         "bug_description": "Example description of bug 50005.",
83     }),
84     3001: CommitInfo(3001, "tomz@codeaurora.org", {
85         "bug_id": 50004,
86         "author_name": "Tom Zakrajsek",
87         "author_email": "tomz@codeaurora.org",
88         "author": committer_list.contributor_by_email("tomz@codeaurora.org"),
89         "reviewer_text": "Darin Adler",
90         "reviewer": committer_list.committer_by_name("Darin Adler"),
91         "changed_files": [
92             "path/to/file",
93             "another/file",
94         ],
95         "bug_description": "Example description of bug 50004.",
96     })
97 }
98
99
100 class MockCheckout(object):
101     def __init__(self):
102         # FIXME: It's unclear if a MockCheckout is very useful.  A normal Checkout
103         # with a MockSCM/MockFileSystem/MockExecutive is probably better.
104         self._filesystem = MockFileSystem()
105
106     def commit_info_for_revision(self, svn_revision):
107         # There are legacy tests that all expected these revision numbers to map
108         # to the same commit description (now mock_revisions[1])
109         if svn_revision in [32, 123, 852, 853, 854, 1234, 21654, 21655, 21656]:
110             return mock_revisions[1]
111
112         if svn_revision in mock_revisions:
113             return mock_revisions[svn_revision]
114
115         # any "unrecognized" svn_revision will return None.
116
117     def is_path_to_changelog(self, path):
118         return self._filesystem.basename(path) == "ChangeLog"
119
120     def bug_id_for_revision(self, svn_revision):
121         return 12345
122
123     def recent_commit_infos_for_files(self, paths):
124         return [self.commit_info_for_revision(32)]
125
126     def modified_changelogs(self, git_commit, changed_files=None):
127         # Ideally we'd return something more interesting here.  The problem is
128         # that LandDiff will try to actually read the patch from disk!
129         return []
130
131     def commit_message_for_this_commit(self, git_commit, changed_files=None):
132         return MockCommitMessage()
133
134     def apply_patch(self, patch):
135         pass
136
137     def apply_reverse_diffs(self, revision):
138         pass
139
140     def suggested_reviewers(self, git_commit, changed_files=None):
141         # FIXME: We should use a shared mock commiter list.
142         return [_mock_reviewers[0]]