Merge ~cjwatson/launchpad:remove-lp-services-scripts-tests-run-script into launchpad:master
- Git
- lp:~cjwatson/launchpad
- remove-lp-services-scripts-tests-run-script
- Merge into master
Proposed by
Colin Watson
Status: | Merged |
---|---|
Approved by: | Colin Watson |
Approved revision: | e62acbf9793e739025b909307c0f17f49ca11d90 |
Merge reported by: | Otto Co-Pilot |
Merged at revision: | not available |
Proposed branch: | ~cjwatson/launchpad:remove-lp-services-scripts-tests-run-script |
Merge into: | launchpad:master |
Diff against target: |
1152 lines (+145/-171) 33 files modified
lib/launchpad_loggerhead/testing.py (+9/-4) lib/lp/answers/tests/test_questionjob.py (+1/-5) lib/lp/archivepublisher/tests/test_generate_contents_files.py (+3/-2) lib/lp/bugs/tests/test_apportjob.py (+3/-3) lib/lp/code/scripts/tests/test_merge_proposal_jobs.py (+6/-3) lib/lp/code/scripts/tests/test_reclaim_branch_space.py (+1/-1) lib/lp/code/scripts/tests/test_request_daily_builds.py (+5/-3) lib/lp/code/scripts/tests/test_scan_branches.py (+6/-4) lib/lp/code/scripts/tests/test_sendbranchmail.py (+8/-3) lib/lp/code/scripts/tests/test_upgrade_branches.py (+9/-7) lib/lp/registry/tests/test_membership_notification_job.py (+1/-5) lib/lp/registry/tests/test_person_merge_job.py (+1/-5) lib/lp/registry/tests/test_productjob.py (+1/-4) lib/lp/registry/tests/test_sharingjob.py (+1/-5) lib/lp/scripts/tests/test_garbo.py (+7/-5) lib/lp/services/job/scripts/tests/test_process_job_source.py (+21/-16) lib/lp/services/scripts/tests/__init__.py (+0/-39) lib/lp/services/webhooks/tests/test_job.py (+3/-3) lib/lp/soyuz/tests/test_distroseriesdifferencejob.py (+3/-3) lib/lp/soyuz/tests/test_initializedistroseriesjob.py (+4/-3) lib/lp/soyuz/tests/test_packagecopyjob.py (+1/-3) lib/lp/soyuz/tests/test_packagediffjob.py (+1/-5) lib/lp/soyuz/tests/test_packagetranslationsuploadjob.py (+1/-5) lib/lp/soyuz/tests/test_processacceptedbugsjob.py (+1/-4) lib/lp/testing/script.py (+9/-8) lib/lp/translations/doc/message-sharing-merge-script.rst (+2/-2) lib/lp/translations/doc/translations-export-to-branch.rst (+2/-2) lib/lp/translations/pottery/tests/test_detect_intltool.py (+9/-2) lib/lp/translations/scripts/tests/test_merge_existing_packagings.py (+3/-4) lib/lp/translations/scripts/tests/test_packaging_translations.py (+5/-5) lib/lp/translations/scripts/tests/test_reupload_translations.py (+2/-2) lib/lp/translations/scripts/tests/test_translations_to_branch.py (+10/-4) lib/lp/translations/tests/test_rosetta_branches_script.py (+6/-2) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ines Almeida | Approve | ||
Review via email: mp+445957@code.launchpad.net |
Commit message
Remove lp.services.
Description of the change
It turned out that the only way in which `lp.testing.
(Note that some tests already had their own separate assertion of the exit code, although it isn't always visible in the patch context.)
To post a comment you must log in.
Revision history for this message
Ines Almeida (ines-almeida) : | # |
review:
Approve
Revision history for this message
Colin Watson (cjwatson) : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/lib/launchpad_loggerhead/testing.py b/lib/launchpad_loggerhead/testing.py |
2 | index 0847bf1..7d24ecc 100644 |
3 | --- a/lib/launchpad_loggerhead/testing.py |
4 | +++ b/lib/launchpad_loggerhead/testing.py |
5 | @@ -18,8 +18,8 @@ from lp.services.osutils import ( |
6 | remove_if_exists, |
7 | ) |
8 | from lp.services.pidfile import pidfile_path |
9 | -from lp.services.scripts.tests import run_script |
10 | from lp.testing.layers import BaseLayer, LayerProcessController |
11 | +from lp.testing.script import run_script |
12 | |
13 | |
14 | class LoggerheadFixtureException(Exception): |
15 | @@ -43,14 +43,19 @@ class LoggerheadFixture(Fixture): |
16 | self.logfile = os.path.join(config.codebrowse.log_folder, "debug.log") |
17 | remove_if_exists(self.logfile) |
18 | self.addCleanup(kill_by_pidfile, pidfile) |
19 | - run_script( |
20 | - os.path.join("scripts", "start-loggerhead.py"), |
21 | - ["--daemon"], |
22 | + exit_code, out, err = run_script( |
23 | + os.path.join(config.root, "scripts", "start-loggerhead.py"), |
24 | + args=["--daemon"], |
25 | # The testrunner-appserver config provides the correct |
26 | # openid_provider_root URL. |
27 | extra_env={"LPCONFIG": BaseLayer.appserver_config_name}, |
28 | universal_newlines=False, |
29 | ) |
30 | + if exit_code != 0: |
31 | + raise AssertionError( |
32 | + "Starting loggerhead failed with exit code %d:\n%s\n%s" |
33 | + % (exit_code, out, err) |
34 | + ) |
35 | self._waitForStartup() |
36 | |
37 | def _hasStarted(self): |
38 | diff --git a/lib/lp/answers/tests/test_questionjob.py b/lib/lp/answers/tests/test_questionjob.py |
39 | index 3c3a7f7..5d7451b 100644 |
40 | --- a/lib/lp/answers/tests/test_questionjob.py |
41 | +++ b/lib/lp/answers/tests/test_questionjob.py |
42 | @@ -3,8 +3,6 @@ |
43 | |
44 | """Tests for QuestionJobs classes.""" |
45 | |
46 | -import os |
47 | - |
48 | import transaction |
49 | from testtools.content import text_content |
50 | from zope.component import getUtility |
51 | @@ -355,12 +353,10 @@ class QuestionEmailJobTestCase(TestCaseWithFactory): |
52 | question.target.addAnswerContact(user, user) |
53 | transaction.commit() |
54 | |
55 | - env = os.environ.copy() |
56 | - env["LP_DEBUG_SQL"] = "1" |
57 | exit_code, out, err = run_script( |
58 | "cronscripts/process-job-source.py", |
59 | args=["-vv", IQuestionEmailJobSource.getName()], |
60 | - env=env, |
61 | + extra_env={"LP_DEBUG_SQL": "1"}, |
62 | ) |
63 | self.addDetail("stdout", text_content(out)) |
64 | self.addDetail("stderr", text_content(err)) |
65 | diff --git a/lib/lp/archivepublisher/tests/test_generate_contents_files.py b/lib/lp/archivepublisher/tests/test_generate_contents_files.py |
66 | index 8dfaee5..838f59f 100644 |
67 | --- a/lib/lp/archivepublisher/tests/test_generate_contents_files.py |
68 | +++ b/lib/lp/archivepublisher/tests/test_generate_contents_files.py |
69 | @@ -20,11 +20,11 @@ from lp.registry.interfaces.series import SeriesStatus |
70 | from lp.services.log.logger import DevNullLogger |
71 | from lp.services.osutils import write_file |
72 | from lp.services.scripts.base import LaunchpadScriptFailure |
73 | -from lp.services.scripts.tests import run_script |
74 | from lp.services.utils import file_exists |
75 | from lp.testing import TestCaseWithFactory |
76 | from lp.testing.faketransaction import FakeTransaction |
77 | from lp.testing.layers import LaunchpadZopelessLayer, ZopelessDatabaseLayer |
78 | +from lp.testing.script import run_script |
79 | |
80 | |
81 | def fake_overrides(script, distroseries): |
82 | @@ -337,6 +337,7 @@ class TestGenerateContentsFiles(TestCaseWithFactory): |
83 | # The script will run stand-alone. |
84 | self.layer.force_dirty_database() |
85 | retval, out, err = run_script( |
86 | - "cronscripts/generate-contents-files.py", ["-d", "ubuntu", "-q"] |
87 | + "cronscripts/generate-contents-files.py", |
88 | + args=["-d", "ubuntu", "-q"], |
89 | ) |
90 | self.assertEqual(0, retval) |
91 | diff --git a/lib/lp/bugs/tests/test_apportjob.py b/lib/lp/bugs/tests/test_apportjob.py |
92 | index c22cfed..0ba8c7d 100644 |
93 | --- a/lib/lp/bugs/tests/test_apportjob.py |
94 | +++ b/lib/lp/bugs/tests/test_apportjob.py |
95 | @@ -23,7 +23,6 @@ from lp.services.features.testing import FeatureFixture |
96 | from lp.services.job.interfaces.job import JobStatus |
97 | from lp.services.job.tests import block_on_job |
98 | from lp.services.librarian.interfaces import ILibraryFileAliasSet |
99 | -from lp.services.scripts.tests import run_script |
100 | from lp.services.temporaryblobstorage.interfaces import ( |
101 | ITemporaryStorageManager, |
102 | ) |
103 | @@ -34,6 +33,7 @@ from lp.testing.layers import ( |
104 | LaunchpadFunctionalLayer, |
105 | LaunchpadZopelessLayer, |
106 | ) |
107 | +from lp.testing.script import run_script |
108 | from lp.testing.views import create_initialized_view |
109 | |
110 | |
111 | @@ -304,9 +304,9 @@ class ProcessApportBlobJobTestCase(TestCaseWithFactory): |
112 | |
113 | retcode, stdout, stderr = run_script( |
114 | "cronscripts/process-job-source.py", |
115 | - ["IProcessApportBlobJobSource"], |
116 | - expect_returncode=0, |
117 | + args=["IProcessApportBlobJobSource"], |
118 | ) |
119 | + self.assertEqual(0, retcode) |
120 | self.assertEqual("", stdout) |
121 | self.assertIn("INFO Ran 1 ProcessApportBlobJob jobs.\n", stderr) |
122 | |
123 | diff --git a/lib/lp/code/scripts/tests/test_merge_proposal_jobs.py b/lib/lp/code/scripts/tests/test_merge_proposal_jobs.py |
124 | index cd56f50..debcd90 100644 |
125 | --- a/lib/lp/code/scripts/tests/test_merge_proposal_jobs.py |
126 | +++ b/lib/lp/code/scripts/tests/test_merge_proposal_jobs.py |
127 | @@ -5,6 +5,8 @@ |
128 | |
129 | """Test the sendbranchmail script""" |
130 | |
131 | +import os.path |
132 | + |
133 | import transaction |
134 | from testtools.matchers import MatchesRegex |
135 | |
136 | @@ -12,9 +14,10 @@ from lp.code.model.tests.test_branchmergeproposaljobs import ( |
137 | make_runnable_incremental_diff_job, |
138 | ) |
139 | from lp.code.model.tests.test_diff import DiffTestCase |
140 | +from lp.services.config import config |
141 | from lp.services.job.interfaces.job import JobStatus |
142 | -from lp.services.scripts.tests import run_script |
143 | from lp.testing.layers import ZopelessAppServerLayer |
144 | +from lp.testing.script import run_script |
145 | |
146 | |
147 | class TestMergeProposalJobScript(DiffTestCase): |
148 | @@ -25,8 +28,8 @@ class TestMergeProposalJobScript(DiffTestCase): |
149 | job = make_runnable_incremental_diff_job(self) |
150 | transaction.commit() |
151 | retcode, stdout, stderr = run_script( |
152 | - "cronscripts/process-job-source.py", |
153 | - ["--log-twisted", "IBranchMergeProposalJobSource"], |
154 | + os.path.join(config.root, "cronscripts", "process-job-source.py"), |
155 | + args=["--log-twisted", "IBranchMergeProposalJobSource"], |
156 | ) |
157 | self.assertEqual(0, retcode) |
158 | self.assertEqual("", stdout) |
159 | diff --git a/lib/lp/code/scripts/tests/test_reclaim_branch_space.py b/lib/lp/code/scripts/tests/test_reclaim_branch_space.py |
160 | index 06d70ce..8effa37 100644 |
161 | --- a/lib/lp/code/scripts/tests/test_reclaim_branch_space.py |
162 | +++ b/lib/lp/code/scripts/tests/test_reclaim_branch_space.py |
163 | @@ -14,9 +14,9 @@ from lp.code.model.branchjob import BranchJob, BranchJobType |
164 | from lp.codehosting.vfs import branch_id_to_path |
165 | from lp.services.config import config |
166 | from lp.services.database.interfaces import IStore |
167 | -from lp.services.scripts.tests import run_script |
168 | from lp.testing import TestCaseWithFactory |
169 | from lp.testing.layers import ZopelessAppServerLayer |
170 | +from lp.testing.script import run_script |
171 | |
172 | |
173 | class TestReclaimBranchSpaceScript(TestCaseWithFactory): |
174 | diff --git a/lib/lp/code/scripts/tests/test_request_daily_builds.py b/lib/lp/code/scripts/tests/test_request_daily_builds.py |
175 | index 2bbe383..9307e12 100644 |
176 | --- a/lib/lp/code/scripts/tests/test_request_daily_builds.py |
177 | +++ b/lib/lp/code/scripts/tests/test_request_daily_builds.py |
178 | @@ -19,11 +19,11 @@ from lp.code.interfaces.codehosting import BRANCH_ID_ALIAS_PREFIX |
179 | from lp.services.config import config |
180 | from lp.services.config.fixture import ConfigFixture, ConfigUseFixture |
181 | from lp.services.features.testing import FeatureFixture |
182 | -from lp.services.scripts.tests import run_script |
183 | from lp.snappy.interfaces.snap import SNAP_TESTING_FLAGS, ISnap |
184 | from lp.soyuz.enums import ArchivePurpose |
185 | from lp.testing import TestCaseWithFactory |
186 | from lp.testing.layers import ZopelessAppServerLayer |
187 | +from lp.testing.script import run_script |
188 | |
189 | |
190 | class SilentWSGIRequestHandler(WSGIRequestHandler): |
191 | @@ -328,8 +328,9 @@ class TestRequestDailyBuilds(TestCaseWithFactory): |
192 | pack_ref.repository, "charmcraft.yaml", b"name: pack-charm" |
193 | ) |
194 | retcode, stdout, stderr = run_script( |
195 | - "cronscripts/request_daily_builds.py", [] |
196 | + "cronscripts/request_daily_builds.py" |
197 | ) |
198 | + self.assertEqual(0, retcode) |
199 | self.assertIn("Requested 4 daily recipe builds.", stderr) |
200 | self.assertIn( |
201 | "Requested 4 sets of automatic snap package builds.", stderr |
202 | @@ -352,8 +353,9 @@ class TestRequestDailyBuilds(TestCaseWithFactory): |
203 | ) |
204 | transaction.commit() |
205 | retcode, stdout, stderr = run_script( |
206 | - "cronscripts/request_daily_builds.py", [] |
207 | + "cronscripts/request_daily_builds.py" |
208 | ) |
209 | + self.assertEqual(0, retcode) |
210 | self.assertEqual(0, recipe.pending_builds.count()) |
211 | self.assertIn("Requested 0 daily recipe builds.", stderr) |
212 | self.assertIn( |
213 | diff --git a/lib/lp/code/scripts/tests/test_scan_branches.py b/lib/lp/code/scripts/tests/test_scan_branches.py |
214 | index 8a1e3eb..2363bb2 100644 |
215 | --- a/lib/lp/code/scripts/tests/test_scan_branches.py |
216 | +++ b/lib/lp/code/scripts/tests/test_scan_branches.py |
217 | @@ -5,6 +5,7 @@ |
218 | |
219 | """Test the scan_branches script.""" |
220 | |
221 | +import os.path |
222 | |
223 | import transaction |
224 | from storm.locals import Store |
225 | @@ -15,11 +16,12 @@ from lp.code.enums import ( |
226 | CodeReviewNotificationLevel, |
227 | ) |
228 | from lp.code.model.branchjob import BranchJob, BranchJobType, BranchScanJob |
229 | +from lp.services.config import config |
230 | from lp.services.job.model.job import Job, JobStatus |
231 | from lp.services.osutils import override_environ |
232 | -from lp.services.scripts.tests import run_script |
233 | from lp.testing import TestCaseWithFactory |
234 | from lp.testing.layers import ZopelessAppServerLayer |
235 | +from lp.testing.script import run_script |
236 | |
237 | |
238 | class TestScanBranches(TestCaseWithFactory): |
239 | @@ -42,11 +44,11 @@ class TestScanBranches(TestCaseWithFactory): |
240 | def run_script_and_assert_success(self): |
241 | """Run the scan_branches script and assert it ran successfully.""" |
242 | retcode, stdout, stderr = run_script( |
243 | - "cronscripts/process-job-source.py", |
244 | - ["IBranchScanJobSource"], |
245 | - expect_returncode=0, |
246 | + os.path.join(config.root, "cronscripts", "process-job-source.py"), |
247 | + args=["IBranchScanJobSource"], |
248 | ) |
249 | self.oops_capture.sync() |
250 | + self.assertEqual(0, retcode) |
251 | self.assertEqual("", stdout) |
252 | self.assertIn("INFO Ran 1 BranchScanJob jobs.\n", stderr) |
253 | |
254 | diff --git a/lib/lp/code/scripts/tests/test_sendbranchmail.py b/lib/lp/code/scripts/tests/test_sendbranchmail.py |
255 | index ff5df34..bf6e9cc 100644 |
256 | --- a/lib/lp/code/scripts/tests/test_sendbranchmail.py |
257 | +++ b/lib/lp/code/scripts/tests/test_sendbranchmail.py |
258 | @@ -3,6 +3,8 @@ |
259 | |
260 | """Test the sendbranchmail script""" |
261 | |
262 | +import os.path |
263 | + |
264 | import transaction |
265 | |
266 | from lp.code.enums import ( |
267 | @@ -11,10 +13,11 @@ from lp.code.enums import ( |
268 | CodeReviewNotificationLevel, |
269 | ) |
270 | from lp.code.model.branchjob import RevisionMailJob, RevisionsAddedJob |
271 | +from lp.services.config import config |
272 | from lp.services.osutils import override_environ |
273 | -from lp.services.scripts.tests import run_script |
274 | from lp.testing import TestCaseWithFactory |
275 | from lp.testing.layers import ZopelessAppServerLayer |
276 | +from lp.testing.script import run_script |
277 | |
278 | |
279 | class TestSendbranchmail(TestCaseWithFactory): |
280 | @@ -47,7 +50,8 @@ class TestSendbranchmail(TestCaseWithFactory): |
281 | ) |
282 | transaction.commit() |
283 | retcode, stdout, stderr = run_script( |
284 | - "cronscripts/process-job-source.py", ["IRevisionMailJobSource"] |
285 | + os.path.join(config.root, "cronscripts", "process-job-source.py"), |
286 | + args=["IRevisionMailJobSource"], |
287 | ) |
288 | self.assertTextMatchesExpressionIgnoreWhitespace( |
289 | "INFO " |
290 | @@ -76,7 +80,8 @@ class TestSendbranchmail(TestCaseWithFactory): |
291 | ) |
292 | transaction.commit() |
293 | retcode, stdout, stderr = run_script( |
294 | - "cronscripts/process-job-source.py", ["IRevisionsAddedJobSource"] |
295 | + os.path.join(config.root, "cronscripts", "process-job-source.py"), |
296 | + args=["IRevisionsAddedJobSource"], |
297 | ) |
298 | self.assertTextMatchesExpressionIgnoreWhitespace( |
299 | "INFO " |
300 | diff --git a/lib/lp/code/scripts/tests/test_upgrade_branches.py b/lib/lp/code/scripts/tests/test_upgrade_branches.py |
301 | index bb5f471..a25e263 100644 |
302 | --- a/lib/lp/code/scripts/tests/test_upgrade_branches.py |
303 | +++ b/lib/lp/code/scripts/tests/test_upgrade_branches.py |
304 | @@ -3,15 +3,17 @@ |
305 | |
306 | """Test the upgrade_branches script.""" |
307 | |
308 | +import os.path |
309 | |
310 | import transaction |
311 | from breezy.branch import Branch as BzrBranch |
312 | |
313 | from lp.code.model.branch import BranchFormat, RepositoryFormat |
314 | from lp.code.model.branchjob import BranchUpgradeJob |
315 | -from lp.services.scripts.tests import run_script |
316 | +from lp.services.config import config |
317 | from lp.testing import TestCaseWithFactory |
318 | from lp.testing.layers import ZopelessAppServerLayer |
319 | +from lp.testing.script import run_script |
320 | |
321 | |
322 | class TestUpgradeBranches(TestCaseWithFactory): |
323 | @@ -33,10 +35,10 @@ class TestUpgradeBranches(TestCaseWithFactory): |
324 | transaction.commit() |
325 | |
326 | retcode, stdout, stderr = run_script( |
327 | - "cronscripts/process-job-source.py", |
328 | - ["IBranchUpgradeJobSource"], |
329 | - expect_returncode=0, |
330 | + os.path.join(config.root, "cronscripts", "process-job-source.py"), |
331 | + args=["IBranchUpgradeJobSource"], |
332 | ) |
333 | + self.assertEqual(0, retcode) |
334 | self.assertEqual("", stdout) |
335 | self.assertIn("INFO Ran 1 BranchUpgradeJob jobs.\n", stderr) |
336 | |
337 | @@ -65,10 +67,10 @@ class TestUpgradeBranches(TestCaseWithFactory): |
338 | transaction.commit() |
339 | |
340 | retcode, stdout, stderr = run_script( |
341 | - "cronscripts/process-job-source.py", |
342 | - ["IBranchUpgradeJobSource"], |
343 | - expect_returncode=0, |
344 | + os.path.join(config.root, "cronscripts", "process-job-source.py"), |
345 | + args=["IBranchUpgradeJobSource"], |
346 | ) |
347 | + self.assertEqual(0, retcode) |
348 | self.assertEqual("", stdout) |
349 | self.assertIn("INFO Ran 1 BranchUpgradeJob jobs.\n", stderr) |
350 | |
351 | diff --git a/lib/lp/registry/tests/test_membership_notification_job.py b/lib/lp/registry/tests/test_membership_notification_job.py |
352 | index 1ff0ef7..dc213dd 100644 |
353 | --- a/lib/lp/registry/tests/test_membership_notification_job.py |
354 | +++ b/lib/lp/registry/tests/test_membership_notification_job.py |
355 | @@ -3,8 +3,6 @@ |
356 | |
357 | """Tests of `MembershipNotificationJob`.""" |
358 | |
359 | -import os |
360 | - |
361 | import transaction |
362 | from testtools.content import text_content |
363 | from zope.component import getUtility |
364 | @@ -113,12 +111,10 @@ class MembershipNotificationJobTest(TestCaseWithFactory): |
365 | ) |
366 | job_repr = repr(job) |
367 | transaction.commit() |
368 | - env = os.environ.copy() |
369 | - env["LP_DEBUG_SQL"] = "1" |
370 | exit_code, out, err = run_script( |
371 | "cronscripts/process-job-source.py", |
372 | args=["-vv", IMembershipNotificationJobSource.getName()], |
373 | - env=env, |
374 | + extra_env={"LP_DEBUG_SQL": "1"}, |
375 | ) |
376 | self.addDetail("stdout", text_content(out)) |
377 | self.addDetail("stderr", text_content(err)) |
378 | diff --git a/lib/lp/registry/tests/test_person_merge_job.py b/lib/lp/registry/tests/test_person_merge_job.py |
379 | index f537096..6db2384 100644 |
380 | --- a/lib/lp/registry/tests/test_person_merge_job.py |
381 | +++ b/lib/lp/registry/tests/test_person_merge_job.py |
382 | @@ -3,8 +3,6 @@ |
383 | |
384 | """Tests of `PersonMergeJob`.""" |
385 | |
386 | -import os |
387 | - |
388 | import transaction |
389 | from testtools.content import text_content |
390 | from zope.component import getUtility |
391 | @@ -143,12 +141,10 @@ class TestPersonMergeJob(TestCaseWithFactory): |
392 | ) |
393 | transaction.commit() |
394 | |
395 | - env = os.environ.copy() |
396 | - env["LP_DEBUG_SQL"] = "1" |
397 | exit_code, out, err = run_script( |
398 | "cronscripts/process-job-source.py", |
399 | args=["-vv", IPersonMergeJobSource.getName()], |
400 | - env=env, |
401 | + extra_env={"LP_DEBUG_SQL": "1"}, |
402 | ) |
403 | |
404 | self.addDetail("stdout", text_content(out)) |
405 | diff --git a/lib/lp/registry/tests/test_productjob.py b/lib/lp/registry/tests/test_productjob.py |
406 | index cc20fee..836f33e 100644 |
407 | --- a/lib/lp/registry/tests/test_productjob.py |
408 | +++ b/lib/lp/registry/tests/test_productjob.py |
409 | @@ -3,7 +3,6 @@ |
410 | |
411 | """Tests for ProductJobs.""" |
412 | |
413 | -import os |
414 | from datetime import datetime, timedelta, timezone |
415 | |
416 | import transaction |
417 | @@ -622,12 +621,10 @@ class CommericialExpirationMixin(CommercialHelpers): |
418 | proprietary_job = self.JOB_CLASS.create(proprietary_product, reviewer) |
419 | transaction.commit() |
420 | |
421 | - env = os.environ.copy() |
422 | - env["LP_DEBUG_SQL"] = "1" |
423 | exit_code, out, err = run_script( |
424 | "cronscripts/process-job-source.py", |
425 | args=["-vv", self.JOB_SOURCE_INTERFACE.getName()], |
426 | - env=env, |
427 | + extra_env={"LP_DEBUG_SQL": "1"}, |
428 | ) |
429 | self.addDetail("stdout", text_content(out)) |
430 | self.addDetail("stderr", text_content(err)) |
431 | diff --git a/lib/lp/registry/tests/test_sharingjob.py b/lib/lp/registry/tests/test_sharingjob.py |
432 | index a088b02..6710772 100644 |
433 | --- a/lib/lp/registry/tests/test_sharingjob.py |
434 | +++ b/lib/lp/registry/tests/test_sharingjob.py |
435 | @@ -3,8 +3,6 @@ |
436 | |
437 | """Tests for SharingJobs.""" |
438 | |
439 | -import os |
440 | - |
441 | import transaction |
442 | from testtools.content import text_content |
443 | from zope.component import getUtility |
444 | @@ -264,12 +262,10 @@ class TestRunViaCron(TestCaseWithFactory): |
445 | ) |
446 | transaction.commit() |
447 | |
448 | - env = os.environ.copy() |
449 | - env["LP_DEBUG_SQL"] = "1" |
450 | exit_code, out, err = run_script( |
451 | "cronscripts/process-job-source.py", |
452 | args=["-vv", job_type], |
453 | - env=env, |
454 | + extra_env={"LP_DEBUG_SQL": "1"}, |
455 | ) |
456 | self.addDetail("stdout", text_content(out)) |
457 | self.addDetail("stderr", text_content(err)) |
458 | diff --git a/lib/lp/scripts/tests/test_garbo.py b/lib/lp/scripts/tests/test_garbo.py |
459 | index cd06fcc..3e92ec0 100644 |
460 | --- a/lib/lp/scripts/tests/test_garbo.py |
461 | +++ b/lib/lp/scripts/tests/test_garbo.py |
462 | @@ -105,7 +105,6 @@ from lp.services.librarian.model import TimeLimitedToken |
463 | from lp.services.messages.interfaces.message import IMessageSet |
464 | from lp.services.messages.model.message import Message |
465 | from lp.services.openid.model.openidconsumer import OpenIDConsumerNonce |
466 | -from lp.services.scripts.tests import run_script |
467 | from lp.services.session.model import SessionData, SessionPkgData |
468 | from lp.services.verification.interfaces.authtoken import LoginTokenType |
469 | from lp.services.verification.model.logintoken import LoginToken |
470 | @@ -144,6 +143,7 @@ from lp.testing.layers import ( |
471 | ZopelessDatabaseLayer, |
472 | ) |
473 | from lp.testing.mail_helpers import pop_notifications |
474 | +from lp.testing.script import run_script |
475 | from lp.translations.model.pofile import POFile |
476 | from lp.translations.model.potmsgset import POTMsgSet |
477 | from lp.translations.model.translationtemplateitem import ( |
478 | @@ -158,18 +158,20 @@ class TestGarboScript(TestCase): |
479 | |
480 | def test_daily_script(self): |
481 | """Ensure garbo-daily.py actually runs.""" |
482 | - rv, out, err = run_script( |
483 | - "cronscripts/garbo-daily.py", ["-q"], expect_returncode=0 |
484 | + exit_code, out, err = run_script( |
485 | + "cronscripts/garbo-daily.py", args=["-q"] |
486 | ) |
487 | + self.assertEqual(0, exit_code) |
488 | self.assertFalse(out.strip(), "Output to stdout: %s" % out) |
489 | self.assertFalse(err.strip(), "Output to stderr: %s" % err) |
490 | DatabaseLayer.force_dirty_database() |
491 | |
492 | def test_hourly_script(self): |
493 | """Ensure garbo-hourly.py actually runs.""" |
494 | - rv, out, err = run_script( |
495 | - "cronscripts/garbo-hourly.py", ["-q"], expect_returncode=0 |
496 | + exit_code, out, err = run_script( |
497 | + "cronscripts/garbo-hourly.py", args=["-q"] |
498 | ) |
499 | + self.assertEqual(0, exit_code) |
500 | self.assertFalse(out.strip(), "Output to stdout: %s" % out) |
501 | self.assertFalse(err.strip(), "Output to stderr: %s" % err) |
502 | DatabaseLayer.force_dirty_database() |
503 | diff --git a/lib/lp/services/job/scripts/tests/test_process_job_source.py b/lib/lp/services/job/scripts/tests/test_process_job_source.py |
504 | index b66e847..6b0465e 100644 |
505 | --- a/lib/lp/services/job/scripts/tests/test_process_job_source.py |
506 | +++ b/lib/lp/services/job/scripts/tests/test_process_job_source.py |
507 | @@ -17,10 +17,10 @@ from lp.registry.interfaces.teammembership import ( |
508 | from lp.services.config import config |
509 | from lp.services.job.scripts import process_job_source |
510 | from lp.services.scripts.base import LOCK_PATH |
511 | -from lp.services.scripts.tests import run_script |
512 | from lp.testing import TestCase, TestCaseWithFactory, login_person |
513 | from lp.testing.layers import LaunchpadScriptLayer |
514 | from lp.testing.matchers import DocTestMatches |
515 | +from lp.testing.script import run_script |
516 | |
517 | |
518 | class ProcessSingleJobSourceConfigTest(TestCase): |
519 | @@ -55,9 +55,8 @@ class ProcessJobSourceTest(TestCaseWithFactory): |
520 | def test_missing_argument(self): |
521 | # The script should display usage info when called without any |
522 | # arguments. |
523 | - returncode, output, error = run_script( |
524 | - self.script, [], expect_returncode=1 |
525 | - ) |
526 | + returncode, output, error = run_script(self.script) |
527 | + self.assertEqual(1, returncode) |
528 | self.assertIn("Usage:", output) |
529 | self.assertIn("process-job-source.py [options] JOB_SOURCE", output) |
530 | |
531 | @@ -65,8 +64,9 @@ class ProcessJobSourceTest(TestCaseWithFactory): |
532 | # The script should just create a lockfile and exit if no jobs |
533 | # are in the queue. |
534 | returncode, output, error = run_script( |
535 | - self.script, ["IMembershipNotificationJobSource"] |
536 | + self.script, args=["IMembershipNotificationJobSource"] |
537 | ) |
538 | + self.assertEqual(0, returncode) |
539 | expected = ( |
540 | "INFO Creating lockfile: .*launchpad-process-job-" |
541 | "source-IMembershipNotificationJobSource.lock.*" |
542 | @@ -85,10 +85,9 @@ class ProcessJobSourceTest(TestCaseWithFactory): |
543 | lock.acquire() |
544 | try: |
545 | returncode, output, error = run_script( |
546 | - self.script, |
547 | - ["IMembershipNotificationJobSource"], |
548 | - expect_returncode=1, |
549 | + self.script, args=["IMembershipNotificationJobSource"] |
550 | ) |
551 | + self.assertEqual(1, returncode) |
552 | expected = dedent( |
553 | """\ |
554 | INFO Creating lockfile: {lock} |
555 | @@ -111,8 +110,9 @@ class ProcessJobSourceTest(TestCaseWithFactory): |
556 | tm.setStatus(TeamMembershipStatus.ADMIN, team.teamowner) |
557 | transaction.commit() |
558 | returncode, output, error = run_script( |
559 | - self.script, ["-v", "IMembershipNotificationJobSource"] |
560 | + self.script, args=["-v", "IMembershipNotificationJobSource"] |
561 | ) |
562 | + self.assertEqual(0, returncode) |
563 | self.assertIn( |
564 | ( |
565 | "INFO Running <MembershipNotificationJob " |
566 | @@ -149,9 +149,8 @@ class ProcessJobSourceGroupsTest(TestCaseWithFactory): |
567 | def test_missing_argument(self): |
568 | # The script should display usage info when called without any |
569 | # arguments. |
570 | - returncode, output, error = run_script( |
571 | - self.script, [], expect_returncode=1 |
572 | - ) |
573 | + returncode, output, error = run_script(self.script) |
574 | + self.assertEqual(1, returncode) |
575 | self.assertIn( |
576 | ( |
577 | "Usage: process-job-source-groups.py " |
578 | @@ -167,7 +166,8 @@ class ProcessJobSourceGroupsTest(TestCaseWithFactory): |
579 | # The script should just run over each job source class, and then |
580 | # exit if no jobs are in the queue. It should not create its own |
581 | # lockfile. |
582 | - returncode, output, error = run_script(self.script, ["MAIN"]) |
583 | + returncode, output, error = run_script(self.script, args=["MAIN"]) |
584 | + self.assertEqual(0, returncode) |
585 | expected = ( |
586 | ".*Creating lockfile:.*launchpad-process-job-" |
587 | "source-IMembershipNotificationJobSource.lock.*" |
588 | @@ -186,7 +186,10 @@ class ProcessJobSourceGroupsTest(TestCaseWithFactory): |
589 | tm = membership_set.getByPersonAndTeam(person, team) |
590 | tm.setStatus(TeamMembershipStatus.ADMIN, team.teamowner) |
591 | transaction.commit() |
592 | - returncode, output, error = run_script(self.script, ["-v", "MAIN"]) |
593 | + returncode, output, error = run_script( |
594 | + self.script, args=["-v", "MAIN"] |
595 | + ) |
596 | + self.assertEqual(0, returncode) |
597 | self.assertTextMatchesExpressionIgnoreWhitespace( |
598 | ( |
599 | "INFO Running <MembershipNotificationJob " |
600 | @@ -202,7 +205,8 @@ class ProcessJobSourceGroupsTest(TestCaseWithFactory): |
601 | args = ["MAIN"] |
602 | for source in self.getJobSources("MAIN"): |
603 | args.extend(("--exclude", source)) |
604 | - returncode, output, error = run_script(self.script, args) |
605 | + returncode, output, error = run_script(self.script, args=args) |
606 | + self.assertEqual(0, returncode) |
607 | self.assertEqual("", error) |
608 | |
609 | def test_exclude_non_existing_group(self): |
610 | @@ -212,6 +216,7 @@ class ProcessJobSourceGroupsTest(TestCaseWithFactory): |
611 | for source in self.getJobSources("MAIN"): |
612 | args.extend(("--exclude", source)) |
613 | args.extend(("--exclude", "BobbyDazzler")) |
614 | - returncode, output, error = run_script(self.script, args) |
615 | + returncode, output, error = run_script(self.script, args=args) |
616 | + self.assertEqual(0, returncode) |
617 | expected = "INFO 'BobbyDazzler' is not in MAIN\n" |
618 | self.assertThat(error, DocTestMatches(expected)) |
619 | diff --git a/lib/lp/services/scripts/tests/__init__.py b/lib/lp/services/scripts/tests/__init__.py |
620 | index 923eff1..7bcea71 100644 |
621 | --- a/lib/lp/services/scripts/tests/__init__.py |
622 | +++ b/lib/lp/services/scripts/tests/__init__.py |
623 | @@ -7,10 +7,8 @@ __all__ = [ |
624 | |
625 | |
626 | import os |
627 | -import subprocess |
628 | |
629 | import lp |
630 | -from lp.services.config import config |
631 | |
632 | LP_TREE = os.path.dirname(os.path.dirname(os.path.dirname(lp.__file__))) |
633 | |
634 | @@ -37,40 +35,3 @@ def find_lp_scripts(): |
635 | continue |
636 | scripts.append(script_path) |
637 | return sorted(scripts) |
638 | - |
639 | - |
640 | -def run_script( |
641 | - script_relpath, |
642 | - args, |
643 | - expect_returncode=0, |
644 | - extra_env=None, |
645 | - universal_newlines=True, |
646 | -): |
647 | - """Run a script for testing purposes. |
648 | - |
649 | - :param script_relpath: The relative path to the script, from the tree |
650 | - root. |
651 | - :param args: Arguments to provide to the script. |
652 | - :param expect_returncode: The return code expected. If a different value |
653 | - is returned, and exception will be raised. |
654 | - :param extra_env: A dictionary of extra environment variables to provide |
655 | - to the script, or None. |
656 | - :param universal_newlines: Passed to `subprocess.Popen`, defaulting to |
657 | - True. |
658 | - """ |
659 | - script = os.path.join(config.root, script_relpath) |
660 | - args = [script] + args |
661 | - env = dict(os.environ) |
662 | - if extra_env is not None: |
663 | - env.update(extra_env) |
664 | - process = subprocess.Popen( |
665 | - args, |
666 | - stdout=subprocess.PIPE, |
667 | - stderr=subprocess.PIPE, |
668 | - env=env, |
669 | - universal_newlines=universal_newlines, |
670 | - ) |
671 | - stdout, stderr = process.communicate() |
672 | - if process.returncode != expect_returncode: |
673 | - raise AssertionError("Failed:\n%s\n%s" % (stdout, stderr)) |
674 | - return (process.returncode, stdout, stderr) |
675 | diff --git a/lib/lp/services/webhooks/tests/test_job.py b/lib/lp/services/webhooks/tests/test_job.py |
676 | index eaca18c..2fee4d2 100644 |
677 | --- a/lib/lp/services/webhooks/tests/test_job.py |
678 | +++ b/lib/lp/services/webhooks/tests/test_job.py |
679 | @@ -42,7 +42,6 @@ from lp.services.features.testing import FeatureFixture |
680 | from lp.services.job.interfaces.job import JobStatus |
681 | from lp.services.job.runner import JobRunner |
682 | from lp.services.job.tests import block_on_job |
683 | -from lp.services.scripts.tests import run_script |
684 | from lp.services.webhooks.client import WebhookClient, create_request |
685 | from lp.services.webhooks.interfaces import ( |
686 | IWebhookClient, |
687 | @@ -69,6 +68,7 @@ from lp.testing.layers import ( |
688 | DatabaseFunctionalLayer, |
689 | ZopelessDatabaseLayer, |
690 | ) |
691 | +from lp.testing.script import run_script |
692 | |
693 | |
694 | class TestWebhookJob(TestCaseWithFactory): |
695 | @@ -925,9 +925,9 @@ class TestViaCronscript(TestCaseWithFactory): |
696 | |
697 | retcode, stdout, stderr = run_script( |
698 | "cronscripts/process-job-source.py", |
699 | - ["IWebhookDeliveryJobSource"], |
700 | - expect_returncode=0, |
701 | + args=["IWebhookDeliveryJobSource"], |
702 | ) |
703 | + self.assertEqual(0, retcode) |
704 | self.assertEqual("", stdout) |
705 | self.assertIn( |
706 | "INFO Scheduling retry due to WebhookDeliveryRetry", stderr |
707 | diff --git a/lib/lp/soyuz/tests/test_distroseriesdifferencejob.py b/lib/lp/soyuz/tests/test_distroseriesdifferencejob.py |
708 | index 39f0ef9..c6ce705 100644 |
709 | --- a/lib/lp/soyuz/tests/test_distroseriesdifferencejob.py |
710 | +++ b/lib/lp/soyuz/tests/test_distroseriesdifferencejob.py |
711 | @@ -21,7 +21,6 @@ from lp.services.database.interfaces import IPrimaryStore |
712 | from lp.services.features.testing import FeatureFixture |
713 | from lp.services.job.interfaces.job import JobStatus |
714 | from lp.services.job.tests import block_on_job |
715 | -from lp.services.scripts.tests import run_script |
716 | from lp.soyuz.enums import ArchivePurpose, PackagePublishingStatus |
717 | from lp.soyuz.interfaces.distributionjob import ( |
718 | DistributionJobType, |
719 | @@ -43,6 +42,7 @@ from lp.testing.layers import ( |
720 | LaunchpadZopelessLayer, |
721 | ZopelessDatabaseLayer, |
722 | ) |
723 | +from lp.testing.script import run_script |
724 | |
725 | |
726 | def find_dsd_for(dsp, package): |
727 | @@ -573,10 +573,10 @@ class TestDistroSeriesDifferenceJobSource(TestCaseWithFactory): |
728 | transaction.commit() |
729 | return_code, stdout, stderr = run_script( |
730 | "cronscripts/process-job-source.py", |
731 | - ["-v", "IDistroSeriesDifferenceJobSource"], |
732 | + args=["-v", "IDistroSeriesDifferenceJobSource"], |
733 | ) |
734 | # The cronscript ran how we expected it to. |
735 | - self.assertEqual(return_code, 0) |
736 | + self.assertEqual(0, return_code) |
737 | self.assertIn("INFO Ran 1 DistroSeriesDifferenceJob jobs.", stderr) |
738 | # And it did what we expected. |
739 | jobs = find_waiting_jobs( |
740 | diff --git a/lib/lp/soyuz/tests/test_initializedistroseriesjob.py b/lib/lp/soyuz/tests/test_initializedistroseriesjob.py |
741 | index 2ba33a2..dd48340 100644 |
742 | --- a/lib/lp/soyuz/tests/test_initializedistroseriesjob.py |
743 | +++ b/lib/lp/soyuz/tests/test_initializedistroseriesjob.py |
744 | @@ -14,7 +14,6 @@ from lp.registry.interfaces.distroseriesparent import IDistroSeriesParentSet |
745 | from lp.registry.interfaces.pocket import PackagePublishingPocket |
746 | from lp.services.features.testing import FeatureFixture |
747 | from lp.services.job.tests import block_on_job |
748 | -from lp.services.scripts.tests import run_script |
749 | from lp.soyuz.enums import SourcePackageFormat |
750 | from lp.soyuz.interfaces.distributionjob import ( |
751 | IInitializeDistroSeriesJobSource, |
752 | @@ -37,6 +36,7 @@ from lp.testing.layers import ( |
753 | DatabaseLayer, |
754 | LaunchpadZopelessLayer, |
755 | ) |
756 | +from lp.testing.script import run_script |
757 | |
758 | |
759 | class InitializeDistroSeriesJobTests(TestCaseWithFactory): |
760 | @@ -401,10 +401,11 @@ class InitializeDistroSeriesJobTestsWithPackages(TestCaseWithFactory): |
761 | self.assertEqual("amd64", child.nominatedarchindep.architecturetag) |
762 | |
763 | def test_cronscript(self): |
764 | - run_script( |
765 | + exit_code, _, _ = run_script( |
766 | "cronscripts/process-job-source.py", |
767 | - ["IInitializeDistroSeriesJobSource"], |
768 | + args=["IInitializeDistroSeriesJobSource"], |
769 | ) |
770 | + self.assertEqual(0, exit_code) |
771 | DatabaseLayer.force_dirty_database() |
772 | |
773 | |
774 | diff --git a/lib/lp/soyuz/tests/test_packagecopyjob.py b/lib/lp/soyuz/tests/test_packagecopyjob.py |
775 | index 189defd..586c1b8 100644 |
776 | --- a/lib/lp/soyuz/tests/test_packagecopyjob.py |
777 | +++ b/lib/lp/soyuz/tests/test_packagecopyjob.py |
778 | @@ -725,12 +725,10 @@ class PlainPackageCopyJobTests(TestCaseWithFactory, LocalTestHelper): |
779 | archive2.newComponentUploader(requester, "main") |
780 | transaction.commit() |
781 | |
782 | - env = os.environ.copy() |
783 | - env["LP_DEBUG_SQL"] = "1" |
784 | exit_code, out, err = run_script( |
785 | "cronscripts/process-job-source.py", |
786 | args=["-vv", IPlainPackageCopyJobSource.getName()], |
787 | - env=env, |
788 | + extra_env={"LP_DEBUG_SQL": "1"}, |
789 | ) |
790 | |
791 | self.addDetail("stdout", text_content(out)) |
792 | diff --git a/lib/lp/soyuz/tests/test_packagediffjob.py b/lib/lp/soyuz/tests/test_packagediffjob.py |
793 | index 31f74b0..8725c6c 100644 |
794 | --- a/lib/lp/soyuz/tests/test_packagediffjob.py |
795 | +++ b/lib/lp/soyuz/tests/test_packagediffjob.py |
796 | @@ -1,8 +1,6 @@ |
797 | # Copyright 2013-2018 Canonical Ltd. This software is licensed under the |
798 | # GNU Affero General Public License version 3 (see the file LICENSE). |
799 | |
800 | -import os |
801 | - |
802 | import transaction |
803 | from testtools.content import text_content |
804 | from zope.component import getUtility |
805 | @@ -78,12 +76,10 @@ class TestPackageDiffJob(TestCaseWithFactory): |
806 | def test_smoke(self): |
807 | diff = create_proper_job(self.factory) |
808 | transaction.commit() |
809 | - env = os.environ.copy() |
810 | - env["LP_DEBUG_SQL"] = "1" |
811 | exit_code, out, err = run_script( |
812 | "cronscripts/process-job-source.py", |
813 | args=["-vv", IPackageDiffJobSource.getName()], |
814 | - env=env, |
815 | + extra_env={"LP_DEBUG_SQL": "1"}, |
816 | ) |
817 | |
818 | self.addDetail("stdout", text_content(out)) |
819 | diff --git a/lib/lp/soyuz/tests/test_packagetranslationsuploadjob.py b/lib/lp/soyuz/tests/test_packagetranslationsuploadjob.py |
820 | index 5d2a734..9e92940 100644 |
821 | --- a/lib/lp/soyuz/tests/test_packagetranslationsuploadjob.py |
822 | +++ b/lib/lp/soyuz/tests/test_packagetranslationsuploadjob.py |
823 | @@ -1,8 +1,6 @@ |
824 | # Copyright 2013-2018 Canonical Ltd. This software is licensed under the |
825 | # GNU Affero General Public License version 3 (see the file LICENSE). |
826 | |
827 | -import os |
828 | - |
829 | import transaction |
830 | from testtools.content import text_content |
831 | from zope.component import getUtility |
832 | @@ -129,12 +127,10 @@ class TestPackageTranslationsUploadJob(LocalTestHelper): |
833 | } |
834 | spr, sp, job = self.makeJob(tar_content=tar_content) |
835 | transaction.commit() |
836 | - env = os.environ.copy() |
837 | - env["LP_DEBUG_SQL"] = "1" |
838 | exit_code, out, err = run_script( |
839 | "cronscripts/process-job-source.py", |
840 | args=["-vv", IPackageTranslationsUploadJobSource.getName()], |
841 | - env=env, |
842 | + extra_env={"LP_DEBUG_SQL": "1"}, |
843 | ) |
844 | |
845 | self.addDetail("stdout", text_content(out)) |
846 | diff --git a/lib/lp/soyuz/tests/test_processacceptedbugsjob.py b/lib/lp/soyuz/tests/test_processacceptedbugsjob.py |
847 | index c7c61e5..3716886 100644 |
848 | --- a/lib/lp/soyuz/tests/test_processacceptedbugsjob.py |
849 | +++ b/lib/lp/soyuz/tests/test_processacceptedbugsjob.py |
850 | @@ -4,7 +4,6 @@ |
851 | """Tests for jobs to close bugs for accepted package uploads.""" |
852 | |
853 | import io |
854 | -import os |
855 | from itertools import product |
856 | from textwrap import dedent |
857 | |
858 | @@ -446,12 +445,10 @@ class TestProcessAcceptedBugsJob(TestCaseWithFactory): |
859 | self.makeJob(spr=spr, bug_ids=[bug.id]) |
860 | transaction.commit() |
861 | |
862 | - env = os.environ.copy() |
863 | - env["LP_DEBUG_SQL"] = "1" |
864 | exit_code, out, err = run_script( |
865 | "cronscripts/process-job-source.py", |
866 | args=["-vv", IProcessAcceptedBugsJobSource.getName()], |
867 | - env=env, |
868 | + extra_env={"LP_DEBUG_SQL": "1"}, |
869 | ) |
870 | |
871 | self.addDetail("stdout", text_content(out)) |
872 | diff --git a/lib/lp/testing/script.py b/lib/lp/testing/script.py |
873 | index 4f4e5e9..039bd60 100644 |
874 | --- a/lib/lp/testing/script.py |
875 | +++ b/lib/lp/testing/script.py |
876 | @@ -61,7 +61,7 @@ def run_command( |
877 | def run_script( |
878 | script: str, |
879 | args: Optional[List[str]] = None, |
880 | - env: Optional[Dict[str, str]] = None, |
881 | + extra_env: Optional[Dict[str, str]] = None, |
882 | cwd: Optional[str] = None, |
883 | input: Optional[Union[bytes, str]] = None, |
884 | universal_newlines: bool = True, |
885 | @@ -70,19 +70,20 @@ def run_script( |
886 | |
887 | :param script: Python script to run. |
888 | :param args: optional list of command-line arguments. |
889 | - :param env: optional environment dict; if none is given, the script will |
890 | - get a copy of the environment of the calling process. In either |
891 | - case, `PYTHONPATH` is removed since inheriting it may break some |
892 | - scripts. |
893 | - :param env: optional, passed to `subprocess.Popen`. |
894 | + :param extra_env: optional dict of extra environment variables to pass |
895 | + to the script, in addition to those in the environment of the |
896 | + calling process. Regardless of whether this is passed, the |
897 | + `PYTHONPATH` environment variable is removed since inheriting it may |
898 | + break some scripts. |
899 | :param cwd: optional, passed to `subprocess.Popen`. |
900 | :param input: optional string to feed to standard input. |
901 | :param universal_newlines: passed to `subprocess.Popen`, defaulting to |
902 | True. |
903 | :return: tuple of return value, standard output, and standard error. |
904 | """ |
905 | - if env is None: |
906 | - env = os.environ.copy() |
907 | + env = os.environ.copy() |
908 | + if extra_env is not None: |
909 | + env.update(extra_env) |
910 | env.pop("PYTHONPATH", None) |
911 | |
912 | return run_command( |
913 | diff --git a/lib/lp/translations/doc/message-sharing-merge-script.rst b/lib/lp/translations/doc/message-sharing-merge-script.rst |
914 | index 09aa659..441c4c9 100644 |
915 | --- a/lib/lp/translations/doc/message-sharing-merge-script.rst |
916 | +++ b/lib/lp/translations/doc/message-sharing-merge-script.rst |
917 | @@ -7,10 +7,10 @@ translations into properly sharing ones. |
918 | Unit tests go through the details of how the script works. Here we just |
919 | show that the script can run and perform its work. |
920 | |
921 | - >>> from lp.services.scripts.tests import run_script |
922 | + >>> from lp.testing.script import run_script |
923 | >>> retcode, stdout, stderr = run_script( |
924 | ... "scripts/rosetta/message-sharing-merge.py", |
925 | - ... ["-q", "-P", "-T", "-d", "ubuntu", "-s", "evolution"], |
926 | + ... args=["-q", "-P", "-T", "-d", "ubuntu", "-s", "evolution"], |
927 | ... ) |
928 | |
929 | The migration succeeds. |
930 | diff --git a/lib/lp/translations/doc/translations-export-to-branch.rst b/lib/lp/translations/doc/translations-export-to-branch.rst |
931 | index f01c7bb..df55b23 100644 |
932 | --- a/lib/lp/translations/doc/translations-export-to-branch.rst |
933 | +++ b/lib/lp/translations/doc/translations-export-to-branch.rst |
934 | @@ -5,9 +5,9 @@ The translations-export-to-branch script visits all ProductSeries with a |
935 | translations_branch set, and for each, exports the series' translations |
936 | to that branch. |
937 | |
938 | - >>> from lp.services.scripts.tests import run_script |
939 | + >>> from lp.testing.script import run_script |
940 | >>> ret_code, stdout, stderr = run_script( |
941 | - ... "cronscripts/translations-export-to-branch.py", [] |
942 | + ... "cronscripts/translations-export-to-branch.py" |
943 | ... ) |
944 | >>> ret_code |
945 | 0 |
946 | diff --git a/lib/lp/translations/pottery/tests/test_detect_intltool.py b/lib/lp/translations/pottery/tests/test_detect_intltool.py |
947 | index 2f1af32..8c0ca0d 100644 |
948 | --- a/lib/lp/translations/pottery/tests/test_detect_intltool.py |
949 | +++ b/lib/lp/translations/pottery/tests/test_detect_intltool.py |
950 | @@ -7,8 +7,9 @@ from textwrap import dedent |
951 | |
952 | from breezy.controldir import ControlDir |
953 | |
954 | -from lp.services.scripts.tests import run_script |
955 | +from lp.services.config import config |
956 | from lp.testing import TestCase |
957 | +from lp.testing.script import run_script |
958 | from lp.translations.pottery.detect_intltool import is_intltool_structure |
959 | |
960 | |
961 | @@ -57,9 +58,15 @@ class SetupTestPackageMixin: |
962 | self.prepare_package("intltool_POTFILES_in_2") |
963 | |
964 | return_code, stdout, stderr = run_script( |
965 | - "scripts/rosetta/pottery-generate-intltool.py", [] |
966 | + os.path.join( |
967 | + config.root, |
968 | + "scripts", |
969 | + "rosetta", |
970 | + "pottery-generate-intltool.py", |
971 | + ) |
972 | ) |
973 | |
974 | + self.assertEqual(0, return_code) |
975 | self.assertEqual( |
976 | dedent( |
977 | """\ |
978 | diff --git a/lib/lp/translations/scripts/tests/test_merge_existing_packagings.py b/lib/lp/translations/scripts/tests/test_merge_existing_packagings.py |
979 | index 0f5794b..db5addd 100644 |
980 | --- a/lib/lp/translations/scripts/tests/test_merge_existing_packagings.py |
981 | +++ b/lib/lp/translations/scripts/tests/test_merge_existing_packagings.py |
982 | @@ -6,9 +6,9 @@ |
983 | |
984 | import transaction |
985 | |
986 | -from lp.services.scripts.tests import run_script |
987 | from lp.testing import TestCaseWithFactory, person_logged_in |
988 | from lp.testing.layers import ZopelessAppServerLayer |
989 | +from lp.testing.script import run_script |
990 | from lp.translations.tests.test_translationpackagingjob import ( |
991 | count_translations, |
992 | make_translation_merge_job, |
993 | @@ -29,10 +29,9 @@ class TestMergeExistingPackagings(TestCaseWithFactory): |
994 | self.assertEqual(2, count_translations(job)) |
995 | transaction.commit() |
996 | retcode, stdout, stderr = run_script( |
997 | - "scripts/rosetta/merge-existing-packagings.py", |
998 | - [], |
999 | - expect_returncode=0, |
1000 | + "scripts/rosetta/merge-existing-packagings.py" |
1001 | ) |
1002 | + self.assertEqual(0, retcode) |
1003 | merge_message = "INFO Merging %s/%s and %s/%s.\n" % ( |
1004 | job.productseries.product.name, |
1005 | job.productseries.name, |
1006 | diff --git a/lib/lp/translations/scripts/tests/test_packaging_translations.py b/lib/lp/translations/scripts/tests/test_packaging_translations.py |
1007 | index 4f30a29..9dc6c3d 100644 |
1008 | --- a/lib/lp/translations/scripts/tests/test_packaging_translations.py |
1009 | +++ b/lib/lp/translations/scripts/tests/test_packaging_translations.py |
1010 | @@ -9,9 +9,9 @@ from textwrap import dedent |
1011 | import transaction |
1012 | from testtools.matchers import MatchesRegex |
1013 | |
1014 | -from lp.services.scripts.tests import run_script |
1015 | from lp.testing import TestCaseWithFactory, admin_logged_in |
1016 | from lp.testing.layers import ZopelessAppServerLayer |
1017 | +from lp.testing.script import run_script |
1018 | from lp.translations.tests.test_translationpackagingjob import ( |
1019 | make_translation_merge_job, |
1020 | ) |
1021 | @@ -25,9 +25,9 @@ class TestMergeTranslations(TestCaseWithFactory): |
1022 | transaction.commit() |
1023 | retcode, stdout, stderr = run_script( |
1024 | "cronscripts/process-job-source.py", |
1025 | - ["ITranslationPackagingJobSource"], |
1026 | - expect_returncode=0, |
1027 | + args=["ITranslationPackagingJobSource"], |
1028 | ) |
1029 | + self.assertEqual(0, retcode) |
1030 | matcher = MatchesRegex( |
1031 | dedent( |
1032 | """\ |
1033 | @@ -52,9 +52,9 @@ class TestMergeTranslations(TestCaseWithFactory): |
1034 | transaction.commit() |
1035 | retcode, stdout, stderr = run_script( |
1036 | "cronscripts/process-job-source.py", |
1037 | - ["ITranslationPackagingJobSource"], |
1038 | - expect_returncode=0, |
1039 | + args=["ITranslationPackagingJobSource"], |
1040 | ) |
1041 | + self.assertEqual(0, retcode) |
1042 | matcher = MatchesRegex( |
1043 | dedent( |
1044 | """\ |
1045 | diff --git a/lib/lp/translations/scripts/tests/test_reupload_translations.py b/lib/lp/translations/scripts/tests/test_reupload_translations.py |
1046 | index 913889a..bb1cdf5 100644 |
1047 | --- a/lib/lp/translations/scripts/tests/test_reupload_translations.py |
1048 | +++ b/lib/lp/translations/scripts/tests/test_reupload_translations.py |
1049 | @@ -14,12 +14,12 @@ from zope.security.proxy import removeSecurityProxy |
1050 | |
1051 | from lp.registry.model.sourcepackage import SourcePackage |
1052 | from lp.services.librarian.model import LibraryFileAliasSet |
1053 | -from lp.services.scripts.tests import run_script |
1054 | from lp.soyuz.model.packagetranslationsuploadjob import ( |
1055 | _filter_ubuntu_translation_file, |
1056 | ) |
1057 | from lp.testing import TestCaseWithFactory |
1058 | from lp.testing.layers import LaunchpadZopelessLayer |
1059 | +from lp.testing.script import run_script |
1060 | from lp.translations.model.translationimportqueue import TranslationImportQueue |
1061 | from lp.translations.scripts.reupload_translations import ( |
1062 | ReuploadPackageTranslations, |
1063 | @@ -193,7 +193,7 @@ class TestReuploadScript(TestCaseWithFactory): |
1064 | """Test a run of the script.""" |
1065 | retcode, stdout, stderr = run_script( |
1066 | "scripts/rosetta/reupload-translations.py", |
1067 | - [ |
1068 | + args=[ |
1069 | "-d", |
1070 | self.distroseries.distribution.name, |
1071 | "-s", |
1072 | diff --git a/lib/lp/translations/scripts/tests/test_translations_to_branch.py b/lib/lp/translations/scripts/tests/test_translations_to_branch.py |
1073 | index 6a581c5..b88a82d 100644 |
1074 | --- a/lib/lp/translations/scripts/tests/test_translations_to_branch.py |
1075 | +++ b/lib/lp/translations/scripts/tests/test_translations_to_branch.py |
1076 | @@ -3,6 +3,7 @@ |
1077 | |
1078 | """Acceptance test for the translations-export-to-branch script.""" |
1079 | |
1080 | +import os.path |
1081 | import re |
1082 | from datetime import datetime, timedelta, timezone |
1083 | from textwrap import dedent |
1084 | @@ -22,10 +23,10 @@ from lp.registry.model.productseries import ProductSeries |
1085 | from lp.services.config import config |
1086 | from lp.services.database.interfaces import IStandbyStore |
1087 | from lp.services.log.logger import BufferLogger |
1088 | -from lp.services.scripts.tests import run_script |
1089 | from lp.testing import TestCaseWithFactory, map_branch_contents |
1090 | from lp.testing.fakemethod import FakeMethod |
1091 | from lp.testing.layers import ZopelessAppServerLayer |
1092 | +from lp.testing.script import run_script |
1093 | from lp.translations.scripts.translations_to_branch import ( |
1094 | ExportTranslationsToBranch, |
1095 | ) |
1096 | @@ -92,7 +93,10 @@ class TestExportTranslationsToBranch(TestCaseWithFactory): |
1097 | |
1098 | # Run The Script. |
1099 | retcode, stdout, stderr = run_script( |
1100 | - "cronscripts/translations-export-to-branch.py", ["-vvv"] |
1101 | + os.path.join( |
1102 | + config.root, "cronscripts", "translations-export-to-branch.py" |
1103 | + ), |
1104 | + args=["-vvv"], |
1105 | ) |
1106 | |
1107 | self.assertEqual("", stdout) |
1108 | @@ -144,8 +148,10 @@ class TestExportTranslationsToBranch(TestCaseWithFactory): |
1109 | # anything because it sees that the POFile has not been changed |
1110 | # since the last export. |
1111 | retcode, stdout, stderr = run_script( |
1112 | - "cronscripts/translations-export-to-branch.py", |
1113 | - ["-vvv", "--no-fudge"], |
1114 | + os.path.join( |
1115 | + config.root, "cronscripts", "translations-export-to-branch.py" |
1116 | + ), |
1117 | + args=["-vvv", "--no-fudge"], |
1118 | ) |
1119 | self.assertEqual(0, retcode) |
1120 | self.assertIn("Last commit was at", stderr) |
1121 | diff --git a/lib/lp/translations/tests/test_rosetta_branches_script.py b/lib/lp/translations/tests/test_rosetta_branches_script.py |
1122 | index d4c3ede..4480a44 100644 |
1123 | --- a/lib/lp/translations/tests/test_rosetta_branches_script.py |
1124 | +++ b/lib/lp/translations/tests/test_rosetta_branches_script.py |
1125 | @@ -7,14 +7,17 @@ This would normally be done in a doctest but TestCaseWithFactory has all the |
1126 | provisions to handle Bazaar branches. |
1127 | """ |
1128 | |
1129 | +import os.path |
1130 | + |
1131 | import transaction |
1132 | from zope.component import getUtility |
1133 | |
1134 | from lp.code.model.branchjob import RosettaUploadJob |
1135 | +from lp.services.config import config |
1136 | from lp.services.osutils import override_environ |
1137 | -from lp.services.scripts.tests import run_script |
1138 | from lp.testing import TestCaseWithFactory |
1139 | from lp.testing.layers import ZopelessAppServerLayer |
1140 | +from lp.testing.script import run_script |
1141 | from lp.translations.enums import RosettaImportStatus |
1142 | from lp.translations.interfaces.translationimportqueue import ( |
1143 | ITranslationImportQueue, |
1144 | @@ -65,7 +68,8 @@ class TestRosettaBranchesScript(TestCaseWithFactory): |
1145 | transaction.commit() |
1146 | |
1147 | return_code, stdout, stderr = run_script( |
1148 | - "cronscripts/process-job-source.py", ["IRosettaUploadJobSource"] |
1149 | + os.path.join(config.root, "cronscripts", "process-job-source.py"), |
1150 | + args=["IRosettaUploadJobSource"], |
1151 | ) |
1152 | self.assertEqual(0, return_code) |
1153 |