Merge lp:~jml/pkgme/more-info-in-api into lp:pkgme
- more-info-in-api
- Merge into trunk
Proposed by
Jonathan Lange
Status: | Work in progress |
---|---|
Proposed branch: | lp:~jml/pkgme/more-info-in-api |
Merge into: | lp:pkgme |
Diff against target: |
761 lines (+291/-269) 9 files modified
NEWS.txt (+11/-0) pkgme/__init__.py (+1/-44) pkgme/backend.py (+55/-48) pkgme/bin/main.py (+52/-4) pkgme/tests/__init__.py (+1/-1) pkgme/tests/test_backend.py (+9/-4) pkgme/tests/test_main.py (+161/-3) pkgme/tests/test_script.py (+1/-42) pkgme/tests/test_write_packaging.py (+0/-123) |
To merge this branch: | bzr merge lp:~jml/pkgme/more-info-in-api |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
pkgme committers | Pending | ||
Review via email:
|
Commit message
Description of the change
More information.
At the moment it's just me going crazy.
To post a comment you must log in.
lp:~jml/pkgme/more-info-in-api
updated
- 144. By Jonathan Lange
-
Just return the straight dict from get_eligible_
backends. - 145. By Jonathan Lange
-
Straight up data
- 146. By Jonathan Lange
-
Move the guts of some of the new methods out to be functions
- 147. By Jonathan Lange
-
Pull the main thing out of the class.
- 148. By Jonathan Lange
-
Move the guts of the __init__ file to main, where other very similar things
already live.Make sure the test modules line up with the modules they are testing.
- 149. By Jonathan Lange
-
We weren't running these tests :(
- 150. By Jonathan Lange
-
Document the change
Unmerged revisions
- 150. By Jonathan Lange
-
Document the change
- 149. By Jonathan Lange
-
We weren't running these tests :(
- 148. By Jonathan Lange
-
Move the guts of the __init__ file to main, where other very similar things
already live.Make sure the test modules line up with the modules they are testing.
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-08-28 10:57:30 +0000 |
3 | +++ NEWS.txt 2012-08-31 10:03:29 +0000 |
4 | @@ -3,6 +3,17 @@ |
5 | NEWS for pkgme |
6 | ============== |
7 | |
8 | + |
9 | +NEXT |
10 | +==== |
11 | + |
12 | +Changes |
13 | +------- |
14 | + |
15 | + * ``BackendSelector.get_eligible_backends`` returns a list of dicts, rather |
16 | + than a list of ``(score, backend)`` 2-tuples. (Jonathan Lange) |
17 | + |
18 | + |
19 | 0.3.1 (2012-08-28) |
20 | ================== |
21 | |
22 | |
23 | === modified file 'pkgme/__init__.py' |
24 | --- pkgme/__init__.py 2012-08-29 16:18:20 +0000 |
25 | +++ pkgme/__init__.py 2012-08-31 10:03:29 +0000 |
26 | @@ -21,54 +21,11 @@ |
27 | __metaclass__ = type |
28 | __all__ = [ |
29 | '__version__', |
30 | - 'get_packaging_info', |
31 | 'write_packaging', |
32 | - 'write_packaging_info', |
33 | ] |
34 | |
35 | |
36 | __version__ = '0.3.1' |
37 | |
38 | |
39 | - |
40 | -def get_packaging_info(path, distribution=None, allowed_backend_names=None): |
41 | - """Get the packaging information for 'path'. |
42 | - |
43 | - :param path: Path to the thing being packaged. |
44 | - :param distribution: Name of the distribution being packaged for. |
45 | - :param allowed_backend_names: List of allowed backend names. If not, |
46 | - provided, all backends are allowed. |
47 | - :return: A ``ProjectInfo`` object. |
48 | - """ |
49 | - # Do these imports in the function to reduce the side-effects of importing |
50 | - # pkgme. This avoids the need for setup.py of the tool being packaged |
51 | - # from having to find all the imported dependencies when running the |
52 | - # extension pkgme_info setup.py command. |
53 | - from pkgme.backend import get_info_for |
54 | - info = get_info_for(path, allowed_backend_names=allowed_backend_names) |
55 | - if distribution: |
56 | - from pkgme.info_elements import Distribution |
57 | - from pkgme.project_info import DictInfo, FallbackInfo |
58 | - info = FallbackInfo(DictInfo({Distribution.name: distribution}), info) |
59 | - return info |
60 | - |
61 | - |
62 | -def write_packaging_info(path, info): |
63 | - """Write packaging information for 'path'. |
64 | - |
65 | - :param path: Path to write the packaging information to. |
66 | - :param info: A ``ProjectInfo`` containing everything we need to package it. |
67 | - """ |
68 | - # Do these imports in the function to reduce the side-effects of importing |
69 | - # pkgme. This avoids the need for setup.py of the tool being packaged |
70 | - # from having to find all the imported dependencies when running the |
71 | - # extension pkgme_info setup.py command. |
72 | - from pkgme.package_files import default_package_file_group |
73 | - from pkgme.write import Writer |
74 | - files = default_package_file_group.get_files(info) |
75 | - Writer().write(files, path) |
76 | - |
77 | - |
78 | -def write_packaging(path, distribution=None, allowed_backend_names=None): |
79 | - info = get_packaging_info(path, distribution, allowed_backend_names) |
80 | - write_packaging_info(path, info) |
81 | +from .bin.main import write_packaging |
82 | |
83 | === modified file 'pkgme/backend.py' |
84 | --- pkgme/backend.py 2012-08-24 13:48:10 +0000 |
85 | +++ pkgme/backend.py 2012-08-31 10:03:29 +0000 |
86 | @@ -1,4 +1,5 @@ |
87 | import json |
88 | +from operator import itemgetter |
89 | import os |
90 | import sys |
91 | |
92 | @@ -265,23 +266,60 @@ |
93 | class NoEligibleBackend(PkgmeError): |
94 | """Raised when pkgme cannot find an appropriate backend.""" |
95 | |
96 | - def __init__(self, path, tried_backends, |
97 | - disallowed_backends=None): |
98 | - backend_names = [] |
99 | - for backend, reason in tried_backends: |
100 | - if reason: |
101 | - name = '%s (%s)' % (backend.name, reason) |
102 | - else: |
103 | - name = backend.name |
104 | - backend_names.append(name) |
105 | - backend_names = sorted(backend_names) |
106 | + def __init__(self, path, tried_backends, disallowed_backends=None): |
107 | + backend_names = sorted(map(self._describe_result, tried_backends)) |
108 | msg = ("No eligible backends for %s. Tried %s" |
109 | % (path, ', '.join(backend_names))) |
110 | - if disallowed_backends is not None: |
111 | + if disallowed_backends: |
112 | msg += (". The following backends were disallowed by policy: %s." |
113 | - % (', '.join(disallowed_backends))) |
114 | + % (', '.join([b.name for b in disallowed_backends]))) |
115 | super(NoEligibleBackend, self).__init__(msg) |
116 | |
117 | + @staticmethod |
118 | + def _describe_result(result): |
119 | + name = result['backend'].name |
120 | + reason = result.get('reason', None) |
121 | + if reason: |
122 | + name = '%s (%s)' % (name, reason) |
123 | + return name |
124 | + |
125 | + |
126 | +def dichotomy(predicate, collection): |
127 | + false, true = [], [] |
128 | + for x in collection: |
129 | + if predicate(x): |
130 | + true.append(x) |
131 | + else: |
132 | + false.append(x) |
133 | + return false, true |
134 | + |
135 | + |
136 | +def _query_backend(path, backend): |
137 | + score, reason = backend.want(path) |
138 | + return {'score': score, 'backend': backend, 'reason': reason} |
139 | + |
140 | + |
141 | +def _query_backends(path, backends): |
142 | + return (_query_backend(path, backend) for backend in backends) |
143 | + |
144 | + |
145 | +def _is_eligible(backend): |
146 | + return backend['score'] > 0 |
147 | + |
148 | + |
149 | +def query_backends(path, backends, allowed_backend_names=None): |
150 | + if not backends: |
151 | + raise NoBackend() |
152 | + if allowed_backend_names is None: |
153 | + disallowed, allowed = [], backends |
154 | + else: |
155 | + disallowed, allowed = dichotomy( |
156 | + lambda b: b.name in allowed_backend_names, backends) |
157 | + results = _query_backends(path, allowed) |
158 | + ineligible, eligible = dichotomy(_is_eligible, results) |
159 | + eligible.sort(key=itemgetter('score'), reverse=True) |
160 | + return disallowed, ineligible, eligible |
161 | + |
162 | |
163 | class BackendSelector(object): |
164 | |
165 | @@ -298,24 +336,6 @@ |
166 | self.backends = backends |
167 | self.allowed_backend_names = allowed_backend_names |
168 | |
169 | - def _split_disallowed_backends(self, backends): |
170 | - """Split backends into those allowed and those not. |
171 | - |
172 | - :return: (disallowed, allowed), where ``disallowed`` is a list |
173 | - of disallowed backend names and ``allowed`` is a list of |
174 | - allowed backends. If all backends are allowed then ``disallowed`` |
175 | - is None. |
176 | - """ |
177 | - if self.allowed_backend_names is None: |
178 | - return None, list(backends) |
179 | - disallowed, allowed = [], [] |
180 | - for backend in backends: |
181 | - if backend.name in self.allowed_backend_names: |
182 | - allowed.append(backend) |
183 | - else: |
184 | - disallowed.append(backend.name) |
185 | - return disallowed, allowed |
186 | - |
187 | def get_eligible_backends(self, path): |
188 | """Get the backends that could possibly work for ``path``. |
189 | |
190 | @@ -324,30 +344,17 @@ |
191 | :return: ``[(score, backend), ...]``. Will always be sorted with |
192 | the highest score first, and then lexographically by backend name. |
193 | """ |
194 | - if not self.backends: |
195 | - raise NoBackend() |
196 | - disallowed, backends = self._split_disallowed_backends(self.backends) |
197 | - eligible = [] |
198 | - ineligible = [] |
199 | - for backend in backends: |
200 | - score, reason = backend.want(path) |
201 | - trace.debug(' %s scored %s' % (backend.name, score)) |
202 | - if score > 0: |
203 | - eligible.append((score, backend)) |
204 | - else: |
205 | - ineligible.append((backend, reason)) |
206 | + disallowed, ineligible, eligible = query_backends( |
207 | + path, self.backends, self.allowed_backend_names) |
208 | if not eligible: |
209 | - # FIXME: some info about the problem. Bug 809423. |
210 | raise NoEligibleBackend( |
211 | - path, ineligible, |
212 | - disallowed_backends=disallowed) |
213 | - return sorted( |
214 | - eligible, key=lambda (score, backend): (-score, backend.name)) |
215 | + path, ineligible, disallowed_backends=disallowed) |
216 | + return eligible |
217 | |
218 | def get_info(self, path): |
219 | trace.debug('Finding backend for %s' % (path,)) |
220 | eligble = self.get_eligible_backends(path) |
221 | - backend = eligble[0][1] |
222 | + backend = eligble[0]['backend'] |
223 | if len(eligble) > 1: |
224 | trace.debug( |
225 | '%s eligble backends. Picked %s' % (len(eligble), backend.name)) |
226 | |
227 | === modified file 'pkgme/bin/main.py' |
228 | --- pkgme/bin/main.py 2012-07-20 19:24:04 +0000 |
229 | +++ pkgme/bin/main.py 2012-08-31 10:03:29 +0000 |
230 | @@ -5,7 +5,6 @@ |
231 | import os |
232 | import sys |
233 | |
234 | -from pkgme import __version__, write_packaging |
235 | from pkgme.backend import ( |
236 | EXTERNAL_BACKEND_PATHS, |
237 | get_backend_selector, |
238 | @@ -21,6 +20,49 @@ |
239 | from pkgme import trace |
240 | |
241 | |
242 | +def get_packaging_info(path, distribution=None, allowed_backend_names=None): |
243 | + """Get the packaging information for 'path'. |
244 | + |
245 | + :param path: Path to the thing being packaged. |
246 | + :param distribution: Name of the distribution being packaged for. |
247 | + :param allowed_backend_names: List of allowed backend names. If not, |
248 | + provided, all backends are allowed. |
249 | + :return: A ``ProjectInfo`` object. |
250 | + """ |
251 | + # Do these imports in the function to reduce the side-effects of importing |
252 | + # pkgme. This avoids the need for setup.py of the tool being packaged |
253 | + # from having to find all the imported dependencies when running the |
254 | + # extension pkgme_info setup.py command. |
255 | + from pkgme.backend import get_info_for |
256 | + info = get_info_for(path, allowed_backend_names=allowed_backend_names) |
257 | + if distribution: |
258 | + from pkgme.info_elements import Distribution |
259 | + from pkgme.project_info import DictInfo, FallbackInfo |
260 | + info = FallbackInfo(DictInfo({Distribution.name: distribution}), info) |
261 | + return info |
262 | + |
263 | + |
264 | +def write_packaging_info(path, info): |
265 | + """Write packaging information for 'path'. |
266 | + |
267 | + :param path: Path to write the packaging information to. |
268 | + :param info: A ``ProjectInfo`` containing everything we need to package it. |
269 | + """ |
270 | + # Do these imports in the function to reduce the side-effects of importing |
271 | + # pkgme. This avoids the need for setup.py of the tool being packaged |
272 | + # from having to find all the imported dependencies when running the |
273 | + # extension pkgme_info setup.py command. |
274 | + from pkgme.package_files import default_package_file_group |
275 | + from pkgme.write import Writer |
276 | + files = default_package_file_group.get_files(info) |
277 | + Writer().write(files, path) |
278 | + |
279 | + |
280 | +def write_packaging(path, distribution=None, allowed_backend_names=None): |
281 | + info = get_packaging_info(path, distribution, allowed_backend_names) |
282 | + write_packaging_info(path, info) |
283 | + |
284 | + |
285 | def build_package(target_dir, interactive, ppa=None, sign=None): |
286 | """Where the magic happens.""" |
287 | trace.debug("Building source package for %s" % (target_dir,)) |
288 | @@ -64,6 +106,7 @@ |
289 | |
290 | |
291 | def get_version_info(debug=False): |
292 | + from pkgme import __version__ |
293 | version = 'pkgme %s' % (__version__,) |
294 | if debug: |
295 | ls = [version, ''] |
296 | @@ -81,7 +124,12 @@ |
297 | """Return a string listing eligible backends for ``target_dir``.""" |
298 | selector = get_backend_selector() |
299 | backends = selector.get_eligible_backends(target_dir) |
300 | - return ', '.join('%s (%s)' % (backend.name, score) for (score, backend) in backends) |
301 | + return ', '.join('%s (%s)' % (r['backend'].name, r['score']) for r in backends) |
302 | + |
303 | + |
304 | +def _encode_backend(result): |
305 | + result.update({'backend': result['backend'].name}) |
306 | + return result |
307 | |
308 | |
309 | def get_all_info(target_dir, selector=None): |
310 | @@ -96,7 +144,7 @@ |
311 | if selector is None: |
312 | selector = get_backend_selector() |
313 | eligible = selector.get_eligible_backends(target_dir) |
314 | - backend = eligible[0][1] |
315 | + backend = eligible[0]['backend'] |
316 | # XXX: This ignores ExtraFiles and ExtraFilesFromPaths because they aren't |
317 | # in get_elements(). |
318 | elements = default_package_file_group.get_elements() |
319 | @@ -104,7 +152,7 @@ |
320 | project_info = backend.get_info(target_dir) |
321 | data = project_info.get_all(keys) |
322 | data[u'selected_backend'] = backend.name |
323 | - data[u'eligible_backends'] = [(score, b.name) for (score, b) in eligible] |
324 | + data[u'eligible_backends'] = map(_encode_backend, eligible) |
325 | return data |
326 | |
327 | |
328 | |
329 | === modified file 'pkgme/tests/__init__.py' |
330 | --- pkgme/tests/__init__.py 2011-11-23 16:26:39 +0000 |
331 | +++ pkgme/tests/__init__.py 2012-08-31 10:03:29 +0000 |
332 | @@ -7,6 +7,7 @@ |
333 | def test_suite(): |
334 | module_names = [ |
335 | 'pkgme.tests.test_backend', |
336 | + 'pkgme.tests.test_debuild', |
337 | 'pkgme.tests.test_distutils_command', |
338 | 'pkgme.tests.test_info_elements', |
339 | 'pkgme.tests.test_main', |
340 | @@ -21,7 +22,6 @@ |
341 | 'pkgme.tests.test_upload', |
342 | 'pkgme.tests.test_vala_backend', |
343 | 'pkgme.tests.test_write', |
344 | - 'pkgme.tests.test_write_packaging', |
345 | ] |
346 | loader = unittest.TestLoader() |
347 | suite = loader.loadTestsFromNames(module_names) |
348 | |
349 | === modified file 'pkgme/tests/test_backend.py' |
350 | --- pkgme/tests/test_backend.py 2012-08-24 13:54:32 +0000 |
351 | +++ pkgme/tests/test_backend.py 2012-08-31 10:03:29 +0000 |
352 | @@ -368,7 +368,8 @@ |
353 | backends = [backend1, backend2] |
354 | selector = BackendSelector(backends) |
355 | self.assertEqual( |
356 | - [(10, backend2), (5, backend1)], |
357 | + [{'score': 10, 'backend': backend2, 'reason': None}, |
358 | + {'score': 5, 'backend': backend1, 'reason': None}], |
359 | selector.get_eligible_backends(path)) |
360 | |
361 | def test_order_by_name_after_score(self): |
362 | @@ -381,7 +382,9 @@ |
363 | backends = [backend1, backend2, backend3] |
364 | selector = BackendSelector(backends) |
365 | self.assertEqual( |
366 | - [(10, backend2), (10, backend3), (5, backend1)], |
367 | + [{'score': 10, 'backend': backend2, 'reason': None}, |
368 | + {'score': 10, 'backend': backend3, 'reason': None}, |
369 | + {'score': 5, 'backend': backend1, 'reason': None}], |
370 | selector.get_eligible_backends(path)) |
371 | |
372 | def test_ineligible_backends_excluded(self): |
373 | @@ -393,7 +396,8 @@ |
374 | backends = [backend1, backend2, backend3] |
375 | selector = BackendSelector(backends) |
376 | self.assertEqual( |
377 | - [(10, backend2), (5, backend1)], |
378 | + [{'score': 10, 'backend': backend2, 'reason': None}, |
379 | + {'score': 5, 'backend': backend1, 'reason': None}], |
380 | selector.get_eligible_backends(path)) |
381 | |
382 | def test_excludes_non_allowed_backend(self): |
383 | @@ -407,7 +411,8 @@ |
384 | selector = BackendSelector(backends, |
385 | allowed_backend_names=allowed_backend_names) |
386 | self.assertEqual( |
387 | - [(10, backend2)], selector.get_eligible_backends(path)) |
388 | + [{'score': 10, 'backend': backend2, 'reason': None}], |
389 | + selector.get_eligible_backends(path)) |
390 | |
391 | |
392 | class ExternalHelpersBackendLoaderTests(TestCase, TestWithFixtures): |
393 | |
394 | === modified file 'pkgme/tests/test_main.py' |
395 | --- pkgme/tests/test_main.py 2011-10-26 19:25:00 +0000 |
396 | +++ pkgme/tests/test_main.py 2012-08-31 10:03:29 +0000 |
397 | @@ -1,12 +1,38 @@ |
398 | +import os |
399 | + |
400 | +from fixtures import TempDir |
401 | from testtools import TestCase |
402 | +from treeshape import HasFileTree |
403 | |
404 | -from pkgme import __version__ |
405 | +from pkgme import ( |
406 | + write_packaging, |
407 | + __version__, |
408 | + ) |
409 | from pkgme.backend import ( |
410 | + BackendSelector, |
411 | EXTERNAL_BACKEND_PATHS, |
412 | StaticBackend, |
413 | ) |
414 | -from pkgme.bin.main import get_version_info |
415 | -from pkgme.testing import StaticLoaderFixture |
416 | +from pkgme.bin.main import ( |
417 | + get_all_info, |
418 | + get_packaging_info, |
419 | + get_version_info, |
420 | + write_packaging_info, |
421 | + ) |
422 | +from pkgme.info_elements import ( |
423 | + Architecture, |
424 | + Description, |
425 | + Maintainer, |
426 | + PackageName, |
427 | + Version, |
428 | + ) |
429 | +from pkgme.package_files import Control, DEBIAN_DIR |
430 | +from pkgme.project_info import DictInfo |
431 | +from pkgme.testing import ( |
432 | + ControlSourceStanzaHasField, |
433 | + StaticLoaderFixture, |
434 | + ) |
435 | + |
436 | |
437 | class TestVersionInfo(TestCase): |
438 | |
439 | @@ -28,3 +54,135 @@ |
440 | ', '.join(map(repr, EXTERNAL_BACKEND_PATHS)), |
441 | expected_backends) |
442 | self.assertEqual(expected, x) |
443 | + |
444 | + |
445 | +class GetAllInfoTests(TestCase): |
446 | + |
447 | + def test_eligible_backends(self): |
448 | + info = DictInfo({}) |
449 | + backend1 = StaticBackend(self.getUniqueString(), 5, info) |
450 | + backend2 = StaticBackend(self.getUniqueString(), 10, info) |
451 | + selector = BackendSelector([backend1, backend2]) |
452 | + path = self.getUniqueString() |
453 | + info = get_all_info(path, selector) |
454 | + self.assertEqual( |
455 | + [{'score': 10, 'backend': backend2.name, 'reason': None}, |
456 | + {'score': 5, 'backend': backend1.name, 'reason': None}], |
457 | + info['eligible_backends']) |
458 | + |
459 | + def test_selected_backend(self): |
460 | + info = DictInfo({}) |
461 | + backend1 = StaticBackend(self.getUniqueString(), 5, info) |
462 | + backend2 = StaticBackend(self.getUniqueString(), 10, info) |
463 | + selector = BackendSelector([backend1, backend2]) |
464 | + path = self.getUniqueString() |
465 | + info = get_all_info(path, selector) |
466 | + self.assertEqual(backend2.name, info['selected_backend']) |
467 | + |
468 | + def test_all_info(self): |
469 | + info = {PackageName.name: self.getUniqueString()} |
470 | + backend = StaticBackend(self.getUniqueString(), 5, DictInfo(info)) |
471 | + selector = BackendSelector([backend]) |
472 | + path = self.getUniqueString() |
473 | + all_info = get_all_info(path, selector) |
474 | + del all_info['eligible_backends'] |
475 | + del all_info['selected_backend'] |
476 | + self.assertEqual(info, all_info) |
477 | + |
478 | + |
479 | +def ControlHasSourceName(name): |
480 | + control_path = os.path.join(DEBIAN_DIR, Control.filename) |
481 | + return HasFileTree( |
482 | + {control_path: |
483 | + {'content': ControlSourceStanzaHasField("Source", name)}}) |
484 | + |
485 | + |
486 | +class WritePackagingTests(TestCase): |
487 | + |
488 | + def make_info(self, name): |
489 | + info = DictInfo( |
490 | + { |
491 | + PackageName.name: name, |
492 | + Maintainer.name: self.getUniqueString(), |
493 | + Architecture.name: "all", |
494 | + Description.name: self.getUniqueString(), |
495 | + Version.name: "1", |
496 | + }) |
497 | + return info |
498 | + |
499 | + def test_write_packaging(self): |
500 | + name = PackageName.clean(self.getUniqueString()) |
501 | + info = self.make_info(name) |
502 | + tempdir = self.useFixture(TempDir()).path |
503 | + backend = StaticBackend( |
504 | + self.getUniqueString(), 10, info, expected_path=tempdir) |
505 | + self.useFixture(StaticLoaderFixture([backend])) |
506 | + write_packaging(tempdir) |
507 | + self.assertThat(tempdir, ControlHasSourceName(name)) |
508 | + |
509 | + def test_write_packaging_passes_allowed_backend_names(self): |
510 | + name = PackageName.clean(self.getUniqueString()) |
511 | + other_name = name + "WRONG" |
512 | + info1 = self.make_info(name) |
513 | + info2 = self.make_info(other_name) |
514 | + tempdir = self.useFixture(TempDir()).path |
515 | + backend1 = StaticBackend( |
516 | + self.getUniqueString(), 10, info1, expected_path=tempdir) |
517 | + backend2 = StaticBackend( |
518 | + self.getUniqueString(), 20, info2) |
519 | + self.useFixture(StaticLoaderFixture( |
520 | + [backend1, backend2])) |
521 | + write_packaging(tempdir, allowed_backend_names=[backend1.name]) |
522 | + self.assertThat(tempdir, ControlHasSourceName(name)) |
523 | + |
524 | + |
525 | +class TestWritePackagingInformation(TestCase): |
526 | + |
527 | + def test_writes_packaging(self): |
528 | + path = self.useFixture(TempDir()).path |
529 | + package_name = PackageName.clean(self.getUniqueString()) |
530 | + info = DictInfo( |
531 | + { |
532 | + PackageName.name: package_name, |
533 | + Maintainer.name: self.getUniqueString(), |
534 | + Architecture.name: "all", |
535 | + Description.name: self.getUniqueString(), |
536 | + Version.name: "1", |
537 | + }) |
538 | + write_packaging_info(path, info) |
539 | + self.assertThat(path, ControlHasSourceName(package_name)) |
540 | + |
541 | + |
542 | +class TestGetPackagingInfo(TestCase): |
543 | + |
544 | + def make_info(self): |
545 | + return DictInfo( |
546 | + { |
547 | + PackageName.name: PackageName.clean(self.getUniqueString()), |
548 | + Maintainer.name: self.getUniqueString(), |
549 | + Architecture.name: "all", |
550 | + Description.name: self.getUniqueString(), |
551 | + Version.name: "1", |
552 | + }) |
553 | + |
554 | + def test_get_packaging_info(self): |
555 | + info = self.make_info() |
556 | + tempdir = self.useFixture(TempDir()).path |
557 | + backend = StaticBackend( |
558 | + self.getUniqueString(), 10, info, expected_path=tempdir) |
559 | + self.useFixture(StaticLoaderFixture([backend])) |
560 | + found = get_packaging_info(tempdir) |
561 | + self.assertEqual(found, info) |
562 | + |
563 | + def test_allowed_backend_names(self): |
564 | + info1 = self.make_info() |
565 | + info2 = self.make_info() |
566 | + tempdir = self.useFixture(TempDir()).path |
567 | + backend1 = StaticBackend( |
568 | + self.getUniqueString(), 10, info1, expected_path=tempdir) |
569 | + backend2 = StaticBackend( |
570 | + self.getUniqueString(), 20, info2) |
571 | + self.useFixture(StaticLoaderFixture([backend1, backend2])) |
572 | + found = get_packaging_info( |
573 | + tempdir, allowed_backend_names=[backend1.name]) |
574 | + self.assertEqual(found, info1) |
575 | |
576 | === modified file 'pkgme/tests/test_script.py' |
577 | --- pkgme/tests/test_script.py 2012-08-06 13:26:01 +0000 |
578 | +++ pkgme/tests/test_script.py 2012-08-31 10:03:29 +0000 |
579 | @@ -14,18 +14,8 @@ |
580 | Not, |
581 | ) |
582 | |
583 | -from pkgme.backend import ( |
584 | - BackendSelector, |
585 | - StaticBackend, |
586 | - ) |
587 | from pkgme.bin.main import get_all_info |
588 | -from pkgme.info_elements import ( |
589 | - PackageName, |
590 | - ) |
591 | -from pkgme.project_info import DictInfo |
592 | -from pkgme.testing import ( |
593 | - TempdirFixture, |
594 | - ) |
595 | +from pkgme.testing import TempdirFixture |
596 | |
597 | |
598 | class ScriptTests(TestCase): |
599 | @@ -115,34 +105,3 @@ |
600 | sig_text = signature.readlines() |
601 | signature.close() |
602 | self.assertNotIn(sig_text, "-----BEGIN PGP SIGNATURE-----\n") |
603 | - |
604 | -class GetAllInfoTests(TestCase): |
605 | - |
606 | - def test_eligible_backends(self): |
607 | - info = DictInfo({}) |
608 | - backend1 = StaticBackend(self.getUniqueString(), 5, info) |
609 | - backend2 = StaticBackend(self.getUniqueString(), 10, info) |
610 | - selector = BackendSelector([backend1, backend2]) |
611 | - path = self.getUniqueString() |
612 | - info = get_all_info(path, selector) |
613 | - self.assertEqual( |
614 | - [(10, backend2.name), (5, backend1.name)], info['eligible_backends']) |
615 | - |
616 | - def test_selected_backend(self): |
617 | - info = DictInfo({}) |
618 | - backend1 = StaticBackend(self.getUniqueString(), 5, info) |
619 | - backend2 = StaticBackend(self.getUniqueString(), 10, info) |
620 | - selector = BackendSelector([backend1, backend2]) |
621 | - path = self.getUniqueString() |
622 | - info = get_all_info(path, selector) |
623 | - self.assertEqual(backend2.name, info['selected_backend']) |
624 | - |
625 | - def test_all_info(self): |
626 | - info = {PackageName.name: self.getUniqueString()} |
627 | - backend = StaticBackend(self.getUniqueString(), 5, DictInfo(info)) |
628 | - selector = BackendSelector([backend]) |
629 | - path = self.getUniqueString() |
630 | - all_info = get_all_info(path, selector) |
631 | - del all_info['eligible_backends'] |
632 | - del all_info['selected_backend'] |
633 | - self.assertEqual(info, all_info) |
634 | |
635 | === removed file 'pkgme/tests/test_write_packaging.py' |
636 | --- pkgme/tests/test_write_packaging.py 2012-08-29 16:07:33 +0000 |
637 | +++ pkgme/tests/test_write_packaging.py 1970-01-01 00:00:00 +0000 |
638 | @@ -1,123 +0,0 @@ |
639 | -import os |
640 | - |
641 | -from fixtures import TempDir |
642 | -from testtools import TestCase |
643 | -from treeshape import HasFileTree |
644 | - |
645 | -from pkgme import ( |
646 | - get_packaging_info, |
647 | - write_packaging, |
648 | - write_packaging_info, |
649 | - ) |
650 | -from pkgme.backend import StaticBackend |
651 | -from pkgme.info_elements import ( |
652 | - Architecture, |
653 | - Description, |
654 | - Maintainer, |
655 | - PackageName, |
656 | - Version, |
657 | - ) |
658 | -from pkgme.package_files import Control, DEBIAN_DIR |
659 | -from pkgme.project_info import DictInfo |
660 | -from pkgme.testing import ( |
661 | - ControlSourceStanzaHasField, |
662 | - StaticLoaderFixture, |
663 | - ) |
664 | - |
665 | - |
666 | -def ControlHasSourceName(name): |
667 | - control_path = os.path.join(DEBIAN_DIR, Control.filename) |
668 | - return HasFileTree( |
669 | - {control_path: |
670 | - {'content': ControlSourceStanzaHasField("Source", name)}}) |
671 | - |
672 | - |
673 | -class WritePackagingTests(TestCase): |
674 | - |
675 | - def make_info(self, name): |
676 | - info = DictInfo( |
677 | - { |
678 | - PackageName.name: name, |
679 | - Maintainer.name: self.getUniqueString(), |
680 | - Architecture.name: "all", |
681 | - Description.name: self.getUniqueString(), |
682 | - Version.name: "1", |
683 | - }) |
684 | - return info |
685 | - |
686 | - def test_write_packaging(self): |
687 | - name = PackageName.clean(self.getUniqueString()) |
688 | - info = self.make_info(name) |
689 | - tempdir = self.useFixture(TempDir()).path |
690 | - backend = StaticBackend( |
691 | - self.getUniqueString(), 10, info, expected_path=tempdir) |
692 | - self.useFixture(StaticLoaderFixture([backend])) |
693 | - write_packaging(tempdir) |
694 | - self.assertThat(tempdir, ControlHasSourceName(name)) |
695 | - |
696 | - def test_write_packaging_passes_allowed_backend_names(self): |
697 | - name = PackageName.clean(self.getUniqueString()) |
698 | - other_name = name + "WRONG" |
699 | - info1 = self.make_info(name) |
700 | - info2 = self.make_info(other_name) |
701 | - tempdir = self.useFixture(TempDir()).path |
702 | - backend1 = StaticBackend( |
703 | - self.getUniqueString(), 10, info1, expected_path=tempdir) |
704 | - backend2 = StaticBackend( |
705 | - self.getUniqueString(), 20, info2) |
706 | - self.useFixture(StaticLoaderFixture( |
707 | - [backend1, backend2])) |
708 | - write_packaging(tempdir, allowed_backend_names=[backend1.name]) |
709 | - self.assertThat(tempdir, ControlHasSourceName(name)) |
710 | - |
711 | - |
712 | -class TestWritePackagingInformation(TestCase): |
713 | - |
714 | - def test_writes_packaging(self): |
715 | - path = self.useFixture(TempDir()).path |
716 | - package_name = PackageName.clean(self.getUniqueString()) |
717 | - info = DictInfo( |
718 | - { |
719 | - PackageName.name: package_name, |
720 | - Maintainer.name: self.getUniqueString(), |
721 | - Architecture.name: "all", |
722 | - Description.name: self.getUniqueString(), |
723 | - Version.name: "1", |
724 | - }) |
725 | - write_packaging_info(path, info) |
726 | - self.assertThat(path, ControlHasSourceName(package_name)) |
727 | - |
728 | - |
729 | -class TestGetPackagingInfo(TestCase): |
730 | - |
731 | - def make_info(self): |
732 | - return DictInfo( |
733 | - { |
734 | - PackageName.name: PackageName.clean(self.getUniqueString()), |
735 | - Maintainer.name: self.getUniqueString(), |
736 | - Architecture.name: "all", |
737 | - Description.name: self.getUniqueString(), |
738 | - Version.name: "1", |
739 | - }) |
740 | - |
741 | - def test_get_packaging_info(self): |
742 | - info = self.make_info() |
743 | - tempdir = self.useFixture(TempDir()).path |
744 | - backend = StaticBackend( |
745 | - self.getUniqueString(), 10, info, expected_path=tempdir) |
746 | - self.useFixture(StaticLoaderFixture([backend])) |
747 | - found = get_packaging_info(tempdir) |
748 | - self.assertEqual(found, info) |
749 | - |
750 | - def test_allowed_backend_names(self): |
751 | - info1 = self.make_info() |
752 | - info2 = self.make_info() |
753 | - tempdir = self.useFixture(TempDir()).path |
754 | - backend1 = StaticBackend( |
755 | - self.getUniqueString(), 10, info1, expected_path=tempdir) |
756 | - backend2 = StaticBackend( |
757 | - self.getUniqueString(), 20, info2) |
758 | - self.useFixture(StaticLoaderFixture([backend1, backend2])) |
759 | - found = get_packaging_info( |
760 | - tempdir, allowed_backend_names=[backend1.name]) |
761 | - self.assertEqual(found, info1) |