Merge ~paride/jenkins-launchpad-plugin:py3 into jenkins-launchpad-plugin:master
- Git
- lp:~paride/jenkins-launchpad-plugin
- py3
- Merge into master
Status: | Merged |
---|---|
Approved by: | Joshua Powers |
Approved revision: | 13a579d13a9737bf7fbc713e081e8779b6b8cd77 |
Merged at revision: | eaed6b64dac253eb20c5754af5092eddc7c298fb |
Proposed branch: | ~paride/jenkins-launchpad-plugin:py3 |
Merge into: | jenkins-launchpad-plugin:master |
Diff against target: |
1189 lines (+155/-161) 29 files modified
.gitignore (+10/-7) dev/null (+0/-1) jlp/__init__.py (+1/-1) jlp/branch.py (+2/-2) jlp/commands/autoland.py (+2/-2) jlp/commands/voteOnMergeProposal.py (+1/-2) jlp/dputrunner.py (+1/-1) jlp/jenkinsutils.py (+6/-8) jlp/jsonjenkins.py (+6/-6) jlp/launchpadagent.py (+2/-2) jlp/launchpadutils.py (+3/-3) scripts/autoland (+1/-1) scripts/dput (+1/-1) scripts/getMergeProposals (+1/-1) scripts/launchpadTrigger (+1/-1) scripts/voteOnMergeProposal (+1/-1) setup.py (+2/-1) tests/__init__.py (+1/-1) tests/test_autoland.py (+21/-16) tests/test_bzrrecipe.py (+17/-17) tests/test_dput.py (+1/-1) tests/test_dputrunner.py (+5/-15) tests/test_getMergeProposals.py (+7/-7) tests/test_jenkinsutils.py (+13/-16) tests/test_jlp.py (+15/-15) tests/test_launchpadTrigger.py (+5/-4) tests/test_launchpadutils.py (+10/-11) tests/test_voteOnMergeProposal.py (+18/-16) tests/util.py (+1/-1) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Joshua Powers (community) | Approve | ||
Review via email: mp+376145@code.launchpad.net |
Commit message
Convert package to Python 3
Description of the change
Paride Legovini (paride) wrote : | # |
Joshua Powers (powersj) wrote : | # |
Can you show an example of this working using some test LP project please? Otherwise 2 in-line questions?
Paride Legovini (paride) wrote : | # |
Thanks for reviewing. I'll setup a test project. On the inline questions: both the lines are left overs from me debugging the test, they are to be removed.
Paride Legovini (paride) wrote : | # |
Lines removed; all tests still passing.
Paride Legovini (paride) wrote : | # |
Tested against the lp:paride-test-project project. This is the MP I used for testing:
https:/
voteOnMergeProposal marked it as Needs Fixing when the result was not PASSED, otherwise it approved it. The autoland script did nothing until I manually set the MP status to Approved. Once I did so it correctly merged the MP. The merged branch is visible in the commit history here:
https:/
The allowed_users list in jlp.config works as expected.
I faked the test a little but as I didn't setup a full CI set of jobs to test JLP, instead I pointed it to the curtin-ci Jenkins jobs. I'll do another few tests before merging, but so far it seems to be working fine.
Paride Legovini (paride) wrote : | # |
The root of the problem seems to be:
[ 267.086787] cloud-init[1461]: Processing triggers for linux-image-
[ 267.410038] cloud-init[1461]: /etc/kernel/
[ 267.411989] cloud-init[1461]: flash-kernel: deferring update (trigger activated)
[ 267.423883] cloud-init[1461]: Processing triggers for flash-kernel (3.0~rc.
[ 267.563889] cloud-init[1461]: Can't find /boot/vmlinuz-
[ 267.579645] cloud-init[1461]: dpkg: error processing package flash-kernel (--configure):
[ 267.591371] cloud-init[1461]: subprocess installed post-installation script returned error exit status 1
[ 267.596234] cloud-init[1461]: Errors were encountered while processing:
[ 267.599077] cloud-init[1461]: flash-kernel
Likely to be caused by this commit:
https:/
Possible workaround: restrict the "run update-initramfs once" logic to arm64 until we find what goes wrong on arm64 and s390x.
Paride Legovini (paride) wrote : | # |
Wrong brower tab :)
Joshua Powers (powersj) : | # |
Preview Diff
1 | diff --git a/.gitignore b/.gitignore |
2 | index bf01a23..9379187 100644 |
3 | --- a/.gitignore |
4 | +++ b/.gitignore |
5 | @@ -1,8 +1,11 @@ |
6 | docs/_build/* |
7 | -./bin |
8 | -./share |
9 | -./local |
10 | -./lib |
11 | -./include |
12 | -./jenkins_launchpad_plugin.egg-info |
13 | -./man |
14 | +/bin |
15 | +/share |
16 | +/local |
17 | +/lib |
18 | +/include |
19 | +/jenkins_launchpad_plugin.egg-info |
20 | +/man |
21 | +__pycache__ |
22 | +*.pyc |
23 | +build |
24 | diff --git a/HACKING b/HACKING |
25 | deleted file mode 100644 |
26 | index b0555b8..0000000 |
27 | --- a/HACKING |
28 | +++ /dev/null |
29 | @@ -1,23 +0,0 @@ |
30 | -If you are not running Ubuntu raring or later you will need run the |
31 | -following in order to install pyruntest: |
32 | - * sudo add-apt-repository ppa:autopilot/ppa |
33 | - |
34 | - |
35 | -You need the following if you want to make changes/run this project: |
36 | - * sudo apt-get install -y python-launchpadlib python-bzrlib python-mock python-testtools python-jenkins python-lockfile python-testscenarios python-pyruntest python-yaml python-git python-jinja2 |
37 | - * install tarmac: |
38 | - bzr branch lp:tarmac |
39 | - cd tarmac |
40 | - sudo python setup.py install |
41 | - |
42 | -To run the tests: |
43 | - * pyruntest tests |
44 | - |
45 | -Virtualenv instructions: |
46 | -$ sudo apt-get install python-virtualenv |
47 | -$ virtualenv . --system-site-packages |
48 | -$ bin/python setup.py develop |
49 | -$ bzr branch lp:tarmac ../tarmac |
50 | -$ jlp=$(pwd) |
51 | -$ cd ../tarmac |
52 | -$ $jlp/bin/python setup.py install |
53 | diff --git a/autoland.py b/autoland.py |
54 | deleted file mode 120000 |
55 | index f8abc68..0000000 |
56 | --- a/autoland.py |
57 | +++ /dev/null |
58 | @@ -1 +0,0 @@ |
59 | -scripts/autoland |
60 | \ No newline at end of file |
61 | diff --git a/dput b/dput |
62 | deleted file mode 120000 |
63 | index f63205d..0000000 |
64 | --- a/dput |
65 | +++ /dev/null |
66 | @@ -1 +0,0 @@ |
67 | -scripts/dput |
68 | \ No newline at end of file |
69 | diff --git a/getMergeProposals.py b/getMergeProposals.py |
70 | deleted file mode 120000 |
71 | index 80e275c..0000000 |
72 | --- a/getMergeProposals.py |
73 | +++ /dev/null |
74 | @@ -1 +0,0 @@ |
75 | -scripts/getMergeProposals |
76 | \ No newline at end of file |
77 | diff --git a/jlp/__init__.py b/jlp/__init__.py |
78 | index 00d6adc..9802aea 100644 |
79 | --- a/jlp/__init__.py |
80 | +++ b/jlp/__init__.py |
81 | @@ -8,7 +8,7 @@ jlp |
82 | """ |
83 | |
84 | __name__ = 'jlp' |
85 | -__version__ = '0.1' |
86 | +__version__ = '3.1' |
87 | __author__ = 'Martin Mrazik' |
88 | |
89 | import jinja2 |
90 | diff --git a/jlp/branch.py b/jlp/branch.py |
91 | index 5334d6f..9462f88 100644 |
92 | --- a/jlp/branch.py |
93 | +++ b/jlp/branch.py |
94 | @@ -1,7 +1,7 @@ |
95 | import logging |
96 | -from bzrlib.plugin import load_plugins |
97 | +from breezy.plugin import load_plugins |
98 | load_plugins() |
99 | -from bzrlib import branch as bzr_branch |
100 | +from breezy import branch as bzr_branch |
101 | from tarmac.branch import Branch as TarmacBranch |
102 | from tarmac.branch import BranchConfig |
103 | from jlp import get_config_option |
104 | diff --git a/jlp/commands/__init__.py b/jlp/commands/__init__.py |
105 | deleted file mode 100644 |
106 | index e69de29..0000000 |
107 | --- a/jlp/commands/__init__.py |
108 | +++ /dev/null |
109 | diff --git a/jlp/commands/autoland.py b/jlp/commands/autoland.py |
110 | index ba95372..a4552f0 100644 |
111 | --- a/jlp/commands/autoland.py |
112 | +++ b/jlp/commands/autoland.py |
113 | @@ -7,10 +7,10 @@ from jlp.launchpadutils import (LaunchpadVote, get_vote_subject, |
114 | get_target_branch, get_source_branch, |
115 | is_git_project) |
116 | from jlp import (launchpadutils, Branch, |
117 | - DputRunner, jenkinsutils, get_launchpad, |
118 | + DputRunner, get_launchpad, |
119 | get_config_option, logger, get_jinja_environment) |
120 | from tarmac.exceptions import TarmacMergeError, BranchHasConflicts |
121 | -from bzrlib.errors import LockFailed |
122 | +from breezy.errors import LockFailed |
123 | import os |
124 | from shutil import rmtree |
125 | import tempfile |
126 | diff --git a/jlp/commands/voteOnMergeProposal.py b/jlp/commands/voteOnMergeProposal.py |
127 | index dab10ef..bf9f008 100644 |
128 | --- a/jlp/commands/voteOnMergeProposal.py |
129 | +++ b/jlp/commands/voteOnMergeProposal.py |
130 | @@ -1,7 +1,6 @@ |
131 | from argparse import ArgumentParser |
132 | import atexit |
133 | -import jinja2 |
134 | -from jlp import launchpadutils, get_launchpad, logger, get_config_option, get_jinja_environment |
135 | +from jlp import launchpadutils, get_launchpad, logger, get_jinja_environment |
136 | import re |
137 | import os |
138 | from shutil import rmtree |
139 | diff --git a/jlp/dputrunner.py b/jlp/dputrunner.py |
140 | index cfce696..d096d77 100644 |
141 | --- a/jlp/dputrunner.py |
142 | +++ b/jlp/dputrunner.py |
143 | @@ -37,7 +37,7 @@ class DputRunner: |
144 | return self.versionFormat.format(**kwargs) |
145 | except KeyError as error: |
146 | logger.error('Unkown variable used in format string: ' + |
147 | - error.message) |
148 | + str(error)) |
149 | return None |
150 | |
151 | def _run_hooks(self, hooks, cwd): |
152 | diff --git a/jlp/jenkinsutils.py b/jlp/jenkinsutils.py |
153 | index 2083d45..8b94b1b 100644 |
154 | --- a/jlp/jenkinsutils.py |
155 | +++ b/jlp/jenkinsutils.py |
156 | @@ -2,18 +2,16 @@ import re |
157 | import os |
158 | from xml.dom.minidom import parseString |
159 | import jenkins |
160 | -import urlparse |
161 | -import urllib2 |
162 | -import launchpadutils |
163 | -from textwrap import dedent |
164 | +import urllib |
165 | +from . import launchpadutils |
166 | from . import get_json_jenkins |
167 | from lazr.restfulclient.errors import Unauthorized |
168 | from jlp import logger, get_config_option, get_jinja_environment |
169 | |
170 | |
171 | def normalize_url(url): |
172 | - return urlparse.urljoin(url, |
173 | - urlparse.urlparse(url).path.replace('//', '/')) |
174 | + return urllib.parse.urljoin(url, |
175 | + urllib.parse.urlparse(url).path.replace('//', '/')) |
176 | |
177 | |
178 | def _actions_has_param(actions, param, value): |
179 | @@ -427,7 +425,7 @@ def is_pipeline_job(jenkins, job_url): |
180 | try: |
181 | data = jenkins.get_json_data(job_url + 'wfapi', |
182 | append_api=False) |
183 | - except urllib2.HTTPError: |
184 | + except urllib.error.HTTPError: |
185 | data = None |
186 | |
187 | if data: |
188 | @@ -755,7 +753,7 @@ def start_jenkins_job(lp_handle, launchpaduser, jenkins_url, jenkins_job, mp, |
189 | try: |
190 | is_merge_only = launchpadutils.is_merge_only(mp) |
191 | except LookupError as error: |
192 | - logger.error(error.message) |
193 | + logger.error(str(error)) |
194 | logger.debug('Skipping this merge proposal') |
195 | return False |
196 | |
197 | diff --git a/jlp/jsonjenkins.py b/jlp/jsonjenkins.py |
198 | index 98ab1e4..353043f 100644 |
199 | --- a/jlp/jsonjenkins.py |
200 | +++ b/jlp/jsonjenkins.py |
201 | @@ -1,5 +1,5 @@ |
202 | import json |
203 | -import urllib2 |
204 | +import urllib |
205 | |
206 | |
207 | class JSONJenkins(): |
208 | @@ -9,11 +9,11 @@ class JSONJenkins(): |
209 | self.jenkins_url = jenkins_url |
210 | self.jenkins_proxy_url = jenkins_proxy_url |
211 | |
212 | - passman = urllib2.HTTPPasswordMgrWithDefaultRealm() |
213 | + passman = urllib.request.HTTPPasswordMgrWithDefaultRealm() |
214 | passman.add_password(None, jenkins_url, username, password) |
215 | - authhandler = urllib2.HTTPBasicAuthHandler(passman) |
216 | - self.urllib_opener = urllib2.build_opener(authhandler) |
217 | - urllib2.install_opener(self.urllib_opener) |
218 | + authhandler = urllib.request.HTTPBasicAuthHandler(passman) |
219 | + self.urllib_opener = urllib.request.build_opener(authhandler) |
220 | + urllib.request.install_opener(self.urllib_opener) |
221 | |
222 | def patch_url(self, url): |
223 | # Test for presence of a url that needs to be patched. |
224 | @@ -30,5 +30,5 @@ class JSONJenkins(): |
225 | url = self.patch_url(url) |
226 | if append_api: |
227 | url = url + '/api/json' |
228 | - data = urllib2.urlopen(url) |
229 | + data = urllib.request.urlopen(url) |
230 | return json.load(data) |
231 | diff --git a/jlp/launchpadagent.py b/jlp/launchpadagent.py |
232 | index 65e0621..fd29d81 100644 |
233 | --- a/jlp/launchpadagent.py |
234 | +++ b/jlp/launchpadagent.py |
235 | @@ -31,7 +31,7 @@ class AuthorizeRequestTokenWithConsole(RequestTokenAuthorizationEngine): |
236 | |
237 | """ |
238 | authorization_url = self.authorization_url(request_token) |
239 | - print WAITING_FOR_USER.format(authorization_url) |
240 | + print(WAITING_FOR_USER.format(authorization_url)) |
241 | # if we don't flush we may not see the message |
242 | sys.stdout.flush() |
243 | while credentials.access_token is None: |
244 | @@ -40,7 +40,7 @@ class AuthorizeRequestTokenWithConsole(RequestTokenAuthorizationEngine): |
245 | credentials.exchange_request_token_for_access_token( |
246 | self.web_root) |
247 | break |
248 | - except HTTPError, e: |
249 | + except HTTPError as e: |
250 | if e.response.status == 403: |
251 | # The user decided not to authorize this |
252 | # application. |
253 | diff --git a/jlp/launchpadutils.py b/jlp/launchpadutils.py |
254 | index 7197180..4c50bba 100644 |
255 | --- a/jlp/launchpadutils.py |
256 | +++ b/jlp/launchpadutils.py |
257 | @@ -1,6 +1,6 @@ |
258 | -import os, re |
259 | +import re |
260 | from jlp import logger, get_config_option |
261 | -import jenkinsutils |
262 | +from jlp import jenkinsutils |
263 | from . import get_json_jenkins |
264 | |
265 | RE_LP_BUG_IDS = r'LP:(,? #\d+)+\s*$' |
266 | @@ -283,7 +283,7 @@ def users_allowed_to_trigger_jobs(lp_users): |
267 | try: |
268 | allowed_person = lp.people[allowed] |
269 | except KeyError: |
270 | - logger.warn('User {} from the allowed_users list is not in ' |
271 | + logger.warning('User {} from the allowed_users list is not in ' |
272 | 'launchpad!'.format(allowed)) |
273 | continue |
274 | if not allowed_person.is_team: |
275 | diff --git a/launchpadTrigger.py b/launchpadTrigger.py |
276 | deleted file mode 120000 |
277 | index 128f211..0000000 |
278 | --- a/launchpadTrigger.py |
279 | +++ /dev/null |
280 | @@ -1 +0,0 @@ |
281 | -scripts/launchpadTrigger |
282 | \ No newline at end of file |
283 | diff --git a/scripts/autoland b/scripts/autoland |
284 | index 7ffac75..6279088 100755 |
285 | --- a/scripts/autoland |
286 | +++ b/scripts/autoland |
287 | @@ -1,4 +1,4 @@ |
288 | -#!/usr/bin/env python |
289 | +#!/usr/bin/env python3 |
290 | import sys |
291 | # this is to keep backwards compatibility with deployments directly from |
292 | # bzr branch |
293 | diff --git a/scripts/dput b/scripts/dput |
294 | index 5d4e952..7bef560 100755 |
295 | --- a/scripts/dput |
296 | +++ b/scripts/dput |
297 | @@ -1,4 +1,4 @@ |
298 | -#!/usr/bin/env python |
299 | +#!/usr/bin/env python3 |
300 | import sys |
301 | # this is to keep backwards compatibility with deployments directly from |
302 | # bzr branch |
303 | diff --git a/scripts/getMergeProposals b/scripts/getMergeProposals |
304 | index f21ffaf..c2b072b 100755 |
305 | --- a/scripts/getMergeProposals |
306 | +++ b/scripts/getMergeProposals |
307 | @@ -1,4 +1,4 @@ |
308 | -#!/usr/bin/env python |
309 | +#!/usr/bin/env python3 |
310 | import sys |
311 | # this is to keep backwards compatibility with deployments directly from |
312 | # bzr branch |
313 | diff --git a/scripts/launchpadTrigger b/scripts/launchpadTrigger |
314 | index e62d7fc..28aa2e3 100755 |
315 | --- a/scripts/launchpadTrigger |
316 | +++ b/scripts/launchpadTrigger |
317 | @@ -1,4 +1,4 @@ |
318 | -#!/usr/bin/env python |
319 | +#!/usr/bin/env python3 |
320 | import sys |
321 | # this is to keep backwards compatibility with deployments directly from |
322 | # bzr branch |
323 | diff --git a/scripts/voteOnMergeProposal b/scripts/voteOnMergeProposal |
324 | index c9274a6..61f099c 100755 |
325 | --- a/scripts/voteOnMergeProposal |
326 | +++ b/scripts/voteOnMergeProposal |
327 | @@ -1,4 +1,4 @@ |
328 | -#!/usr/bin/env python |
329 | +#!/usr/bin/env python3 |
330 | import sys |
331 | # this is to keep backwards compatibility with deployments directly from |
332 | # bzr branch |
333 | diff --git a/setup.py b/setup.py |
334 | index db40a0b..346810d 100644 |
335 | --- a/setup.py |
336 | +++ b/setup.py |
337 | @@ -1,9 +1,10 @@ |
338 | from distutils.core import setup |
339 | from setuptools import find_packages |
340 | +from jlp import __version__ |
341 | import glob |
342 | setup( |
343 | name='jenkins-launchpad-plugin', |
344 | - version='0.1', |
345 | + version=__version__, |
346 | url='https://launchpad.net/jenkins-launchpad-plugin', |
347 | packages=find_packages(), |
348 | include_package_data=True, |
349 | diff --git a/tests/__init__.py b/tests/__init__.py |
350 | index 2cce6c0..2843c1f 100644 |
351 | --- a/tests/__init__.py |
352 | +++ b/tests/__init__.py |
353 | @@ -160,7 +160,7 @@ class JenkinsJSONData(): |
354 | |
355 | def get_json_data(self, url, append_api=True): |
356 | url = url.rstrip('/') |
357 | - print url |
358 | + print(url) |
359 | if url == 'http://10.0.0.1:8080/job/my-job': |
360 | return self.job_data |
361 | elif url == 'http://10.0.0.1:8080/job/my-job/3': |
362 | diff --git a/tests/test_autoland.py b/tests/test_autoland.py |
363 | index e6d1aef..e82de4f 100644 |
364 | --- a/tests/test_autoland.py |
365 | +++ b/tests/test_autoland.py |
366 | @@ -1,10 +1,10 @@ |
367 | import unittest |
368 | -from mock import patch |
369 | -from mock import MagicMock |
370 | +from unittest.mock import patch |
371 | +from unittest.mock import MagicMock |
372 | import tests.util as util |
373 | from jlp import get_config_option |
374 | from tarmac.exceptions import TarmacMergeError, BranchHasConflicts |
375 | -from bzrlib.errors import LockFailed |
376 | +from breezy.errors import LockFailed |
377 | from jlp.launchpadutils import LaunchpadVote |
378 | import jlp.commands.autoland as autoland |
379 | |
380 | @@ -18,7 +18,7 @@ class TestGetFixesCommitMessage(unittest.TestCase): |
381 | b.web_link = 'http://' + str(i) |
382 | mp.source_branch.linked_bugs_collection.append(b) |
383 | ret = autoland.get_fixes_commit_message(mp) |
384 | - expected = ' Fixes: http://0, http://1, http://2, http://3.' |
385 | + expected = ' Fixes: http://0, http://1, http://2, http://3' |
386 | self.assertEqual(ret, expected) |
387 | |
388 | def test_no_bugs(self): |
389 | @@ -198,7 +198,7 @@ class TestAutolandVoting(TestAutolandForMergeAndCommit): |
390 | def test_last_vote_was_needs_fixing(self): |
391 | sys_argv = ['autoland.py', '-r', 'PASSED', |
392 | '-v', '123', '-m', 'url'] |
393 | - merge_and_commit = lambda x, y: 0 |
394 | + merge_and_commit = lambda x, y, z: 0 |
395 | get_last_mp_vote = lambda x: LaunchpadVote.NEEDS_FIXING |
396 | with patch('sys.argv', sys_argv), \ |
397 | patch( |
398 | @@ -215,7 +215,7 @@ class TestAutolandVoting(TestAutolandForMergeAndCommit): |
399 | def test_last_vote_was_approved(self): |
400 | sys_argv = ['autoland.py', '-r', 'PASSED', |
401 | '-v', '123', '-m', 'url'] |
402 | - merge_and_commit = lambda y, z: 0 |
403 | + merge_and_commit = lambda x, y, z: 0 |
404 | get_last_mp_vote = lambda x: LaunchpadVote.APPROVE |
405 | with patch('sys.argv', sys_argv), \ |
406 | patch('jlp.commands.autoland.get_last_mp_vote', |
407 | @@ -223,7 +223,7 @@ class TestAutolandVoting(TestAutolandForMergeAndCommit): |
408 | patch('jlp.commands.autoland.merge_and_commit', |
409 | merge_and_commit): |
410 | autoland.autoland() |
411 | - self.assertEquals(self.mp.createComment.call_count, 0) |
412 | + self.assertEqual(self.mp.createComment.call_count, 0) |
413 | |
414 | |
415 | class TestAutolandMergeAndCommitWithDescription(TestAutolandForMergeAndCommit): |
416 | @@ -250,12 +250,13 @@ class TestAutolandWithMultipleDputs(TestAutolandForMergeAndCommit): |
417 | '-d', 'quantal,precise'] |
418 | dputRunner = MagicMock() |
419 | with patch('sys.argv', sys_argv), \ |
420 | - patch('jlp.commands.autoland.DputRunner', new=dputRunner): |
421 | + patch('jlp.commands.autoland.DputRunner', new=dputRunner), \ |
422 | + patch('jlp.commands.autoland.get_config_option'): |
423 | self.assertTrue(autoland.autoland() == 0) |
424 | ppas_expected = ['ppa:myppa', 'ppa:myppa2'] |
425 | distributions_expected = ['quantal', 'precise'] |
426 | - self.assertEquals(ppas_expected, dputRunner.call_args[1]['ppas']) |
427 | - self.assertEquals(distributions_expected, |
428 | + self.assertEqual(ppas_expected, dputRunner.call_args[1]['ppas']) |
429 | + self.assertEqual(distributions_expected, |
430 | dputRunner.call_args[1]['distributions']) |
431 | |
432 | |
433 | @@ -266,7 +267,8 @@ class TestAutolandWithReleaseOnly(TestAutolandForMergeAndCommit): |
434 | '-d', 'quantal', '--release-only'] |
435 | dputRunner = MagicMock() |
436 | with patch('sys.argv', sys_argv), \ |
437 | - patch('jlp.commands.autoland.DputRunner', new=dputRunner): |
438 | + patch('jlp.commands.autoland.DputRunner', new=dputRunner), \ |
439 | + patch('jlp.commands.autoland.get_config_option'): |
440 | autoland.autoland() |
441 | self.assertTrue(dputRunner.call_args[1]['release_only']) |
442 | |
443 | @@ -278,10 +280,11 @@ class TestAutolandWithVersionFormatString(TestAutolandForMergeAndCommit): |
444 | '-d', 'quantal', '-f', '{PACKAGE_VERSION}0'] |
445 | dputRunner = MagicMock() |
446 | with patch('sys.argv', sys_argv), \ |
447 | - patch('jlp.commands.autoland.DputRunner', new=dputRunner): |
448 | + patch('jlp.commands.autoland.DputRunner', new=dputRunner), \ |
449 | + patch('jlp.commands.autoland.get_config_option'): |
450 | self.assertTrue(autoland.autoland() == 0) |
451 | version_format_expected = '{PACKAGE_VERSION}0' |
452 | - self.assertEquals(version_format_expected, |
453 | + self.assertEqual(version_format_expected, |
454 | dputRunner.call_args[1]['versionFormat']) |
455 | |
456 | def test_quoted_string(self): |
457 | @@ -290,10 +293,11 @@ class TestAutolandWithVersionFormatString(TestAutolandForMergeAndCommit): |
458 | '-d', 'quantal', '-f', '"{PACKAGE_VERSION}"'] |
459 | dputRunner = MagicMock() |
460 | with patch('sys.argv', sys_argv), \ |
461 | - patch('jlp.commands.autoland.DputRunner', new=dputRunner): |
462 | + patch('jlp.commands.autoland.DputRunner', new=dputRunner), \ |
463 | + patch('jlp.commands.autoland.get_config_option'): |
464 | self.assertTrue(autoland.autoland() == 0) |
465 | version_format_expected = '{PACKAGE_VERSION}' |
466 | - self.assertEquals(version_format_expected, |
467 | + self.assertEqual(version_format_expected, |
468 | dputRunner.call_args[1]['versionFormat']) |
469 | |
470 | |
471 | @@ -317,7 +321,8 @@ class TestAutolandMergeCommitAndDput(TestAutolandForMergeAndCommit): |
472 | '-a', 'packaging_branch', '-b', |
473 | 'http://10.0.0.1:8080/job/unity-daily/17/', '-d', |
474 | 'precise'] |
475 | - with patch('sys.argv', sys_argv): |
476 | + with patch('sys.argv', sys_argv), \ |
477 | + patch('jlp.commands.autoland.get_config_option'): |
478 | self.assertTrue(autoland.autoland() == 0) |
479 | self.assertTrue(self.target.merge.call_count == 1) |
480 | self.assertTrue(self.target.commit.call_count == 1) |
481 | diff --git a/tests/test_bzrrecipe.py b/tests/test_bzrrecipe.py |
482 | index be211ea..b31c564 100644 |
483 | --- a/tests/test_bzrrecipe.py |
484 | +++ b/tests/test_bzrrecipe.py |
485 | @@ -1,6 +1,6 @@ |
486 | import unittest |
487 | -from mock import patch |
488 | -from mock import MagicMock |
489 | +from unittest.mock import patch |
490 | +from unittest.mock import MagicMock |
491 | from jlp import BzrRecipe |
492 | from textwrap import dedent |
493 | |
494 | @@ -15,8 +15,8 @@ class TestBzrRecipeInstantiation(unittest.TestCase): |
495 | nest-part ubuntu lp:dummy/packaging debian |
496 | ''') |
497 | recipe.generateRecipe() |
498 | - self.assertEquals(recipe.recipe, expected) |
499 | - self.assertEquals(recipe.getTrunkRevno(), 14) |
500 | + self.assertEqual(recipe.recipe, expected) |
501 | + self.assertEqual(recipe.getTrunkRevno(), 14) |
502 | |
503 | def test_check_recipe_without_explicit_revision(self): |
504 | bzr = MagicMock() |
505 | @@ -29,8 +29,8 @@ class TestBzrRecipeInstantiation(unittest.TestCase): |
506 | nest-part ubuntu lp:dummy/packaging debian |
507 | ''') |
508 | recipe.generateRecipe() |
509 | - self.assertEquals(recipe.recipe, expected) |
510 | - self.assertEquals(recipe.getTrunkRevno(), 10) |
511 | + self.assertEqual(recipe.recipe, expected) |
512 | + self.assertEqual(recipe.getTrunkRevno(), 10) |
513 | |
514 | def test_check_recipe_without_packaging_branch(self): |
515 | bzr = MagicMock() |
516 | @@ -43,8 +43,8 @@ class TestBzrRecipeInstantiation(unittest.TestCase): |
517 | # No packaging branch |
518 | ''') |
519 | recipe.generateRecipe() |
520 | - self.assertEquals(recipe.recipe, expected) |
521 | - self.assertEquals(recipe.getTrunkRevno(), 10) |
522 | + self.assertEqual(recipe.recipe, expected) |
523 | + self.assertEqual(recipe.getTrunkRevno(), 10) |
524 | |
525 | def test_check_recipe_with_inline_packaging(self): |
526 | bzr = MagicMock() |
527 | @@ -57,15 +57,15 @@ class TestBzrRecipeInstantiation(unittest.TestCase): |
528 | # No packaging branch |
529 | ''') |
530 | recipe.generateRecipe() |
531 | - self.assertEquals(recipe.recipe, expected) |
532 | - self.assertEquals(recipe.getTrunkRevno(), 10) |
533 | + self.assertEqual(recipe.recipe, expected) |
534 | + self.assertEqual(recipe.getTrunkRevno(), 10) |
535 | |
536 | def test_get_packaging_branch_revno(self): |
537 | bzr = MagicMock() |
538 | bzr.revno = lambda self: 10 |
539 | with patch('jlp.bzrrecipe.Bazaar', new=MagicMock(return_value=bzr)): |
540 | recipe = BzrRecipe('lp:dummy', 'lp:dummy/packaging', 14) |
541 | - self.assertEquals(recipe.getPackagingBranchRevno(), 10) |
542 | + self.assertEqual(recipe.getPackagingBranchRevno(), 10) |
543 | |
544 | def test_getDir_before_tree_building(self): |
545 | with patch('jlp.bzrrecipe.Bazaar'): |
546 | @@ -219,10 +219,10 @@ class TestBzrRecipe(unittest.TestCase): |
547 | class TestBzrRecipeBuildTree(TestBzrRecipe): |
548 | def test_buildTree(self): |
549 | self.recipe.buildTree() |
550 | - self.assertEquals( |
551 | + self.assertEqual( |
552 | self.open_file.__enter__.return_value.write.call_count, 1) |
553 | - self.assertEquals(self.recipe.getBuildDir(), self.temp_dir) |
554 | - self.assertEquals(self.recipe.getTrunkDir(), |
555 | + self.assertEqual(self.recipe.getBuildDir(), self.temp_dir) |
556 | + self.assertEqual(self.recipe.getTrunkDir(), |
557 | self.temp_dir + '/trunk') |
558 | |
559 | |
560 | @@ -230,10 +230,10 @@ class TestBzrRecipeBuildTreeTwice(TestBzrRecipe): |
561 | def test_buildTree_twice(self): |
562 | self.recipe.buildTree() |
563 | self.recipe.buildTree() |
564 | - self.assertEquals( |
565 | + self.assertEqual( |
566 | self.open_file.__enter__.return_value.write.call_count, 1) |
567 | - self.assertEquals(self.recipe.getBuildDir(), self.temp_dir) |
568 | - self.assertEquals(self.recipe.getTrunkDir(), |
569 | + self.assertEqual(self.recipe.getBuildDir(), self.temp_dir) |
570 | + self.assertEqual(self.recipe.getTrunkDir(), |
571 | self.temp_dir + '/trunk') |
572 | |
573 | |
574 | diff --git a/tests/test_dput.py b/tests/test_dput.py |
575 | index b9267d9..3977d70 100644 |
576 | --- a/tests/test_dput.py |
577 | +++ b/tests/test_dput.py |
578 | @@ -1,6 +1,6 @@ |
579 | import jlp.commands.dput as dput |
580 | import unittest |
581 | -from mock import patch, MagicMock |
582 | +from unittest.mock import patch, MagicMock |
583 | |
584 | |
585 | class TestDput(unittest.TestCase): |
586 | diff --git a/tests/test_dputrunner.py b/tests/test_dputrunner.py |
587 | index 80c35bd..8c51f38 100644 |
588 | --- a/tests/test_dputrunner.py |
589 | +++ b/tests/test_dputrunner.py |
590 | @@ -1,8 +1,8 @@ |
591 | import unittest |
592 | -from mock import patch, MagicMock |
593 | -import mock |
594 | +from unittest.mock import patch, MagicMock |
595 | +from unittest import mock |
596 | try: |
597 | - from mock import call |
598 | + from unittest.mock import call |
599 | except ImportError: |
600 | pass |
601 | from jlp import DputRunner |
602 | @@ -69,8 +69,6 @@ class TestDputRunner(TestDputBase): |
603 | release_only=release_only)) |
604 | return calls |
605 | |
606 | - @unittest.skipIf(StrictVersion(mock.__version__) < StrictVersion('0.8'), |
607 | - "assert_has_calls not suppored by mock < 0.8") |
608 | def test_dput(self): |
609 | recipe = MagicMock() |
610 | recipe.getTrunkRevno = lambda: 10 |
611 | @@ -81,8 +79,6 @@ class TestDputRunner(TestDputBase): |
612 | calls = self._build_calls(recipe, False) |
613 | self.dput_runner.doDput.assert_has_calls(calls) |
614 | |
615 | - @unittest.skipIf(StrictVersion(mock.__version__) < StrictVersion('0.8'), |
616 | - "assert_has_calls not suppored by mock < 0.8") |
617 | def test_dput_release_only(self): |
618 | recipe = MagicMock() |
619 | recipe.getTrunkRevno = lambda: 10 |
620 | @@ -154,8 +150,6 @@ class TestDput(TestDputBase): |
621 | cwd='/build')) |
622 | return calls |
623 | |
624 | - @unittest.skipIf(StrictVersion(mock.__version__) < StrictVersion('0.8'), |
625 | - "assert_has_calls not suppored by mock < 0.8") |
626 | def test_doDput(self): |
627 | recipe = self._build_recipe() |
628 | check_call = MagicMock() |
629 | @@ -173,8 +167,6 @@ class TestDput(TestDputBase): |
630 | release_only=False) |
631 | check_call.assert_has_calls(calls) |
632 | |
633 | - @unittest.skipIf(StrictVersion(mock.__version__) < StrictVersion('0.8'), |
634 | - "assert_has_calls not suppored by mock < 0.8") |
635 | def test_doDput_with_epoch(self): |
636 | recipe = self._build_recipe() |
637 | check_call = MagicMock() |
638 | @@ -193,8 +185,6 @@ class TestDput(TestDputBase): |
639 | release_only=False) |
640 | check_call.assert_has_calls(calls) |
641 | |
642 | - @unittest.skipIf(StrictVersion(mock.__version__) < StrictVersion('0.8'), |
643 | - "assert_has_calls not suppored by mock < 0.8") |
644 | def test_doReleaseOnlyDput(self): |
645 | recipe = self._build_recipe() |
646 | check_call = MagicMock() |
647 | @@ -287,7 +277,7 @@ class DPutVersionTests(TestWithScenarios, TestDput): |
648 | |
649 | ('unknown tag', |
650 | { |
651 | - 'formatString': '{PACKAGE_VERSION}-{UNKOWN_TAG}', |
652 | + 'formatString': '{PACKAGE_VERSION}-{UNKNOWN_TAG}', |
653 | 'variables': { |
654 | 'PACKAGE_VERSION': 13, |
655 | 'BZR_REVISION': 43, |
656 | @@ -303,4 +293,4 @@ class DPutVersionTests(TestWithScenarios, TestDput): |
657 | self.make_dput_runner(versionFormat=self.formatString) |
658 | |
659 | result_format = self.dput_runner.formatVersionString(**self.variables) |
660 | - self.assertEquals(self.expectedResult, result_format) |
661 | + self.assertEqual(self.expectedResult, result_format) |
662 | diff --git a/tests/test_getMergeProposals.py b/tests/test_getMergeProposals.py |
663 | index 4c1cc4f..399350b 100644 |
664 | --- a/tests/test_getMergeProposals.py |
665 | +++ b/tests/test_getMergeProposals.py |
666 | @@ -1,5 +1,5 @@ |
667 | import unittest |
668 | -from mock import patch, MagicMock |
669 | +from unittest.mock import patch, MagicMock |
670 | import tests.util as util |
671 | from jlp.commands.getMergeProposals import getMergeProposals |
672 | |
673 | @@ -32,12 +32,12 @@ class TestGetMergeProposal(unittest.TestCase): |
674 | """No branch specified; exit with error message.""" |
675 | |
676 | sys_argv = ['getMergeProposals.py'] |
677 | - error_message = 'error: too few arguments' |
678 | + error_message = 'error: the following arguments are required: branch' |
679 | with patch('sys.argv', sys_argv), util.captured_stderr() as stderr: |
680 | with self.assertRaises(SystemExit) as e: |
681 | getMergeProposals() |
682 | self.assertIn(error_message, stderr.getvalue()) |
683 | - self.assertEquals(2, e.exception.code) |
684 | + self.assertEqual(2, e.exception.code) |
685 | |
686 | def test_no_mp_found_one_branch(self): |
687 | """One branch specified with no MPs found.""" |
688 | @@ -49,7 +49,7 @@ class TestGetMergeProposal(unittest.TestCase): |
689 | as get_merge_proposals: |
690 | get_merge_proposals.return_value = [] |
691 | count = getMergeProposals() |
692 | - self.assertEquals(0, count) |
693 | + self.assertEqual(0, count) |
694 | |
695 | def test_no_mp_found_multiple_branches(self): |
696 | """Muiltipe branches specified with no MPs found.""" |
697 | @@ -63,7 +63,7 @@ class TestGetMergeProposal(unittest.TestCase): |
698 | as get_merge_proposals: |
699 | get_merge_proposals.return_value = [] |
700 | count = getMergeProposals() |
701 | - self.assertEquals(0, count) |
702 | + self.assertEqual(0, count) |
703 | |
704 | def test_mp_found_one_branch(self): |
705 | """One branch specified with one MP found.""" |
706 | @@ -75,7 +75,7 @@ class TestGetMergeProposal(unittest.TestCase): |
707 | as get_merge_proposals: |
708 | get_merge_proposals.return_value = ['Launchpad_mp'] |
709 | count = getMergeProposals() |
710 | - self.assertEquals(1, count) |
711 | + self.assertEqual(1, count) |
712 | |
713 | def test_mp_found_multiple_branches(self): |
714 | """One branch specified with multiple MPs found.""" |
715 | @@ -89,4 +89,4 @@ class TestGetMergeProposal(unittest.TestCase): |
716 | 'Launchpad_mp2', |
717 | 'Launchpad_mp3'] |
718 | count = getMergeProposals() |
719 | - self.assertEquals(3, count) |
720 | + self.assertEqual(3, count) |
721 | diff --git a/tests/test_jenkinsutils.py b/tests/test_jenkinsutils.py |
722 | index d0a6d9b..8c7bd85 100644 |
723 | --- a/tests/test_jenkinsutils.py |
724 | +++ b/tests/test_jenkinsutils.py |
725 | @@ -1,4 +1,4 @@ |
726 | -from mock import MagicMock, patch |
727 | +from unittest.mock import MagicMock, patch |
728 | from jlp import jenkinsutils, launchpadutils, _config |
729 | import unittest |
730 | from tests import JenkinsJSONData |
731 | @@ -222,7 +222,7 @@ class TestIsJobOrDownstreamBuildingScenarios(TestWithScenarios): |
732 | jenkins.get_json_data = lambda x, append_api=True: self.jenkins_data |
733 | with patch('jlp.jenkinsutils.get_json_jenkins', |
734 | new=MagicMock(return_value=jenkins)): |
735 | - self.assertEquals( |
736 | + self.assertEqual( |
737 | jenkinsutils.is_job_or_downstream_building( |
738 | 'job', self.job_params), |
739 | self.expected) |
740 | @@ -330,7 +330,7 @@ class TestGetRunningBuilds(TestWithScenarios): |
741 | jenkins.get_json_data = lambda x, append_api=True: self.jenkins_data |
742 | with patch('jlp.jenkinsutils.get_json_jenkins', |
743 | new=MagicMock(return_value=jenkins)): |
744 | - self.assertEquals( |
745 | + self.assertEqual( |
746 | jenkinsutils.get_running_builds('job', self.job_params), |
747 | self.expected) |
748 | |
749 | @@ -494,7 +494,7 @@ class TestIsJobQueued(TestWithScenarios): |
750 | upstream_params = self.upstream_params |
751 | else: |
752 | upstream_params = {} |
753 | - self.assertEquals( |
754 | + self.assertEqual( |
755 | jenkinsutils.is_job_queued( |
756 | 'job', queue=self.queue, job_params=self.job_params, |
757 | upstream_job=self.upstream_job, |
758 | @@ -508,7 +508,7 @@ class TestGetBuildActions(unittest.TestCase): |
759 | json_jenkins = MagicMock() |
760 | json_jenkins.get_json_data.return_value = {} |
761 | get_json_jenkins.return_value = json_jenkins |
762 | - self.assertEquals(jenkinsutils._get_build_actions('job', 23), |
763 | + self.assertEqual(jenkinsutils._get_build_actions('job', 23), |
764 | []) |
765 | |
766 | @patch('jlp.jenkinsutils.get_json_jenkins') |
767 | @@ -554,7 +554,7 @@ class JenkinsUtilsGetDownstreamBuilds(unittest.TestCase): |
768 | 'http://ip:8080/job/', |
769 | 'my-job', |
770 | 3, 11) |
771 | - self.assertEquals(ret, []) |
772 | + self.assertEqual(ret, []) |
773 | |
774 | def test_filter_intermediate_job(self): |
775 | blacklist = lambda name: ['job-freestyle'] |
776 | @@ -675,11 +675,11 @@ class JenkinsUtilsGetExecutedBuilds(unittest.TestCase): |
777 | def test_get_executed_builds(self): |
778 | ret = jenkinsutils.get_executed_builds(self.jenkins, self.build_url) |
779 | expected = [ |
780 | - {'output': 'http://10.0.0.1:8080/job/job-multiconfig/.' + |
781 | - '/distribution=raring,flavor=amd64/3/console', |
782 | + {'output': 'http://10.0.0.1:8080/job/job-multiconfig/' + |
783 | + 'distribution=raring,flavor=amd64/3/console', |
784 | 'result': 'FAILURE', }, |
785 | - {'output': 'http://10.0.0.1:8080/job/job-multiconfig/.' + |
786 | - '/distribution=raring,flavor=i386/3/console', |
787 | + {'output': 'http://10.0.0.1:8080/job/job-multiconfig/' + |
788 | + 'distribution=raring,flavor=i386/3/console', |
789 | 'result': 'FAILURE', }, |
790 | {'output': 'http://10.0.0.1:8080/job/job-freestyle/7/console', |
791 | 'result': u'SUCCESS', }, |
792 | @@ -702,10 +702,10 @@ class JenkinsUtilsGetExecutedTestRuns(unittest.TestCase): |
793 | self.jenkins, |
794 | 'http://10.0.0.1:8080/job/job-multiconfig/' + |
795 | './distribution=raring,flavor=amd64/3/') |
796 | - expected = ['http://10.0.0.1:8080/job/job-multiconfig/./' + |
797 | + expected = ['http://10.0.0.1:8080/job/job-multiconfig/' + |
798 | 'distribution=raring,flavor=amd64/3/artifact/' + |
799 | 'results/coverity/CID_10895.html', |
800 | - 'http://10.0.0.1:8080/job/job-multiconfig/./' + |
801 | + 'http://10.0.0.1:8080/job/job-multiconfig/' + |
802 | 'distribution=raring,flavor=amd64/3/artifact/results' + |
803 | '/coverity/CID_10896.html'] |
804 | self.assertEqual(ret, expected) |
805 | @@ -1258,10 +1258,7 @@ class TestTriggerAl(unittest.TestCase): |
806 | [MagicMock(), MagicMock(), MagicMock()], |
807 | 'job', 'url', None) |
808 | self.assertEqual(start_jenkins_job.call_count, 0) |
809 | - # the new vote is the 5th argument in change_mp_status (and we count |
810 | - # from 0) |
811 | - new_vote_position = 4 |
812 | - self.assertEqual(report_to_launchpad.call_args[0][new_vote_position], |
813 | + self.assertEqual(report_to_launchpad.call_args[1]['vote'], |
814 | launchpadutils.LaunchpadVote.NEEDS_FIXING) |
815 | |
816 | @patch('jlp.launchpadutils.is_commit_message_set', |
817 | diff --git a/tests/test_jlp.py b/tests/test_jlp.py |
818 | index f46eb7c..651d1bc 100644 |
819 | --- a/tests/test_jlp.py |
820 | +++ b/tests/test_jlp.py |
821 | @@ -2,7 +2,7 @@ from unittest import TestCase |
822 | import jlp |
823 | from jlp import (get_json_jenkins, load_config, get_config_option, |
824 | set_log_level) |
825 | -from mock import patch, MagicMock |
826 | +from unittest.mock import patch, MagicMock |
827 | import logging |
828 | |
829 | |
830 | @@ -24,7 +24,7 @@ class TestGetJsonJenkins(TestCase): |
831 | """Existing JSONJenkins class must be returned when calling |
832 | get_json_jenkins 2+ time""" |
833 | ret = get_json_jenkins() |
834 | - self.assertEquals(ret, self.json_jenkins) |
835 | + self.assertEqual(ret, self.json_jenkins) |
836 | |
837 | @patch('jlp.load_config') |
838 | def test_get_json_replace_no_url(self, load_config): |
839 | @@ -37,7 +37,7 @@ class TestGetJsonJenkins(TestCase): |
840 | } |
841 | json_jenkins = get_json_jenkins() |
842 | url = json_jenkins.patch_url('https://proxy/job/my-job') |
843 | - self.assertEquals(url, 'https://proxy/job/my-job') |
844 | + self.assertEqual(url, 'https://proxy/job/my-job') |
845 | |
846 | @patch('jlp.load_config') |
847 | def test_get_json_replace_no_proxy_url(self, load_config): |
848 | @@ -50,7 +50,7 @@ class TestGetJsonJenkins(TestCase): |
849 | } |
850 | json_jenkins = get_json_jenkins() |
851 | url = json_jenkins.patch_url('https://proxy/subdir/job/my-job') |
852 | - self.assertEquals(url, 'https://proxy/subdir/job/my-job') |
853 | + self.assertEqual(url, 'https://proxy/subdir/job/my-job') |
854 | |
855 | @patch('jlp.load_config') |
856 | def test_get_json_replace_proxy_url(self, load_config): |
857 | @@ -64,7 +64,7 @@ class TestGetJsonJenkins(TestCase): |
858 | } |
859 | json_jenkins = get_json_jenkins() |
860 | url = json_jenkins.patch_url('https://proxy/subdir/job/my-job') |
861 | - self.assertEquals(url, 'http://backend:8080/subdir/job/my-job') |
862 | + self.assertEqual(url, 'http://backend:8080/subdir/job/my-job') |
863 | |
864 | @patch('jlp._json_jenkins', new=None) |
865 | @patch('jlp.JSONJenkins') |
866 | @@ -72,34 +72,34 @@ class TestGetJsonJenkins(TestCase): |
867 | """Test that json_jenkins is returned when get_json_jenkins is called |
868 | for the first time""" |
869 | ret = get_json_jenkins() |
870 | - self.assertEquals(json_jenkins.call_count, 1) |
871 | + self.assertEqual(json_jenkins.call_count, 1) |
872 | self.assertIsNotNone(ret) |
873 | |
874 | @patch('jlp._config', new=config) |
875 | @patch('jlp.yaml.safe_load') |
876 | def test_load_config_subsequent_time(self, safe_load): |
877 | ret = load_config() |
878 | - self.assertEquals(safe_load.call_count, 0) |
879 | - self.assertEquals(ret, self.config) |
880 | + self.assertEqual(safe_load.call_count, 0) |
881 | + self.assertEqual(ret, self.config) |
882 | |
883 | @patch('jlp._config', new=None) |
884 | - @patch('__builtin__.open') |
885 | + @patch('builtins.open') |
886 | @patch('jlp.yaml.safe_load') |
887 | def test_load_config_from_home_first_time(self, safe_load, open_mock): |
888 | ret = load_config() |
889 | - self.assertEquals(safe_load.call_count, 1) |
890 | + self.assertEqual(safe_load.call_count, 1) |
891 | self.assertIsNotNone(ret) |
892 | |
893 | @patch('jlp._config', new=None) |
894 | - @patch('__builtin__.open', new=custom_open) |
895 | + @patch('builtins.open', new=custom_open) |
896 | @patch('jlp.yaml.safe_load') |
897 | def test_load_config_from_cwd_first_time(self, safe_load): |
898 | ret = load_config() |
899 | self.assertIsNotNone(ret) |
900 | - self.assertEquals(safe_load.call_count, 1) |
901 | + self.assertEqual(safe_load.call_count, 1) |
902 | |
903 | @patch('jlp._config', new=None) |
904 | - @patch('__builtin__.open') |
905 | + @patch('builtins.open') |
906 | def test_no_config_found(self, open_mock): |
907 | """If no config is found jlp should sys.exit with 1""" |
908 | open_mock.side_effect = IOError() |
909 | @@ -107,7 +107,7 @@ class TestGetJsonJenkins(TestCase): |
910 | try: |
911 | load_config() |
912 | except SystemExit as e: |
913 | - self.assertEquals(e.code, 1) |
914 | + self.assertEqual(e.code, 1) |
915 | systemExit = True |
916 | self.assertTrue(systemExit) |
917 | |
918 | @@ -116,7 +116,7 @@ class TestGetJsonJenkins(TestCase): |
919 | """get_config_option must return the right value for a defined |
920 | option""" |
921 | value = get_config_option('my_option') |
922 | - self.assertEquals(value, 'my_value') |
923 | + self.assertEqual(value, 'my_value') |
924 | |
925 | @patch('jlp.load_config', new=lambda: {'my_option': 'my_value'}) |
926 | def test_get_invalid_config_option(self): |
927 | diff --git a/tests/test_launchpadTrigger.py b/tests/test_launchpadTrigger.py |
928 | index 6e01673..78075e1 100644 |
929 | --- a/tests/test_launchpadTrigger.py |
930 | +++ b/tests/test_launchpadTrigger.py |
931 | @@ -1,5 +1,5 @@ |
932 | import unittest |
933 | -from mock import patch, MagicMock |
934 | +from unittest.mock import patch, MagicMock |
935 | import tests.util as util |
936 | from jlp.commands.launchpadTrigger import launchpadTrigger, trigger_jenkins |
937 | from jlp import get_config_option |
938 | @@ -57,7 +57,8 @@ class TestLaunchpadTriggerParams(PatchedLaunchpadTriggerTest): |
939 | "-a", |
940 | "--job=faux-dbus-test-runner", |
941 | "--autoland"] |
942 | - error_message = "error: argument -b/--branch is required" |
943 | + error_message = ("error: the following arguments are required: " |
944 | + "-b/--branch") |
945 | with patch('sys.argv', sys_argv), \ |
946 | util.captured_stderr() as stderr: |
947 | try: |
948 | @@ -74,7 +75,7 @@ class TestLaunchpadTriggerParams(PatchedLaunchpadTriggerTest): |
949 | "-n", |
950 | "--branch=lp:faux-dbus-test-runner", |
951 | "--autoland"] |
952 | - error_message = 'argument -j/--job is required' |
953 | + error_message = 'error: the following arguments are required: -j/--job' |
954 | with patch('sys.argv', sys_argv), \ |
955 | util.captured_stderr() as stderr: |
956 | try: |
957 | @@ -154,7 +155,7 @@ class TestLaunchpadTriggerParams(PatchedLaunchpadTriggerTest): |
958 | patch('jlp.commands.launchpadTrigger.get_merge_proposals') as \ |
959 | get_merge_proposals, \ |
960 | patch('jlp.commands.launchpadTrigger.jenkinsutils.' + |
961 | - 'trigger_ci_build') as trigger_ci_build: |
962 | + 'trigger_ci_build'): |
963 | get_merge_proposals.return_value = [self.merge_proposal] |
964 | launchpadTrigger() |
965 | get_merge_proposals.assert_called_with(self.launchpad, |
966 | diff --git a/tests/test_launchpadutils.py b/tests/test_launchpadutils.py |
967 | index 19febf2..cdb5b10 100644 |
968 | --- a/tests/test_launchpadutils.py |
969 | +++ b/tests/test_launchpadutils.py |
970 | @@ -1,8 +1,7 @@ |
971 | import unittest |
972 | from jlp import launchpadutils, get_config_option |
973 | -from mock import MagicMock, patch |
974 | +from unittest.mock import MagicMock, patch |
975 | from testscenarios import TestWithScenarios |
976 | -from textwrap import dedent |
977 | |
978 | |
979 | class LaunchpadUtilsTests(unittest.TestCase): |
980 | @@ -104,7 +103,7 @@ class LaunchpadUtilsTests(unittest.TestCase): |
981 | vote.comment.vote = 'Approve' |
982 | reviews = launchpadutils.get_reviews(mp) |
983 | for review in reviews: |
984 | - self.assertEquals(review, 'jenkins;Approve') |
985 | + self.assertEqual(review, 'jenkins;Approve') |
986 | |
987 | def test_unapproved_prerequisite_no_prerequisite(self): |
988 | mp = MagicMock() |
989 | @@ -651,13 +650,13 @@ class TestGetGitMergeProposals(unittest.TestCase): |
990 | def test_get_git_merge_proposals_with_wrong_launchpad_version(self): |
991 | launchpad = self._get_launchpad_without_git() |
992 | with self.assertRaises(RuntimeError): |
993 | - ret = launchpadutils.get_merge_proposals(launchpad, '', '', |
994 | + launchpadutils.get_merge_proposals(launchpad, '', '', |
995 | repo_type='git') |
996 | |
997 | def test_invalid_repo_type(self): |
998 | launchpad = self._get_launchpad(None) |
999 | with self.assertRaises(RuntimeError): |
1000 | - ret = launchpadutils.get_merge_proposals(launchpad, '', '', |
1001 | + launchpadutils.get_merge_proposals(launchpad, '', '', |
1002 | repo_type='test') |
1003 | |
1004 | class TestGetMpHandleFromURL(unittest.TestCase): |
1005 | @@ -666,7 +665,7 @@ class TestGetMpHandleFromURL(unittest.TestCase): |
1006 | """If there is no way how to get branch link from the merge proposal |
1007 | url then get_mp_handle_from_url must return None""" |
1008 | ret = launchpadutils.get_mp_handle_from_url(MagicMock(), 'http://') |
1009 | - self.assertEquals(ret, None) |
1010 | + self.assertEqual(ret, None) |
1011 | |
1012 | @patch("jlp.launchpadutils.get_branch_from_mp", new=lambda x: 'http://') |
1013 | def test_unable_to_get_branch_handle(self): |
1014 | @@ -675,7 +674,7 @@ class TestGetMpHandleFromURL(unittest.TestCase): |
1015 | launchpad = MagicMock() |
1016 | launchpad.branches.getByUrl = lambda url: None |
1017 | ret = launchpadutils.get_mp_handle_from_url(launchpad, 'http://') |
1018 | - self.assertEquals(ret, None) |
1019 | + self.assertEqual(ret, None) |
1020 | |
1021 | @patch("jlp.launchpadutils.get_branch_from_mp", new=lambda x: 'http://') |
1022 | def test_get_mp_handle_from_url(self): |
1023 | @@ -691,7 +690,7 @@ class TestGetMpHandleFromURL(unittest.TestCase): |
1024 | branch.landing_targets = [mp] |
1025 | launchpad.branches.getByUrl = lambda url: branch |
1026 | ret = launchpadutils.get_mp_handle_from_url(launchpad, mp_url) |
1027 | - self.assertEquals(ret, mp) |
1028 | + self.assertEqual(ret, mp) |
1029 | |
1030 | def test_call_git_api_for_git_url(self): |
1031 | """If there is a merge proposal for the given merge proposal URL then |
1032 | @@ -706,7 +705,7 @@ class TestGetMpHandleFromURL(unittest.TestCase): |
1033 | git_repo.landing_targets = [mp] |
1034 | launchpad.git_repositories.getByPath = lambda path: git_repo |
1035 | ret = launchpadutils.get_mp_handle_from_url(launchpad, mp_url) |
1036 | - self.assertEquals(ret, mp) |
1037 | + self.assertEqual(ret, mp) |
1038 | |
1039 | class TestGetBranchHandle(unittest.TestCase): |
1040 | def setUp(self): |
1041 | @@ -807,7 +806,7 @@ class TestGetBranchHandle(unittest.TestCase): |
1042 | name = 'lp:dummy' |
1043 | # Create multiple matches to be returned for the url |
1044 | branch = self.create_fake_bazaar_branch() |
1045 | - repo = self.create_fake_git_repo() |
1046 | + self.create_fake_git_repo() |
1047 | result = launchpadutils.get_branch_handle_for(self.launchpad, name, |
1048 | 'bazaar'); |
1049 | self.assertEqual(result, ('bazaar', branch)) |
1050 | @@ -818,7 +817,7 @@ class TestGetBranchHandle(unittest.TestCase): |
1051 | ''' |
1052 | name = 'lp:dummy' |
1053 | # Create multiple matches to be returned for the url |
1054 | - branch = self.create_fake_bazaar_branch() |
1055 | + self.create_fake_bazaar_branch() |
1056 | repo = self.create_fake_git_repo() |
1057 | result = launchpadutils.get_branch_handle_for(self.launchpad, name, |
1058 | 'git'); |
1059 | diff --git a/tests/test_voteOnMergeProposal.py b/tests/test_voteOnMergeProposal.py |
1060 | index 4f9523c..0378006 100644 |
1061 | --- a/tests/test_voteOnMergeProposal.py |
1062 | +++ b/tests/test_voteOnMergeProposal.py |
1063 | @@ -1,5 +1,5 @@ |
1064 | import unittest |
1065 | -from mock import patch, MagicMock |
1066 | +from unittest.mock import patch, MagicMock |
1067 | import tests.util as util |
1068 | from jlp.commands.voteOnMergeProposal import voteOnMergeProposal |
1069 | |
1070 | @@ -41,13 +41,14 @@ class TestVoteOnMergeProposal(unittest.TestCase): |
1071 | '--branch="lp:~mrazik/faux-dbus-test-runner/yar8"', |
1072 | '--merge-proposal="https://code.launchpad.net/~mrazik/' + |
1073 | 'faux-dbus-test-runner/yar8/+merge/106113"'] |
1074 | - error_message = 'error: argument -u/--build-url is required' |
1075 | + error_message = ('error: the following arguments are required: ' |
1076 | + '-u/--build-url') |
1077 | with patch('sys.argv', sys_argv), \ |
1078 | util.captured_stderr() as stderr: |
1079 | with self.assertRaises(SystemExit) as e: |
1080 | voteOnMergeProposal() |
1081 | self.assertTrue(error_message in stderr.getvalue()) |
1082 | - self.assertEquals(2, e.exception.code) |
1083 | + self.assertEqual(2, e.exception.code) |
1084 | |
1085 | def test_no_revision_specified(self): |
1086 | """No revision specified; exit with message.""" |
1087 | @@ -59,13 +60,14 @@ class TestVoteOnMergeProposal(unittest.TestCase): |
1088 | '--branch="lp:~mrazik/faux-dbus-test-runner/yar8"', |
1089 | '--merge-proposal="https://code.launchpad.net/~mrazik/' + |
1090 | 'faux-dbus-test-runner/yar8/+merge/106113"'] |
1091 | - error_message = 'error: argument -r/--revision is required' |
1092 | + error_message = ('error: the following arguments are required: ' |
1093 | + '-r/--revision') |
1094 | with patch('sys.argv', sys_argv), \ |
1095 | util.captured_stderr() as stderr: |
1096 | with self.assertRaises(SystemExit) as e: |
1097 | voteOnMergeProposal() |
1098 | self.assertTrue(error_message in stderr.getvalue()) |
1099 | - self.assertEquals(2, e.exception.code) |
1100 | + self.assertEqual(2, e.exception.code) |
1101 | |
1102 | def test_no_merge_proposal_specified(self): |
1103 | """No merge_proposal specified; exit with message.""" |
1104 | @@ -76,13 +78,14 @@ class TestVoteOnMergeProposal(unittest.TestCase): |
1105 | 'faux-dbus-test-runner-ci/configure"', |
1106 | '--revision=66', |
1107 | '--branch="lp:~mrazik/faux-dbus-test-runner/yar8"'] |
1108 | - error_message = 'error: argument -p/--merge-proposal is required' |
1109 | + error_message = ('error: the following arguments are required: ' |
1110 | + '-p/--merge-proposal') |
1111 | with patch('sys.argv', sys_argv), \ |
1112 | util.captured_stderr() as stderr: |
1113 | with self.assertRaises(SystemExit) as e: |
1114 | voteOnMergeProposal() |
1115 | self.assertTrue(error_message in stderr.getvalue()) |
1116 | - self.assertEquals(2, e.exception.code) |
1117 | + self.assertEqual(2, e.exception.code) |
1118 | |
1119 | def test_unknown_merge_proposal(self): |
1120 | """The given merge proposal wasn't found; error out with message.""" |
1121 | @@ -108,12 +111,11 @@ class TestVoteOnMergeProposal(unittest.TestCase): |
1122 | pass |
1123 | self.assertTrue(error_message in stderr.getvalue()) |
1124 | |
1125 | - @patch('sys.argv') |
1126 | @patch('jlp.commands.voteOnMergeProposal.launchpadutils.get_mp_handle_from_url') |
1127 | @patch('jlp.launchpadutils.report_to_launchpad') |
1128 | @patch('jlp.commands.voteOnMergeProposal.launchpadutils.get_template_args') |
1129 | @patch('jlp.commands.voteOnMergeProposal.get_jinja_environment') |
1130 | - def test_passed_vote(self, gje, gta, rtl, gmphandle, sys_argv): |
1131 | + def test_passed_vote(self, gje, gta, rtl, gmphandle): |
1132 | """Vote on a proposal which passed.""" |
1133 | |
1134 | sys_argv = ['voteOnMergeProposal.py', |
1135 | @@ -130,21 +132,20 @@ class TestVoteOnMergeProposal(unittest.TestCase): |
1136 | 'result': 'PASSED', |
1137 | 'revision': '66' |
1138 | } |
1139 | - ret = voteOnMergeProposal() |
1140 | + with patch('sys.argv', sys_argv): |
1141 | + ret = voteOnMergeProposal() |
1142 | self.assertEqual(ret, 0) |
1143 | rtl.assert_called_once() |
1144 | - gje.get_template.assert_called_with('ci_test.j2') |
1145 | + gje.return_value.get_template.assert_called_with('ci_test.j2') |
1146 | |
1147 | |
1148 | - @patch('sys.argv') |
1149 | @patch('jlp.commands.voteOnMergeProposal.launchpadutils.' +\ |
1150 | 'get_mp_handle_from_url') |
1151 | @patch('jlp.launchpadutils.report_to_launchpad') |
1152 | @patch('jlp.launchpadutils.is_commit_message_set') |
1153 | @patch('jlp.commands.voteOnMergeProposal.launchpadutils.get_template_args') |
1154 | @patch('jlp.commands.voteOnMergeProposal.get_jinja_environment') |
1155 | - def test_no_commit_message_set(self, gje, gta, icms, |
1156 | - rtl, gmphandle, sys_argv): |
1157 | + def test_no_commit_message_set(self, gje, gta, icms, rtl, gmphandle): |
1158 | """Vote on a proposal where tests passed but no commit message |
1159 | was set.""" |
1160 | |
1161 | @@ -167,6 +168,7 @@ class TestVoteOnMergeProposal(unittest.TestCase): |
1162 | } |
1163 | icms.return_value = False |
1164 | |
1165 | - ret = voteOnMergeProposal() |
1166 | + with patch('sys.argv', sys_argv): |
1167 | + ret = voteOnMergeProposal() |
1168 | self.assertEqual(ret, 0) |
1169 | - gje.get_template.assert_called_with('no_commit.j2') |
1170 | + gje.return_value.get_template.assert_called_with('no_commit.j2') |
1171 | diff --git a/tests/util.py b/tests/util.py |
1172 | index 4ba80fb..b9bd5c9 100644 |
1173 | --- a/tests/util.py |
1174 | +++ b/tests/util.py |
1175 | @@ -1,5 +1,5 @@ |
1176 | import sys |
1177 | -from StringIO import StringIO |
1178 | +from io import StringIO |
1179 | import contextlib |
1180 | |
1181 | |
1182 | diff --git a/voteOnMergeProposal.py b/voteOnMergeProposal.py |
1183 | deleted file mode 120000 |
1184 | index ebf0657..0000000 |
1185 | --- a/voteOnMergeProposal.py |
1186 | +++ /dev/null |
1187 | @@ -1 +0,0 @@ |
1188 | -scripts/voteOnMergeProposal |
1189 | \ No newline at end of file |
All the tests are passing. Can be tested with:
$ python3 setup.py build test clean
As for tarmac I have a branch with a overhauled debian/ directory, but let's take care of the Python 3 conversion first.