@@ 141-171 (lines=31) @@ | ||
138 | ) |
|
139 | ||
140 | ||
141 | @pytest.mark.parametrize('error_message', [ |
|
142 | ( |
|
143 | "fatal: repository 'https://github.com/hackebro/cookiedozer' " |
|
144 | "not found" |
|
145 | ).encode('utf-8'), |
|
146 | 'hg: abort: HTTP Error 404: Not Found'.encode('utf-8'), |
|
147 | ]) |
|
148 | def test_clone_handles_repo_typo(mocker, clone_dir, error_message): |
|
149 | """In `clone()`, repository not found errors should raise an |
|
150 | appropriate exception. |
|
151 | """ |
|
152 | # side_effect is set to an iterable here (and below), |
|
153 | # because of a Python 3.4 unittest.mock regression |
|
154 | # http://bugs.python.org/issue23661 |
|
155 | mocker.patch( |
|
156 | 'cookiecutter.vcs.subprocess.check_output', |
|
157 | autospec=True, |
|
158 | side_effect=[subprocess.CalledProcessError( |
|
159 | -1, 'cmd', output=error_message |
|
160 | )] |
|
161 | ) |
|
162 | ||
163 | repository_url = 'https://github.com/hackebro/cookiedozer' |
|
164 | with pytest.raises(exceptions.RepositoryNotFound) as err: |
|
165 | vcs.clone( |
|
166 | repository_url, |
|
167 | clone_to_dir=clone_dir, |
|
168 | no_input=True |
|
169 | ) |
|
170 | ||
171 | assert str(err.value) == ( |
|
172 | 'The repository {} could not be found, have you made a typo?' |
|
173 | ).format(repository_url) |
|
174 | ||
@@ 176-204 (lines=29) @@ | ||
173 | ).format(repository_url) |
|
174 | ||
175 | ||
176 | @pytest.mark.parametrize('error_message', [ |
|
177 | ( |
|
178 | "error: pathspec 'unknown_branch' did not match any file(s) known " |
|
179 | "to git" |
|
180 | ).encode('utf-8'), |
|
181 | "hg: abort: unknown revision 'unknown_branch'!".encode('utf-8'), |
|
182 | ]) |
|
183 | def test_clone_handles_branch_typo(mocker, clone_dir, error_message): |
|
184 | """In `clone()`, branch not found errors should raise an |
|
185 | appropriate exception. |
|
186 | """ |
|
187 | mocker.patch( |
|
188 | 'cookiecutter.vcs.subprocess.check_output', |
|
189 | autospec=True, |
|
190 | side_effect=[subprocess.CalledProcessError( |
|
191 | -1, 'cmd', output=error_message |
|
192 | )] |
|
193 | ) |
|
194 | ||
195 | repository_url = 'https://github.com/pytest-dev/cookiecutter-pytest-plugin' |
|
196 | with pytest.raises(exceptions.RepositoryCloneFailed) as err: |
|
197 | vcs.clone( |
|
198 | repository_url, |
|
199 | clone_to_dir=clone_dir, |
|
200 | checkout='unknown_branch', |
|
201 | no_input=True |
|
202 | ) |
|
203 | ||
204 | assert str(err.value) == ( |
|
205 | 'The unknown_branch branch of repository ' |
|
206 | '{} could not found, have you made a typo?' |
|
207 | ).format(repository_url) |