Merge lp:~jml/pkgme/imports-and-tempdir into lp:pkgme
- imports-and-tempdir
- Merge into trunk
Proposed by
Jonathan Lange
Status: | Merged |
---|---|
Approved by: | Jonathan Lange |
Approved revision: | 194 |
Merged at revision: | 140 |
Proposed branch: | lp:~jml/pkgme/imports-and-tempdir |
Merge into: | lp:pkgme |
Prerequisite: | lp:~jml/pkgme/api-rationalization |
Diff against target: |
1362 lines (+288/-324) 20 files modified
NEWS.txt (+11/-5) pkgme/testing.py (+8/-9) pkgme/tests/test_api.py (+6/-6) pkgme/tests/test_backend.py (+45/-51) pkgme/tests/test_debuild.py (+16/-28) pkgme/tests/test_distutils_command.py (+11/-10) pkgme/tests/test_info_elements.py (+2/-2) pkgme/tests/test_main.py (+4/-4) pkgme/tests/test_package_files.py (+13/-15) pkgme/tests/test_project_info.py (+60/-66) pkgme/tests/test_python_backend.py (+9/-10) pkgme/tests/test_run_script.py (+1/-1) pkgme/tests/test_script.py (+15/-24) pkgme/tests/test_template_file.py (+1/-1) pkgme/tests/test_testing.py (+1/-1) pkgme/tests/test_trace.py (+9/-8) pkgme/tests/test_upload.py (+1/-1) pkgme/tests/test_vala_backend.py (+45/-53) pkgme/tests/test_write.py (+29/-28) versions.cfg (+1/-1) |
To merge this branch: | bzr merge lp:~jml/pkgme/imports-and-tempdir |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Westby | Approve | ||
Review via email: mp+122551@code.launchpad.net |
Commit message
Deprecate TempdirFixture. Use treeshape 0.2.1 instead.
Description of the change
Changes the tests to use treeshape rather than TempdirFixture. This cuts down on lines of code and allows us to delete stuff from pkgme.testing if we so choose, which in turn will simplify dependency touch points.
To post a comment you must log in.
- 194. By Jonathan Lange
-
Merge trunk, resolving conflicts.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'NEWS.txt' |
2 | --- NEWS.txt 2012-09-03 14:31:00 +0000 |
3 | +++ NEWS.txt 2012-09-04 15:26:25 +0000 |
4 | @@ -15,14 +15,20 @@ |
5 | * New module ``pkgme.api`` that has the useful stuff from the pkgme script. |
6 | (Jonathan Lange) |
7 | |
8 | - * ``pkgme.bin.main.get_all_info`` is deprecated. Use |
9 | + |
10 | +Deprecations |
11 | +------------ |
12 | + |
13 | + * ``pkgme.bin.main.get_all_info``. Use |
14 | ``packaging_info_as_data(get_all_info(...))`` instead. Both are in |
15 | ``pkgme.api``. (Jonathan Lange) |
16 | |
17 | - * ``pkgme.write_packaging`` is deprecated. Instead use |
18 | - ``pkgme.api.get_all_info`` to get packaging information, and |
19 | - ``pkgme.api.write_packaging_info`` to write it out to disk. |
20 | - (Jonathan Lange) |
21 | + * ``pkgme.write_packaging``. Instead use ``pkgme.api.get_all_info`` to get |
22 | + packaging information, and ``pkgme.api.write_packaging_info`` to write it |
23 | + out to disk. (Jonathan Lange) |
24 | + |
25 | + * From ``pkgme.testing``, ``TempdirFixture``, ``FileFixture`` and |
26 | + ``ExecutableFileFixture``. Use ``treeshape.FileTree`` instead. |
27 | |
28 | |
29 | 0.3.1 (2012-08-28) |
30 | |
31 | === modified file 'pkgme/testing.py' |
32 | --- pkgme/testing.py 2012-08-06 13:26:13 +0000 |
33 | +++ pkgme/testing.py 2012-09-04 15:26:25 +0000 |
34 | @@ -1,12 +1,13 @@ |
35 | from ConfigParser import ConfigParser |
36 | import os |
37 | -import shutil |
38 | from StringIO import StringIO |
39 | -import tempfile |
40 | import subprocess |
41 | |
42 | from debian import deb822 |
43 | -from fixtures import Fixture |
44 | +from fixtures import ( |
45 | + Fixture, |
46 | + TempDir, |
47 | + ) |
48 | from testtools.matchers import ( |
49 | Equals, |
50 | Matcher, |
51 | @@ -22,12 +23,8 @@ |
52 | from pkgme.write import write_file |
53 | |
54 | |
55 | -class TempdirFixture(Fixture): |
56 | - |
57 | - def setUp(self): |
58 | - Fixture.setUp(self) |
59 | - self.path = tempfile.mkdtemp(prefix="pkgme-tests-") |
60 | - self.addCleanup(shutil.rmtree, self.path) |
61 | +class TempdirFixture(TempDir): |
62 | + """DEPRECATED - Use ``treeshape.FileTree`` instead.""" |
63 | |
64 | def abspath(self, relpath): |
65 | return os.path.abspath(os.path.join(self.path, relpath)) |
66 | @@ -53,6 +50,7 @@ |
67 | |
68 | |
69 | class FileFixture(Fixture): |
70 | + """DEPRECATED - Use ``treeshape.FileTree`` instead.""" |
71 | |
72 | def __init__(self, path, contents): |
73 | super(FileFixture, self).__init__() |
74 | @@ -67,6 +65,7 @@ |
75 | |
76 | |
77 | class ExecutableFileFixture(FileFixture): |
78 | + """DEPRECATED - Use ``treeshape.FileTree`` instead.""" |
79 | |
80 | def setUp(self): |
81 | FileFixture.setUp(self) |
82 | |
83 | === modified file 'pkgme/tests/test_api.py' |
84 | --- pkgme/tests/test_api.py 2012-09-03 14:19:36 +0000 |
85 | +++ pkgme/tests/test_api.py 2012-09-04 15:26:25 +0000 |
86 | @@ -5,18 +5,18 @@ |
87 | from treeshape import HasFileTree |
88 | |
89 | from .. import write_packaging |
90 | -from pkgme.api import write_packaging_info |
91 | -from pkgme.backend import StaticBackend |
92 | -from pkgme.info_elements import ( |
93 | +from ..api import write_packaging_info |
94 | +from ..backend import StaticBackend |
95 | +from ..info_elements import ( |
96 | Architecture, |
97 | Description, |
98 | Maintainer, |
99 | PackageName, |
100 | Version, |
101 | ) |
102 | -from pkgme.package_files import Control, DEBIAN_DIR |
103 | -from pkgme.project_info import DictInfo |
104 | -from pkgme.testing import ( |
105 | +from ..package_files import Control, DEBIAN_DIR |
106 | +from ..project_info import DictInfo |
107 | +from ..testing import ( |
108 | ControlSourceStanzaHasField, |
109 | StaticLoaderFixture, |
110 | ) |
111 | |
112 | === modified file 'pkgme/tests/test_backend.py' |
113 | --- pkgme/tests/test_backend.py 2012-08-31 09:23:08 +0000 |
114 | +++ pkgme/tests/test_backend.py 2012-09-04 15:26:25 +0000 |
115 | @@ -1,10 +1,14 @@ |
116 | import os |
117 | import sys |
118 | |
119 | -from fixtures import TestWithFixtures |
120 | +from fixtures import TempDir |
121 | from testtools import TestCase |
122 | +from treeshape import ( |
123 | + FileTree, |
124 | + from_rough_spec, |
125 | + ) |
126 | |
127 | -from pkgme.backend import ( |
128 | +from ..backend import ( |
129 | Backend, |
130 | BackendSelector, |
131 | EXTERNAL_BACKEND_PATHS, |
132 | @@ -19,17 +23,12 @@ |
133 | StaticLoader, |
134 | WantError, |
135 | ) |
136 | -from pkgme.project_info import ( |
137 | +from ..project_info import ( |
138 | MultipleExternalHelpersInfo, |
139 | SingleExternalHelperInfo, |
140 | ) |
141 | -from pkgme.run_script import ScriptUserError |
142 | -from pkgme.testing import ( |
143 | - ExecutableFileFixture, |
144 | - FileFixture, |
145 | - StaticLoaderFixture, |
146 | - TempdirFixture, |
147 | - ) |
148 | +from ..run_script import ScriptUserError |
149 | +from ..testing import StaticLoaderFixture |
150 | |
151 | |
152 | class TestBackend(TestCase): |
153 | @@ -40,18 +39,17 @@ |
154 | self.assertEqual(backend.name, backend.describe()) |
155 | |
156 | |
157 | -class ExternalHelpersBackendTests(TestCase, TestWithFixtures): |
158 | +class ExternalHelpersBackendTests(TestCase): |
159 | |
160 | def make_want_script(self, script, executable=True): |
161 | - tempdir = self.useFixture(TempdirFixture()) |
162 | - script_name = ExternalHelpersBackend.WANT_SCRIPT_NAME |
163 | - script_path = os.path.join(tempdir.path, script_name) |
164 | if executable: |
165 | - cls = ExecutableFileFixture |
166 | + permissions = 0700 |
167 | else: |
168 | - cls = FileFixture |
169 | - self.useFixture(cls(script_path, script)) |
170 | - return tempdir |
171 | + permissions = 0600 |
172 | + script_name = ExternalHelpersBackend.WANT_SCRIPT_NAME |
173 | + return self.useFixture( |
174 | + FileTree({script_name: {'content': script, |
175 | + 'permissions': permissions}})) |
176 | |
177 | def test_describe(self): |
178 | backend = ExternalHelpersBackend( |
179 | @@ -145,13 +143,13 @@ |
180 | self.assertEqual((10, None), backend.want(tempdir.path)) |
181 | |
182 | def test_missing_want_script(self): |
183 | - tempdir = self.useFixture(TempdirFixture()) |
184 | + path = self.useFixture(TempDir()).path |
185 | name = self.getUniqueString() |
186 | - backend = ExternalHelpersBackend(name, tempdir.path) |
187 | - e = self.assertRaises(AssertionError, backend.want, tempdir.path) |
188 | + backend = ExternalHelpersBackend(name, path) |
189 | + e = self.assertRaises(AssertionError, backend.want, path) |
190 | self.assertEqual( |
191 | "Backend %s (%s) has no '%s' script" |
192 | - % (name, tempdir.path, ExternalHelpersBackend.WANT_SCRIPT_NAME), |
193 | + % (name, path, ExternalHelpersBackend.WANT_SCRIPT_NAME), |
194 | str(e)) |
195 | |
196 | def test_want_script_not_executable(self): |
197 | @@ -219,18 +217,18 @@ |
198 | str(e)) |
199 | |
200 | def test_want_script_run_in_correct_dir(self): |
201 | - cwd_tempdir = self.useFixture(TempdirFixture()) |
202 | + cwd_tempdir = self.useFixture(TempDir()).path |
203 | script = """#!%s |
204 | import os |
205 | if os.getcwd() != '%s': |
206 | print "Backend was called in %%s rather than %%s" %% (os.getcwd(), '%s') |
207 | else: |
208 | print 10 |
209 | -""" % (sys.executable, cwd_tempdir.path, cwd_tempdir.path) |
210 | +""" % (sys.executable, cwd_tempdir, cwd_tempdir) |
211 | backend_tempdir = self.make_want_script(script) |
212 | backend = ExternalHelpersBackend( |
213 | self.getUniqueString(), backend_tempdir.path) |
214 | - self.assertEqual((10, None), backend.want(cwd_tempdir.path)) |
215 | + self.assertEqual((10, None), backend.want(cwd_tempdir)) |
216 | |
217 | def test_get_info_with_multiple(self): |
218 | helpers_path = self.getUniqueString() |
219 | @@ -242,18 +240,18 @@ |
220 | self.assertEqual(cwd_path, project_info.cwd) |
221 | |
222 | def test_get_info_with_single(self): |
223 | - helpers_tempdir = self.useFixture(TempdirFixture()) |
224 | + helpers_tempdir = self.useFixture(TempDir()).path |
225 | info_script_path = os.path.join( |
226 | - helpers_tempdir.path, |
227 | + helpers_tempdir, |
228 | SingleExternalHelperInfo.INFO_SCRIPT_NAME) |
229 | with open(info_script_path, "w"): |
230 | pass |
231 | cwd_path = self.getUniqueString() |
232 | backend = ExternalHelpersBackend( |
233 | - self.getUniqueString(), helpers_tempdir.path) |
234 | + self.getUniqueString(), helpers_tempdir) |
235 | project_info = backend.get_info(cwd_path) |
236 | self.assertIsInstance(project_info, SingleExternalHelperInfo) |
237 | - self.assertEqual(helpers_tempdir.path, project_info.basepath) |
238 | + self.assertEqual(helpers_tempdir, project_info.basepath) |
239 | self.assertEqual(cwd_path, project_info.cwd) |
240 | |
241 | |
242 | @@ -415,42 +413,40 @@ |
243 | selector.get_eligible_backends(path)) |
244 | |
245 | |
246 | -class ExternalHelpersBackendLoaderTests(TestCase, TestWithFixtures): |
247 | +class ExternalHelpersBackendLoaderTests(TestCase): |
248 | + |
249 | + def make_tree(self, *args): |
250 | + return self.useFixture(FileTree(from_rough_spec(args))) |
251 | |
252 | def test_loads_no_backends(self): |
253 | - tempdir = self.useFixture(TempdirFixture()) |
254 | - loader = ExternalHelpersBackendLoader([tempdir.path]) |
255 | + loader = ExternalHelpersBackendLoader([]) |
256 | self.assertEqual([], loader.load()) |
257 | |
258 | def test_loads_from_one_dir(self): |
259 | - tempdir = self.useFixture(TempdirFixture()) |
260 | backend_name = self.getUniqueString() |
261 | - basepath = tempdir.mkdir(backend_name) |
262 | - loader = ExternalHelpersBackendLoader([tempdir.path]) |
263 | + tree = self.make_tree(backend_name + '/') |
264 | + loader = ExternalHelpersBackendLoader([tree.path]) |
265 | backends = loader.load() |
266 | self.assertEqual(1, len(backends)) |
267 | self.assertIsInstance(backends[0], ExternalHelpersBackend) |
268 | self.assertEqual(backend_name, backends[0].name) |
269 | - self.assertEqual(basepath, backends[0].basepath) |
270 | + self.assertEqual(tree.join(backend_name), backends[0].basepath) |
271 | |
272 | def test_loads_from_two_dirs(self): |
273 | - tempdir1 = self.useFixture(TempdirFixture()) |
274 | - tempdir2 = self.useFixture(TempdirFixture()) |
275 | backend_name1 = self.getUniqueString() |
276 | backend_name2 = self.getUniqueString() |
277 | - tempdir1.mkdir(backend_name1) |
278 | - tempdir2.mkdir(backend_name2) |
279 | + tempdir1 = self.make_tree(backend_name1 + '/') |
280 | + tempdir2 = self.make_tree(backend_name2 + '/') |
281 | loader = ExternalHelpersBackendLoader( |
282 | [tempdir1.path, tempdir2.path]) |
283 | backends = loader.load() |
284 | self.assertEqual(2, len(backends)) |
285 | |
286 | def test_loads_only_one_instance_of_each_name(self): |
287 | - tempdir1 = self.useFixture(TempdirFixture()) |
288 | - tempdir2 = self.useFixture(TempdirFixture()) |
289 | backend_name = self.getUniqueString() |
290 | - basepath1 = tempdir1.mkdir(backend_name) |
291 | - tempdir2.mkdir(backend_name) |
292 | + tempdir1 = self.make_tree(backend_name + '/') |
293 | + tempdir2 = self.make_tree(backend_name + '/') |
294 | + basepath1 = tempdir1.join(backend_name) |
295 | loader = ExternalHelpersBackendLoader( |
296 | [tempdir1.path, tempdir2.path]) |
297 | backends = loader.load() |
298 | @@ -458,19 +454,17 @@ |
299 | self.assertEqual(basepath1, backends[0].basepath) |
300 | |
301 | def test_loads_only_dirs(self): |
302 | - tempdir = self.useFixture(TempdirFixture()) |
303 | - tempdir.touch(self.getUniqueString()) |
304 | - loader = ExternalHelpersBackendLoader([tempdir.path]) |
305 | + path = self.make_tree(self.getUniqueString()).path |
306 | + loader = ExternalHelpersBackendLoader([path]) |
307 | self.assertEqual([], loader.load()) |
308 | |
309 | def test_ignores_dotdirs(self): |
310 | - tempdir = self.useFixture(TempdirFixture()) |
311 | - tempdir.mkdir("." + self.getUniqueString()) |
312 | - loader = ExternalHelpersBackendLoader([tempdir.path]) |
313 | + dirname = '.%s/' % (self.getUniqueString(),) |
314 | + tempdir = self.make_tree(dirname).path |
315 | + loader = ExternalHelpersBackendLoader([tempdir]) |
316 | self.assertEqual([], loader.load()) |
317 | |
318 | def test_ignores_missing_dirs(self): |
319 | - self.useFixture(TempdirFixture()) |
320 | loader = ExternalHelpersBackendLoader([self.getUniqueString()]) |
321 | self.assertEqual([], loader.load()) |
322 | |
323 | |
324 | === modified file 'pkgme/tests/test_debuild.py' |
325 | --- pkgme/tests/test_debuild.py 2012-08-06 18:21:44 +0000 |
326 | +++ pkgme/tests/test_debuild.py 2012-09-04 15:26:25 +0000 |
327 | @@ -2,37 +2,26 @@ |
328 | import tarfile |
329 | |
330 | from testtools import TestCase |
331 | +from treeshape import FileTree |
332 | |
333 | -from pkgme.debuild import ( |
334 | +from ..debuild import ( |
335 | _find_binary_files_in_dir, |
336 | build_debian_source_include_binaries_content, |
337 | build_orig_tar_gz, |
338 | ) |
339 | -from pkgme.testing import ( |
340 | - TempdirFixture, |
341 | - ) |
342 | - |
343 | - |
344 | -class DebianTempDirFixture(TempdirFixture): |
345 | - """A temp directory with a "testpkg" directory that contains |
346 | - a skeleton dir debian/ structure |
347 | - """ |
348 | - |
349 | - def setUp(self, with_binary_data=False): |
350 | - super(DebianTempDirFixture, self).setUp() |
351 | - self.pkgdir = self.abspath("testpkg") |
352 | - self.icon_path = os.path.join(self.pkgdir, "debian", "icons") |
353 | - self.debian_source_path = os.path.join(self.pkgdir, "debian", "source") |
354 | - # setup fake env |
355 | - os.makedirs(self.icon_path) |
356 | - os.makedirs(self.debian_source_path) |
357 | + |
358 | + |
359 | +def DebianTempDirFixture(): |
360 | + return FileTree( |
361 | + {'debian/icons/': {}, |
362 | + 'debian/source/': {}}) |
363 | |
364 | |
365 | class BuildTarTestCase(TestCase): |
366 | |
367 | def test_build_orig_tar_gz(self): |
368 | tempdir = self.useFixture(DebianTempDirFixture()) |
369 | - changelog_path = os.path.join(tempdir.pkgdir, "debian", "changelog") |
370 | + changelog_path = tempdir.join("debian", "changelog") |
371 | with open(changelog_path, "w") as f: |
372 | f.write(""" |
373 | testpkg (0.1) unstable; urgency=low |
374 | @@ -41,10 +30,10 @@ |
375 | |
376 | -- Some Guy <foo@example.com> Thu, 19 Apr 2012 10:53:30 +0200 |
377 | """) |
378 | - with open(os.path.join(tempdir.pkgdir, "canary"), "w") as f: |
379 | + with open(tempdir.join("canary"), "w") as f: |
380 | f.write("pieep") |
381 | # build it |
382 | - result_path = build_orig_tar_gz(tempdir.pkgdir) |
383 | + result_path = build_orig_tar_gz(tempdir.path) |
384 | # verify |
385 | self.assertEqual( |
386 | "testpkg_0.1.orig.tar.gz", os.path.basename(result_path)) |
387 | @@ -58,14 +47,14 @@ |
388 | |
389 | def _make_icons(self, tempdir): |
390 | for icon_name in ["foo.png", "bar.png"]: |
391 | - with open(os.path.join(tempdir.icon_path, icon_name), "w") as f: |
392 | + icon_path = tempdir.join('debian', 'icons', icon_name) |
393 | + with open(icon_path, "w") as f: |
394 | f.write("x\0x") |
395 | |
396 | def test_find_binary_files(self): |
397 | tempdir = self.useFixture(DebianTempDirFixture()) |
398 | self._make_icons(tempdir) |
399 | - bin_files = _find_binary_files_in_dir(os.path.join( |
400 | - tempdir.pkgdir, "debian")) |
401 | + bin_files = _find_binary_files_in_dir(tempdir.join('debian')) |
402 | self.assertEqual( |
403 | sorted(["icons/foo.png", "icons/bar.png"]), |
404 | sorted(bin_files)) |
405 | @@ -73,11 +62,10 @@ |
406 | def test_build_debian_source_include_binaries_content(self): |
407 | tempdir = self.useFixture(DebianTempDirFixture()) |
408 | self._make_icons(tempdir) |
409 | - build_debian_source_include_binaries_content(tempdir.pkgdir) |
410 | + build_debian_source_include_binaries_content(tempdir.path) |
411 | expected_binaries = sorted( |
412 | ['debian/icons/foo.png', 'debian/icons/bar.png']) |
413 | - include_binaries = os.path.join( |
414 | - tempdir.debian_source_path, "include-binaries") |
415 | + include_binaries = tempdir.join('debian', 'source', "include-binaries") |
416 | with open(include_binaries) as f: |
417 | found_binaries = sorted(line.strip() for line in f.readlines()) |
418 | self.assertEqual(expected_binaries, found_binaries) |
419 | |
420 | === modified file 'pkgme/tests/test_distutils_command.py' |
421 | --- pkgme/tests/test_distutils_command.py 2012-05-28 21:37:22 +0000 |
422 | +++ pkgme/tests/test_distutils_command.py 2012-09-04 15:26:25 +0000 |
423 | @@ -1,14 +1,15 @@ |
424 | from distutils.dist import Distribution |
425 | import json |
426 | +import os |
427 | |
428 | -from fixtures import TestWithFixtures |
429 | +from fixtures import TempDir |
430 | from testtools import TestCase |
431 | |
432 | -from pkgme.distutils_command.pkgme_info import pkgme_info |
433 | -from pkgme.testing import PathRequiredTestCase, TempdirFixture |
434 | - |
435 | - |
436 | -class pkgme_info_tests(TestCase, TestWithFixtures, PathRequiredTestCase): |
437 | +from ..distutils_command.pkgme_info import pkgme_info |
438 | +from ..testing import PathRequiredTestCase |
439 | + |
440 | + |
441 | +class pkgme_info_tests(TestCase, PathRequiredTestCase): |
442 | |
443 | def test_interprets_pkgmeinfo(self): |
444 | dist = Distribution() |
445 | @@ -26,8 +27,8 @@ |
446 | self.assertEqual([], cmd.pkgmeinfo) |
447 | |
448 | def test_provides_requested_information(self): |
449 | - tempdir = self.useFixture(TempdirFixture()) |
450 | - out_path = tempdir.abspath('output') |
451 | + tempdir = self.useFixture(TempDir()).path |
452 | + out_path = os.path.join(tempdir, 'output') |
453 | name = self.getUniqueString() |
454 | dist = Distribution(dict(name=name)) |
455 | cmd = pkgme_info(dist) |
456 | @@ -41,8 +42,8 @@ |
457 | self.assertEqual({"package_name": name}, output) |
458 | |
459 | def test_skips_unknown_info(self): |
460 | - tempdir = self.useFixture(TempdirFixture()) |
461 | - out_path = tempdir.abspath("output") |
462 | + tempdir = self.useFixture(TempDir()).path |
463 | + out_path = os.path.join(tempdir, "output") |
464 | name = self.getUniqueString() |
465 | dist = Distribution(dict(name=name)) |
466 | cmd = pkgme_info(dist) |
467 | |
468 | === modified file 'pkgme/tests/test_info_elements.py' |
469 | --- pkgme/tests/test_info_elements.py 2012-08-21 15:13:44 +0000 |
470 | +++ pkgme/tests/test_info_elements.py 2012-09-04 15:26:25 +0000 |
471 | @@ -3,7 +3,7 @@ |
472 | from fixtures import EnvironmentVariableFixture |
473 | from testtools import TestCase |
474 | |
475 | -from pkgme.info_elements import ( |
476 | +from ..info_elements import ( |
477 | BuildDepends, |
478 | debian_formatted_text, |
479 | Description, |
480 | @@ -16,7 +16,7 @@ |
481 | MissingInfoError, |
482 | PackageName, |
483 | ) |
484 | -from pkgme.project_info import DictInfo |
485 | +from ..project_info import DictInfo |
486 | |
487 | |
488 | class TestElement(InfoElement): |
489 | |
490 | === modified file 'pkgme/tests/test_main.py' |
491 | --- pkgme/tests/test_main.py 2012-08-31 10:28:27 +0000 |
492 | +++ pkgme/tests/test_main.py 2012-09-04 15:26:25 +0000 |
493 | @@ -1,12 +1,12 @@ |
494 | from testtools import TestCase |
495 | |
496 | -from pkgme import __version__ |
497 | -from pkgme.backend import ( |
498 | +from .. import __version__ |
499 | +from ..backend import ( |
500 | EXTERNAL_BACKEND_PATHS, |
501 | StaticBackend, |
502 | ) |
503 | -from pkgme.bin.main import get_version_info |
504 | -from pkgme.testing import StaticLoaderFixture |
505 | +from ..bin.main import get_version_info |
506 | +from ..testing import StaticLoaderFixture |
507 | |
508 | |
509 | class TestVersionInfo(TestCase): |
510 | |
511 | === modified file 'pkgme/tests/test_package_files.py' |
512 | --- pkgme/tests/test_package_files.py 2012-08-21 15:26:20 +0000 |
513 | +++ pkgme/tests/test_package_files.py 2012-09-04 15:26:25 +0000 |
514 | @@ -5,8 +5,9 @@ |
515 | from debian import changelog |
516 | from testtools import TestCase |
517 | from testtools.matchers import StartsWith |
518 | +from treeshape import FileTree |
519 | |
520 | -from pkgme.info_elements import ( |
521 | +from ..info_elements import ( |
522 | Architecture, |
523 | ApplicationName, |
524 | BuildDepends, |
525 | @@ -32,7 +33,7 @@ |
526 | Version, |
527 | WorkingDirectory, |
528 | ) |
529 | -from pkgme.package_files import ( |
530 | +from ..package_files import ( |
531 | BasicFile, |
532 | Changelog, |
533 | Compat, |
534 | @@ -46,14 +47,13 @@ |
535 | Rules, |
536 | TemplatePackageFile, |
537 | ) |
538 | -from pkgme.project_info import DictInfo |
539 | -from pkgme.testing import ( |
540 | +from ..project_info import DictInfo |
541 | +from ..testing import ( |
542 | AreDesktopValuesFor, |
543 | ControlStanzaHasField, |
544 | ControlStanzaDoesntHaveField, |
545 | ControlSourceStanzaHasField, |
546 | ControlSourceStanzaDoesntHaveField, |
547 | - TempdirFixture, |
548 | ) |
549 | |
550 | |
551 | @@ -610,21 +610,19 @@ |
552 | self.assertEqual(True, foo.overwrite) |
553 | |
554 | def test_extra_files_from_paths(self): |
555 | - tempdir = self.useFixture(TempdirFixture()) |
556 | - filename1 = 'foo' |
557 | - filename2 = 'bar' |
558 | - content1 = 'This is foo' |
559 | - content2 = 'This is bar' |
560 | - tempdir.create_file(filename1, content1) |
561 | - tempdir.create_file(filename2, content2) |
562 | + foo_content = self.getUniqueString() |
563 | + tree = self.useFixture( |
564 | + FileTree( |
565 | + {'foo': {'content': foo_content}, |
566 | + 'bar': {}})) |
567 | group = PackageFileGroup() |
568 | project_info = DictInfo({ |
569 | ExtraFilesFromPaths.name: { |
570 | - 'foo.txt': tempdir.abspath(filename1), |
571 | - 'debian/install': tempdir.abspath(filename2), |
572 | + 'foo.txt': tree.join('foo'), |
573 | + 'debian/install': tree.join('bar'), |
574 | }}) |
575 | files = group.get_files(project_info) |
576 | [foo, install] = files |
577 | self.assertEqual('foo.txt', foo.path) |
578 | - self.assertEqual(content1, foo.get_contents()) |
579 | + self.assertEqual(foo_content, foo.get_contents()) |
580 | self.assertEqual(True, foo.overwrite) |
581 | |
582 | === modified file 'pkgme/tests/test_project_info.py' |
583 | --- pkgme/tests/test_project_info.py 2011-10-31 18:15:27 +0000 |
584 | +++ pkgme/tests/test_project_info.py 2012-09-04 15:26:25 +0000 |
585 | @@ -1,24 +1,24 @@ |
586 | import json |
587 | import sys |
588 | |
589 | -from fixtures import TestWithFixtures |
590 | +from fixtures import TempDir |
591 | from testtools import TestCase |
592 | +from treeshape import ( |
593 | + CONTENT, |
594 | + FileTree, |
595 | + PERMISSIONS, |
596 | + ) |
597 | |
598 | -from pkgme.project_info import ( |
599 | +from ..project_info import ( |
600 | DictInfo, |
601 | FallbackInfo, |
602 | MultipleExternalHelpersInfo, |
603 | SingleExternalHelperInfo, |
604 | ) |
605 | -from pkgme.run_script import ( |
606 | +from ..run_script import ( |
607 | ScriptFailed, |
608 | ScriptPermissionDenied, |
609 | ) |
610 | -from pkgme.testing import ( |
611 | - ExecutableFileFixture, |
612 | - FileFixture, |
613 | - TempdirFixture, |
614 | - ) |
615 | |
616 | |
617 | class DictInfoTests(TestCase): |
618 | @@ -81,70 +81,70 @@ |
619 | self.assertEqual({key: value1}, info.get_all([key])) |
620 | |
621 | |
622 | -class MultipleExternalHelpersInfoTests(TestCase, TestWithFixtures): |
623 | +class MultipleExternalHelpersInfoTests(TestCase): |
624 | + |
625 | + def make_script(self, name, contents, permission=0700): |
626 | + return self.useFixture( |
627 | + FileTree({name: {CONTENT: contents, |
628 | + PERMISSIONS: permission}})).path |
629 | |
630 | def test_missing_helper(self): |
631 | - tempdir = self.useFixture(TempdirFixture()) |
632 | - info = MultipleExternalHelpersInfo(tempdir.path, tempdir.path) |
633 | + tempdir = self.useFixture(TempDir()).path |
634 | + info = MultipleExternalHelpersInfo(tempdir, tempdir) |
635 | key = self.getUniqueString() |
636 | self.assertEqual({key: None}, info.get_all([key])) |
637 | |
638 | def test_uses_output(self): |
639 | - tempdir = self.useFixture(TempdirFixture()) |
640 | script_name = self.getUniqueString() |
641 | - script_path = tempdir.abspath(script_name) |
642 | value = self.getUniqueString() |
643 | script = "#!/bin/sh\necho %s\n" % value |
644 | - self.useFixture(ExecutableFileFixture(script_path, script)) |
645 | - info = MultipleExternalHelpersInfo(tempdir.path, tempdir.path) |
646 | + tempdir = self.make_script(script_name, script) |
647 | + info = MultipleExternalHelpersInfo(tempdir, tempdir) |
648 | self.assertEqual({script_name: value}, info.get_all([script_name])) |
649 | |
650 | def test_script_error(self): |
651 | - tempdir = self.useFixture(TempdirFixture()) |
652 | script_name = self.getUniqueString() |
653 | - script_path = tempdir.abspath(script_name) |
654 | script = "#!/bin/sh\nexit 1\n" |
655 | - self.useFixture(ExecutableFileFixture(script_path, script)) |
656 | - info = MultipleExternalHelpersInfo(tempdir.path, tempdir.path) |
657 | + tempdir = self.make_script(script_name, script) |
658 | + info = MultipleExternalHelpersInfo(tempdir, tempdir) |
659 | self.assertRaises( |
660 | ScriptFailed, info.get_all, [script_name]) |
661 | |
662 | def test_script_permission_denied(self): |
663 | """Check the exception raised when the info script isn't executable.""" |
664 | - tempdir = self.useFixture(TempdirFixture()) |
665 | script_name = self.getUniqueString() |
666 | - script_path = tempdir.abspath(script_name) |
667 | script = "#!/bin/sh\nexit 0\n" |
668 | - self.useFixture(FileFixture(script_path, script)) |
669 | - info = MultipleExternalHelpersInfo(tempdir.path, tempdir.path) |
670 | + tempdir = self.make_script(script_name, script, 0644) |
671 | + info = MultipleExternalHelpersInfo(tempdir, tempdir) |
672 | self.assertRaises( |
673 | ScriptPermissionDenied, info.get_all, [script_name]) |
674 | |
675 | def test_correct_working_directory(self): |
676 | - script_tempdir = self.useFixture(TempdirFixture()) |
677 | - cwd_tempdir = self.useFixture(TempdirFixture()) |
678 | + cwd_tempdir = self.useFixture(TempDir()).path |
679 | script_name = self.getUniqueString() |
680 | - script_path = script_tempdir.abspath(script_name) |
681 | script = "#!%s\nimport os\nprint os.getcwd()\n" % sys.executable |
682 | - self.useFixture(ExecutableFileFixture(script_path, script)) |
683 | - info = MultipleExternalHelpersInfo( |
684 | - script_tempdir.path, cwd_tempdir.path) |
685 | + script_tempdir = self.make_script(script_name, script) |
686 | + info = MultipleExternalHelpersInfo(script_tempdir, cwd_tempdir) |
687 | self.assertEqual( |
688 | - {script_name: cwd_tempdir.path}, info.get_all([script_name])) |
689 | - |
690 | - |
691 | -class SingleExternalHelperInfoTests(TestCase, TestWithFixtures): |
692 | + {script_name: cwd_tempdir}, info.get_all([script_name])) |
693 | + |
694 | + |
695 | +class SingleExternalHelperInfoTests(TestCase): |
696 | + |
697 | + def make_script(self, contents, permission=0700): |
698 | + name = SingleExternalHelperInfo.INFO_SCRIPT_NAME |
699 | + return self.useFixture( |
700 | + FileTree({name: {CONTENT: contents, |
701 | + PERMISSIONS: permission}})) |
702 | |
703 | def test_uses_output(self): |
704 | - tempdir = self.useFixture(TempdirFixture()) |
705 | - script_name = self.getUniqueString() |
706 | - script_path = tempdir.abspath(SingleExternalHelperInfo.INFO_SCRIPT_NAME) |
707 | + element_name = self.getUniqueString() |
708 | value = self.getUniqueString() |
709 | script = '#!%s\nimport json\nprint json.dumps(%s)\n' % ( |
710 | - sys.executable, json.dumps({script_name: value})) |
711 | - self.useFixture(ExecutableFileFixture(script_path, script)) |
712 | - info = SingleExternalHelperInfo(tempdir.path, tempdir.path) |
713 | - self.assertEqual({script_name: value}, info.get_all([script_name])) |
714 | + sys.executable, json.dumps({element_name: value})) |
715 | + tempdir = self.make_script(script).path |
716 | + info = SingleExternalHelperInfo(tempdir, tempdir) |
717 | + self.assertEqual({element_name: value}, info.get_all([element_name])) |
718 | |
719 | def test_when_script_gives_invalid_json_output(self): |
720 | """Test when the script doesn't produce valid JSON. |
721 | @@ -152,48 +152,42 @@ |
722 | As this is a problem with the backend we expect an AssertionError |
723 | with an intelligible message. |
724 | """ |
725 | - tempdir = self.useFixture(TempdirFixture()) |
726 | - script_path = tempdir.abspath(SingleExternalHelperInfo.INFO_SCRIPT_NAME) |
727 | - value = self.getUniqueString() |
728 | script = '#!%s\nprint "}Nonsense"' % (sys.executable, ) |
729 | - self.useFixture(ExecutableFileFixture(script_path, script)) |
730 | + tempdir = self.make_script(script) |
731 | info = SingleExternalHelperInfo(tempdir.path, tempdir.path) |
732 | e = self.assertRaises(AssertionError, info.get_all, []) |
733 | - self.assertEquals("%s didn't return valid JSON: '}Nonsense\\n'" |
734 | - % (script_path, ), str(e)) |
735 | + self.assertEquals( |
736 | + "%s didn't return valid JSON: '}Nonsense\\n'" % ( |
737 | + tempdir.join(SingleExternalHelperInfo.INFO_SCRIPT_NAME),), |
738 | + str(e)) |
739 | |
740 | def test_passes_input(self): |
741 | - tempdir = self.useFixture(TempdirFixture()) |
742 | - script_name = self.getUniqueString() |
743 | - script_path = tempdir.abspath(SingleExternalHelperInfo.INFO_SCRIPT_NAME) |
744 | + element_name = self.getUniqueString() |
745 | value = self.getUniqueString() |
746 | - script = """#!%s |
747 | + script = """#!%(python)s |
748 | import json |
749 | import sys |
750 | |
751 | raw_input = sys.stdin.read() |
752 | input = json.loads(raw_input) |
753 | -if input != ["%s"]: |
754 | - print json.dumps({"%s": "Did not pass correct input: %%s" %% raw_input}) |
755 | +if input != ["%(element)s"]: |
756 | + print json.dumps({"%(element)s": "Did not pass correct input: %%s" %% raw_input}) |
757 | else: |
758 | - print json.dumps({"%s": "%s"}) |
759 | -""" % (sys.executable, script_name, script_name, script_name, value) |
760 | - self.useFixture(ExecutableFileFixture(script_path, script)) |
761 | - info = SingleExternalHelperInfo(tempdir.path, tempdir.path) |
762 | - self.assertEqual({script_name: value}, info.get_all([script_name])) |
763 | + print json.dumps({"%(element)s": "%(value)s"}) |
764 | +""" % {'python': sys.executable, 'element': element_name, 'value': value} |
765 | + tempdir = self.make_script(script).path |
766 | + info = SingleExternalHelperInfo(tempdir, tempdir) |
767 | + self.assertEqual({element_name: value}, info.get_all([element_name])) |
768 | |
769 | def test_correct_working_directory(self): |
770 | - script_tempdir = self.useFixture(TempdirFixture()) |
771 | - cwd_tempdir = self.useFixture(TempdirFixture()) |
772 | - script_name = self.getUniqueString() |
773 | - script_path = script_tempdir.abspath(SingleExternalHelperInfo.INFO_SCRIPT_NAME) |
774 | + cwd_tempdir = self.useFixture(TempDir()) |
775 | + element_name = self.getUniqueString() |
776 | script = """#!%s |
777 | import os |
778 | import json |
779 | print json.dumps({"%s": os.getcwd()}) |
780 | -""" % (sys.executable, script_name) |
781 | - self.useFixture(ExecutableFileFixture(script_path, script)) |
782 | - info = SingleExternalHelperInfo( |
783 | - script_tempdir.path, cwd_tempdir.path) |
784 | +""" % (sys.executable, element_name) |
785 | + script_tempdir = self.make_script(script).path |
786 | + info = SingleExternalHelperInfo(script_tempdir, cwd_tempdir.path) |
787 | self.assertEqual( |
788 | - {script_name: cwd_tempdir.path}, info.get_all([script_name])) |
789 | + {element_name: cwd_tempdir.path}, info.get_all([element_name])) |
790 | |
791 | === modified file 'pkgme/tests/test_python_backend.py' |
792 | --- pkgme/tests/test_python_backend.py 2012-09-03 10:42:06 +0000 |
793 | +++ pkgme/tests/test_python_backend.py 2012-09-04 15:26:25 +0000 |
794 | @@ -1,33 +1,32 @@ |
795 | -from fixtures import TestWithFixtures |
796 | from testtools import TestCase |
797 | +from treeshape import FileTree |
798 | |
799 | -from pkgme.backend import ExternalHelpersBackend, get_backend_dir |
800 | -from pkgme.testing import TempdirFixture |
801 | +from ..backend import ExternalHelpersBackend, get_backend_dir |
802 | |
803 | |
804 | backend_dir = get_backend_dir(__file__, 'python') |
805 | |
806 | |
807 | -class PythonBackendTests(TestCase, TestWithFixtures): |
808 | +class PythonBackendTests(TestCase): |
809 | |
810 | def test_want_with_setup_py(self): |
811 | - tempdir = self.useFixture(TempdirFixture()) |
812 | - tempdir.touch('setup.py') |
813 | + tempdir = self.useFixture(FileTree({'setup.py': {}})) |
814 | backend = ExternalHelpersBackend("python", backend_dir) |
815 | self.assertEqual((20, None), backend.want(tempdir.path)) |
816 | |
817 | def test_want_without_setup_py(self): |
818 | - tempdir = self.useFixture(TempdirFixture()) |
819 | + tempdir = self.useFixture(FileTree({})) |
820 | backend = ExternalHelpersBackend("python", backend_dir) |
821 | self.assertEqual( |
822 | (0, "Couldn't find a setup.py"), backend.want(tempdir.path)) |
823 | |
824 | def test_all_info(self): |
825 | - tempdir = self.useFixture(TempdirFixture()) |
826 | - tempdir.create_file('setup.py', """from distutils.core import setup |
827 | + tempdir = self.useFixture( |
828 | + FileTree({'setup.py': {'content': """\ |
829 | +from distutils.core import setup |
830 | |
831 | setup(name="foo") |
832 | -""") |
833 | +"""}})) |
834 | backend = ExternalHelpersBackend("python", backend_dir) |
835 | info = backend.get_info(tempdir.path) |
836 | info = info.get_all(['package_name']) |
837 | |
838 | === modified file 'pkgme/tests/test_run_script.py' |
839 | --- pkgme/tests/test_run_script.py 2012-08-22 13:37:48 +0000 |
840 | +++ pkgme/tests/test_run_script.py 2012-09-04 15:26:25 +0000 |
841 | @@ -2,7 +2,7 @@ |
842 | |
843 | from testtools import TestCase |
844 | |
845 | -from pkgme.run_script import ( |
846 | +from ..run_script import ( |
847 | ScriptFailed, |
848 | ScriptUserError, |
849 | ) |
850 | |
851 | === modified file 'pkgme/tests/test_script.py' |
852 | --- pkgme/tests/test_script.py 2012-09-04 15:17:02 +0000 |
853 | +++ pkgme/tests/test_script.py 2012-09-04 15:26:25 +0000 |
854 | @@ -13,16 +13,13 @@ |
855 | DirExists, |
856 | Not, |
857 | ) |
858 | +from treeshape import FileTree |
859 | |
860 | from ..api import ( |
861 | get_all_info, |
862 | load_backends, |
863 | packaging_info_as_data, |
864 | ) |
865 | -from ..backend import StaticBackend |
866 | -from ..info_elements import PackageName |
867 | -from ..project_info import DictInfo |
868 | -from ..testing import TempdirFixture |
869 | |
870 | |
871 | class ScriptTests(TestCase): |
872 | @@ -54,23 +51,21 @@ |
873 | self.assertEqual('', stderr.getvalue()) |
874 | return stdout.getvalue() |
875 | |
876 | - def create_marker_file(self, tempdir, prefix=None): |
877 | + def create_marker_file(self, prefix=None): |
878 | """Create the file that triggers the dummy backend for testing.""" |
879 | path = "is_pkgme_test" |
880 | if prefix is not None: |
881 | path = os.path.join(prefix, path) |
882 | - tempdir.create_file(path, "") |
883 | + return self.useFixture(FileTree({path: {}})) |
884 | |
885 | def test_writes_files(self): |
886 | - tempdir = self.useFixture(TempdirFixture()) |
887 | - self.create_marker_file(tempdir) |
888 | + tempdir = self.create_marker_file() |
889 | self.run_script(tempdir.path) |
890 | - self.assertThat(tempdir.abspath("debian"), DirExists()) |
891 | + self.assertThat(tempdir.join("debian"), DirExists()) |
892 | |
893 | def test_builds_source_package(self): |
894 | - tempdir = self.useFixture(TempdirFixture()) |
895 | - self.create_marker_file(tempdir, prefix="foo") |
896 | - self.run_script(tempdir.abspath('foo')) |
897 | + tempdir = self.create_marker_file(prefix="foo") |
898 | + self.run_script(tempdir.join('foo')) |
899 | self.assertThat(tempdir.path, DirContains( |
900 | ["foo_0.0.0.orig.tar.gz", |
901 | "foo_0.0.0.debian.tar.gz", |
902 | @@ -81,31 +76,27 @@ |
903 | ])) |
904 | |
905 | def test_nobuild_doesnt_builds_source_package(self): |
906 | - tempdir = self.useFixture(TempdirFixture()) |
907 | - self.create_marker_file(tempdir, prefix="foo") |
908 | - self.run_script(tempdir.abspath('foo'), ['--nobuild']) |
909 | + tempdir = self.create_marker_file(prefix="foo") |
910 | + self.run_script(tempdir.join('foo'), ['--nobuild']) |
911 | self.assertThat(tempdir.path, DirContains(["foo"])) |
912 | |
913 | def test_which_backends(self): |
914 | - tempdir = self.useFixture(TempdirFixture()) |
915 | - self.create_marker_file(tempdir) |
916 | + tempdir = self.create_marker_file() |
917 | output = self.run_script(tempdir.path, ['--which-backends']) |
918 | self.assertEqual('dummy (100)\n', output) |
919 | - self.assertThat(tempdir.abspath("debian"), Not(DirExists())) |
920 | + self.assertThat(tempdir.join("debian"), Not(DirExists())) |
921 | |
922 | def test_dump(self): |
923 | - tempdir = self.useFixture(TempdirFixture()) |
924 | - self.create_marker_file(tempdir) |
925 | + tempdir = self.create_marker_file() |
926 | all_info = get_all_info(tempdir.path, load_backends()) |
927 | clean_info = packaging_info_as_data(all_info) |
928 | output = self.run_script(tempdir.path, ['--dump']) |
929 | self.assertEqual(clean_info, json.loads(output)) |
930 | - self.assertThat(tempdir.abspath("debian"), Not(DirExists())) |
931 | + self.assertThat(tempdir.join("debian"), Not(DirExists())) |
932 | |
933 | def test_nosign(self): |
934 | - tempdir = self.useFixture(TempdirFixture()) |
935 | - self.create_marker_file(tempdir, prefix='foo') |
936 | - self.run_script(tempdir.abspath('foo'), ['--nosign']) |
937 | + tempdir = self.create_marker_file(prefix='foo') |
938 | + self.run_script(tempdir.join('foo'), ['--nosign']) |
939 | changes_file = os.path.join(tempdir.path, |
940 | "foo_0.0.0_source.changes") |
941 | signature = open(changes_file) |
942 | |
943 | === modified file 'pkgme/tests/test_template_file.py' |
944 | --- pkgme/tests/test_template_file.py 2010-11-05 20:29:46 +0000 |
945 | +++ pkgme/tests/test_template_file.py 2012-09-04 15:26:25 +0000 |
946 | @@ -1,6 +1,6 @@ |
947 | from testtools import TestCase |
948 | |
949 | -from pkgme.template_file import TemplateFile |
950 | +from ..template_file import TemplateFile |
951 | |
952 | |
953 | class TemplateFileTests(TestCase): |
954 | |
955 | === modified file 'pkgme/tests/test_testing.py' |
956 | --- pkgme/tests/test_testing.py 2012-08-06 13:26:01 +0000 |
957 | +++ pkgme/tests/test_testing.py 2012-09-04 15:26:25 +0000 |
958 | @@ -6,7 +6,7 @@ |
959 | FileContains, |
960 | ) |
961 | |
962 | -from pkgme.testing import ( |
963 | +from ..testing import ( |
964 | TempdirFixture, |
965 | ) |
966 | |
967 | |
968 | === modified file 'pkgme/tests/test_trace.py' |
969 | --- pkgme/tests/test_trace.py 2012-01-19 12:18:32 +0000 |
970 | +++ pkgme/tests/test_trace.py 2012-09-04 15:26:25 +0000 |
971 | @@ -1,11 +1,14 @@ |
972 | import os |
973 | |
974 | -from fixtures import EnvironmentVariableFixture |
975 | +from fixtures import ( |
976 | + EnvironmentVariableFixture, |
977 | + TempDir, |
978 | + TempHomeDir, |
979 | + ) |
980 | from testtools import TestCase |
981 | from testtools.matchers import MatchesRegex |
982 | |
983 | -from pkgme.testing import TempdirFixture |
984 | -from pkgme import trace |
985 | +from .. import trace |
986 | |
987 | |
988 | _date_time_re = r'\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d,\d\d\d' |
989 | @@ -13,9 +16,7 @@ |
990 | class TestLogging(TestCase): |
991 | |
992 | def with_temp_home(self): |
993 | - temp_dir = self.useFixture(TempdirFixture()) |
994 | - self.useFixture(EnvironmentVariableFixture('HOME', temp_dir.path)) |
995 | - return temp_dir |
996 | + return self.useFixture(TempHomeDir()) |
997 | |
998 | def with_temp_log(self): |
999 | self.with_temp_home() |
1000 | @@ -31,8 +32,8 @@ |
1001 | |
1002 | def test_log_location_from_env_var(self): |
1003 | # If PKGME_LOG_DIR is set in the environment we log there. |
1004 | - temp_home = self.with_temp_home() |
1005 | - temp_dir = self.useFixture(TempdirFixture()) |
1006 | + self.with_temp_home() |
1007 | + temp_dir = self.useFixture(TempDir()) |
1008 | self.useFixture(EnvironmentVariableFixture('PKGME_LOG_DIR', temp_dir.path)) |
1009 | log_location = trace.get_log_location() |
1010 | self.assertEqual(os.path.join(temp_dir.path, 'pkgme.log'), log_location) |
1011 | |
1012 | === modified file 'pkgme/tests/test_upload.py' |
1013 | --- pkgme/tests/test_upload.py 2011-08-01 18:11:44 +0000 |
1014 | +++ pkgme/tests/test_upload.py 2012-09-04 15:26:25 +0000 |
1015 | @@ -1,6 +1,6 @@ |
1016 | from testtools import TestCase |
1017 | |
1018 | -from pkgme.upload import ( |
1019 | +from ..upload import ( |
1020 | CannotUpload, |
1021 | InvalidPPAName, |
1022 | NoSuchPerson, |
1023 | |
1024 | === modified file 'pkgme/tests/test_vala_backend.py' |
1025 | --- pkgme/tests/test_vala_backend.py 2012-04-27 14:45:31 +0000 |
1026 | +++ pkgme/tests/test_vala_backend.py 2012-09-04 15:26:25 +0000 |
1027 | @@ -18,116 +18,108 @@ |
1028 | # Authors: Michael Terry <michael.terry@canonical.com> |
1029 | # ===================================================================== |
1030 | |
1031 | -import os |
1032 | - |
1033 | -from fixtures import TestWithFixtures |
1034 | +from fixtures import TempDir |
1035 | from testtools import TestCase |
1036 | +from treeshape import FileTree, from_rough_spec |
1037 | |
1038 | -from pkgme.backend import ExternalHelpersBackend, get_backend_dir |
1039 | -from pkgme.testing import CommandRequiredTestCase, TempdirFixture |
1040 | +from ..backend import ExternalHelpersBackend, get_backend_dir |
1041 | +from ..testing import CommandRequiredTestCase |
1042 | |
1043 | |
1044 | backend_dir = get_backend_dir(__file__, 'vala') |
1045 | |
1046 | |
1047 | -class ValaBackendTests(TestCase, TestWithFixtures, CommandRequiredTestCase): |
1048 | +class ValaBackendTests(TestCase, CommandRequiredTestCase): |
1049 | |
1050 | - def setUp(self): |
1051 | - super(ValaBackendTests, self).setUp() |
1052 | - self.tempdir = self.useFixture(TempdirFixture()) |
1053 | + def make_tree(self, *spec): |
1054 | + return self.useFixture(FileTree(from_rough_spec(spec))) |
1055 | |
1056 | def get_backend(self): |
1057 | return ExternalHelpersBackend("vala", backend_dir) |
1058 | |
1059 | - def get_info(self): |
1060 | - backend = self.get_backend() |
1061 | - return backend.get_info(self.tempdir.path) |
1062 | - |
1063 | def test_want_zero_deep(self): |
1064 | - self.tempdir.create_file("configure.ac", "") |
1065 | - self.tempdir.create_file("main.vala", "") |
1066 | + tempdir = self.make_tree('configure.ac', 'main.vala') |
1067 | backend = self.get_backend() |
1068 | - self.assertEqual((20, None), backend.want(self.tempdir.path)) |
1069 | + self.assertEqual((20, None), backend.want(tempdir.path)) |
1070 | |
1071 | def test_want_one_deep(self): |
1072 | - self.tempdir.create_file("configure.ac", "") |
1073 | - self.tempdir.create_file(os.path.join("one", "main.vala"), "") |
1074 | + tempdir = self.make_tree("configure.ac", "one/main.vala") |
1075 | backend = self.get_backend() |
1076 | - self.assertEqual((20, None), backend.want(self.tempdir.path)) |
1077 | + self.assertEqual((20, None), backend.want(tempdir.path)) |
1078 | |
1079 | def test_want_two_deep(self): |
1080 | - self.tempdir.create_file("configure.ac", "") |
1081 | - self.tempdir.create_file( |
1082 | - os.path.join("one", "two", "main.vala"), "") |
1083 | + tempdir = self.make_tree("configure.ac", "one/two/main.vala") |
1084 | backend = self.get_backend() |
1085 | - self.assertEqual((0, None), backend.want(self.tempdir.path)) |
1086 | + self.assertEqual((0, None), backend.want(tempdir.path)) |
1087 | |
1088 | def test_want_without_configure_ac(self): |
1089 | - self.tempdir.create_file("main.vala", "") |
1090 | + tempdir = self.make_tree("main.vala") |
1091 | backend = self.get_backend() |
1092 | - self.assertEqual((0, None), backend.want(self.tempdir.path)) |
1093 | + self.assertEqual((0, None), backend.want(tempdir.path)) |
1094 | |
1095 | def test_want_with_configure_in(self): |
1096 | - self.tempdir.create_file("configure.in", "") |
1097 | - self.tempdir.create_file("main.vala", "") |
1098 | + tempdir = self.make_tree("main.vala", "configure.in") |
1099 | backend = self.get_backend() |
1100 | - self.assertEqual((20, None), backend.want(self.tempdir.path)) |
1101 | + self.assertEqual((20, None), backend.want(tempdir.path)) |
1102 | |
1103 | def test_architecture(self): |
1104 | - info = self.get_info() |
1105 | + tempdir = self.useFixture(TempDir()) |
1106 | + info = self.get_backend().get_info(tempdir.path) |
1107 | self.assertEqual( |
1108 | {"architecture": "any"}, info.get_all(["architecture"])) |
1109 | |
1110 | def test_buildsystem(self): |
1111 | - info = self.get_info() |
1112 | + tempdir = self.useFixture(TempDir()) |
1113 | + info = self.get_backend().get_info(tempdir.path) |
1114 | self.assertEqual( |
1115 | {"buildsystem": "autoconf"}, info.get_all(["buildsystem"])) |
1116 | |
1117 | def test_build_depends(self): |
1118 | self.skipTestIfCommandNotExecutable('vala-dep-scanner') |
1119 | - self.tempdir.create_file("main.vala", "Gtk.Window win;") |
1120 | - info = self.get_info() |
1121 | + tempdir = self.make_tree(("main.vala", "Gtk.Window win;")) |
1122 | + info = self.get_backend().get_info(tempdir.path) |
1123 | self.assertEqual( |
1124 | {"build_depends": "libgtk3.0-dev, valac"}, |
1125 | info.get_all(["build_depends"])) |
1126 | |
1127 | def test_depends(self): |
1128 | - info = self.get_info() |
1129 | + tempdir = self.useFixture(TempDir()) |
1130 | + info = self.get_backend().get_info(tempdir.path) |
1131 | self.assertEqual( |
1132 | {"depends": "${shlibs:Depends}"}, info.get_all(["depends"])) |
1133 | |
1134 | def test_homepage(self): |
1135 | - self.tempdir.create_file( |
1136 | - "configure.ac", |
1137 | - "AC_INIT([Example Project],[1.0],[http://bugs.example.com/]," |
1138 | - "[example-project], [http://example.com/] )") |
1139 | - info = self.get_info() |
1140 | + tempdir = self.make_tree( |
1141 | + ("configure.ac", |
1142 | + "AC_INIT([Example Project],[1.0],[http://bugs.example.com/]," |
1143 | + "[example-project], [http://example.com/] )")) |
1144 | + info = self.get_backend().get_info(tempdir.path) |
1145 | self.assertEqual( |
1146 | {"homepage": "http://example.com/"}, info.get_all(["homepage"])) |
1147 | |
1148 | def test_homepage_none(self): |
1149 | - self.tempdir.create_file( |
1150 | - "configure.ac", |
1151 | - "AC_INIT([Example Project],[1.0],[http://bugs.example.com/]," |
1152 | - "[example-project])") |
1153 | - info = self.get_info() |
1154 | + tempdir = self.make_tree( |
1155 | + ("configure.ac", |
1156 | + "AC_INIT([Example Project],[1.0],[http://bugs.example.com/]," |
1157 | + "[example-project])")) |
1158 | + info = self.get_backend().get_info(tempdir.path) |
1159 | self.assertEqual( |
1160 | {"homepage": ""}, info.get_all(["homepage"])) |
1161 | |
1162 | def test_package_name(self): |
1163 | - self.tempdir.create_file( |
1164 | - "configure.ac", |
1165 | - "AC_INIT([GNU Example Project],[1.0],[http://bugs.example.com/]," |
1166 | - "[co ol-proj],[http://example.com/])") |
1167 | - info = self.get_info() |
1168 | + tempdir = self.make_tree( |
1169 | + ("configure.ac", |
1170 | + "AC_INIT([GNU Example Project],[1.0],[http://bugs.example.com/]," |
1171 | + "[co ol-proj],[http://example.com/])")) |
1172 | + info = self.get_backend().get_info(tempdir.path) |
1173 | self.assertEqual( |
1174 | {"package_name": "co ol-proj"}, info.get_all(["package_name"])) |
1175 | |
1176 | def test_package_name_none(self): |
1177 | - self.tempdir.create_file( |
1178 | - "configure.ac", |
1179 | - "AC_INIT( [GNU Example Project] , [1.0]," |
1180 | - "[http://bugs.example.com/])") |
1181 | - info = self.get_info() |
1182 | + tempdir = self.make_tree( |
1183 | + ("configure.ac", |
1184 | + "AC_INIT( [GNU Example Project] , [1.0]," |
1185 | + "[http://bugs.example.com/])")) |
1186 | + info = self.get_backend().get_info(tempdir.path) |
1187 | self.assertEqual( |
1188 | {"package_name": "example-project"}, info.get_all(["package_name"])) |
1189 | |
1190 | === modified file 'pkgme/tests/test_write.py' |
1191 | --- pkgme/tests/test_write.py 2012-08-06 13:26:01 +0000 |
1192 | +++ pkgme/tests/test_write.py 2012-09-04 15:26:25 +0000 |
1193 | @@ -1,6 +1,6 @@ |
1194 | import os |
1195 | |
1196 | -from fixtures import TestWithFixtures |
1197 | +from fixtures import TempDir |
1198 | from testtools import TestCase |
1199 | from testtools.matchers import ( |
1200 | DirExists, |
1201 | @@ -8,16 +8,17 @@ |
1202 | PathExists, |
1203 | ) |
1204 | |
1205 | -from pkgme.package_files import PackageFile |
1206 | -from pkgme.testing import ( |
1207 | - TempdirFixture, |
1208 | - ) |
1209 | -from pkgme.write import ( |
1210 | +from ..package_files import PackageFile |
1211 | +from ..write import ( |
1212 | write_file, |
1213 | Writer, |
1214 | ) |
1215 | |
1216 | |
1217 | +def abspath(fixture, *segments): |
1218 | + return os.path.join(fixture.path, *segments) |
1219 | + |
1220 | + |
1221 | class SimplePackageFile(PackageFile): |
1222 | |
1223 | def __init__(self, path, contents="", overwrite=True): |
1224 | @@ -29,80 +30,80 @@ |
1225 | return self.contents |
1226 | |
1227 | |
1228 | -class WriterTests(TestCase, TestWithFixtures): |
1229 | +class WriterTests(TestCase): |
1230 | |
1231 | def get_writer(self): |
1232 | return Writer() |
1233 | |
1234 | def do_write(self, tempdir=None): |
1235 | if tempdir is None: |
1236 | - tempdir = self.useFixture(TempdirFixture()) |
1237 | + tempdir = self.useFixture(TempDir()) |
1238 | writer = self.get_writer() |
1239 | writer.write(tempdir.path) |
1240 | return tempdir |
1241 | |
1242 | def test_write_creates_target_dir(self): |
1243 | writer = self.get_writer() |
1244 | - tempdir = self.useFixture(TempdirFixture()) |
1245 | - target_dir = tempdir.abspath(self.getUniqueString()) |
1246 | + tempdir = self.useFixture(TempDir()) |
1247 | + target_dir = abspath(tempdir, self.getUniqueString()) |
1248 | writer.write( |
1249 | [SimplePackageFile(self.getUniqueString())], target_dir) |
1250 | self.assertThat(target_dir, DirExists()) |
1251 | |
1252 | def test_write_creates_needed_subdirs(self): |
1253 | writer = self.get_writer() |
1254 | - tempdir = self.useFixture(TempdirFixture()) |
1255 | + tempdir = self.useFixture(TempDir()) |
1256 | subdir = self.getUniqueString() |
1257 | package_file = SimplePackageFile( |
1258 | os.path.join(subdir, self.getUniqueString())) |
1259 | writer.write([package_file], tempdir.path) |
1260 | - self.assertThat(tempdir.abspath(subdir), DirExists()) |
1261 | + self.assertThat(abspath(tempdir, subdir), DirExists()) |
1262 | |
1263 | def test_write_accepts_existing_subdir(self): |
1264 | writer = self.get_writer() |
1265 | - tempdir = self.useFixture(TempdirFixture()) |
1266 | + tempdir = self.useFixture(TempDir()) |
1267 | subdir = self.getUniqueString() |
1268 | package_file = SimplePackageFile( |
1269 | os.path.join(subdir, self.getUniqueString())) |
1270 | - os.makedirs(tempdir.abspath(subdir)) |
1271 | + os.makedirs(abspath(tempdir, subdir)) |
1272 | writer.write([package_file], tempdir.path) |
1273 | - self.assertThat(tempdir.abspath(subdir), DirExists()) |
1274 | + self.assertThat(abspath(tempdir, subdir), DirExists()) |
1275 | |
1276 | def test_write_creates_file(self): |
1277 | writer = self.get_writer() |
1278 | - tempdir = self.useFixture(TempdirFixture()) |
1279 | + tempdir = self.useFixture(TempDir()) |
1280 | filename = self.getUniqueString() |
1281 | package_file = SimplePackageFile(filename) |
1282 | writer.write([package_file], tempdir.path) |
1283 | - self.assertThat(tempdir.abspath(filename), PathExists()) |
1284 | + self.assertThat(abspath(tempdir, filename), PathExists()) |
1285 | |
1286 | def test_write_creates_file_with_correct_contents(self): |
1287 | writer = self.get_writer() |
1288 | - tempdir = self.useFixture(TempdirFixture()) |
1289 | + tempdir = self.useFixture(TempDir()) |
1290 | filename = self.getUniqueString() |
1291 | contents = self.getUniqueString() |
1292 | package_file = SimplePackageFile(filename, contents=contents) |
1293 | writer.write([package_file], tempdir.path) |
1294 | - self.assertThat(tempdir.abspath(filename), FileContains(contents)) |
1295 | + self.assertThat(abspath(tempdir, filename), FileContains(contents)) |
1296 | |
1297 | def test_write_creates_all_files(self): |
1298 | writer = self.get_writer() |
1299 | - tempdir = self.useFixture(TempdirFixture()) |
1300 | + tempdir = self.useFixture(TempDir()) |
1301 | filename1 = self.getUniqueString() |
1302 | package_file1 = SimplePackageFile(filename1) |
1303 | filename2 = self.getUniqueString() |
1304 | package_file2 = SimplePackageFile(filename2) |
1305 | writer.write([package_file1, package_file2], tempdir.path) |
1306 | - self.assertThat(tempdir.abspath(filename1), PathExists()) |
1307 | - self.assertThat(tempdir.abspath(filename2), PathExists()) |
1308 | + self.assertThat(abspath(tempdir, filename1), PathExists()) |
1309 | + self.assertThat(abspath(tempdir, filename2), PathExists()) |
1310 | |
1311 | def test_write_overwrites(self): |
1312 | writer = self.get_writer() |
1313 | - tempdir = self.useFixture(TempdirFixture()) |
1314 | + tempdir = self.useFixture(TempDir()) |
1315 | original_contents = self.getUniqueString() |
1316 | new_contents = self.getUniqueString() |
1317 | filename = self.getUniqueString() |
1318 | - target_path = tempdir.abspath(filename) |
1319 | + target_path = abspath(tempdir, filename) |
1320 | write_file(target_path, original_contents) |
1321 | package_file = SimplePackageFile( |
1322 | filename, contents=new_contents, overwrite=True) |
1323 | @@ -111,11 +112,11 @@ |
1324 | |
1325 | def test_write_doesnt_overwrite_files_with_overwrite_False(self): |
1326 | writer = self.get_writer() |
1327 | - tempdir = self.useFixture(TempdirFixture()) |
1328 | + tempdir = self.useFixture(TempDir()) |
1329 | original_contents = self.getUniqueString() |
1330 | new_contents = self.getUniqueString() |
1331 | filename = self.getUniqueString() |
1332 | - target_path = tempdir.abspath(filename) |
1333 | + target_path = abspath(tempdir, filename) |
1334 | write_file(target_path, original_contents) |
1335 | package_file = SimplePackageFile( |
1336 | filename, contents=new_contents, overwrite=False) |
1337 | @@ -124,10 +125,10 @@ |
1338 | |
1339 | def test_write_encodes_unicode(self): |
1340 | writer = self.get_writer() |
1341 | - tempdir = self.useFixture(TempdirFixture()) |
1342 | + tempdir = self.useFixture(TempDir()) |
1343 | contents = u"\x80" |
1344 | filename = self.getUniqueString() |
1345 | - target_path = tempdir.abspath(filename) |
1346 | + target_path = abspath(tempdir, filename) |
1347 | package_file = SimplePackageFile(filename, contents=contents) |
1348 | writer.write([package_file], tempdir.path) |
1349 | self.assertThat(target_path, FileContains(contents.encode('utf-8'))) |
1350 | |
1351 | === modified file 'versions.cfg' |
1352 | --- versions.cfg 2012-08-29 15:29:32 +0000 |
1353 | +++ versions.cfg 2012-09-04 15:26:25 +0000 |
1354 | @@ -26,7 +26,7 @@ |
1355 | simplejson = 2.6.1 |
1356 | testresources = 0.2.5 |
1357 | testtools = 0.9.16 |
1358 | -treeshape = 0.2.0 |
1359 | +treeshape = 0.2.1 |
1360 | wadllib = 1.3.1 |
1361 | wsgi-intercept = 0.5.1 |
1362 | z3c.recipe.scripts = 1.0.1 |
Looks good.
Thanks,
James