Merge lp:~jml/pkgme/more-information into lp:pkgme

Proposed by Jonathan Lange
Status: Merged
Approved by: James Westby
Approved revision: 83
Merged at revision: 81
Proposed branch: lp:~jml/pkgme/more-information
Merge into: lp:pkgme
Diff against target: 292 lines (+114/-21)
7 files modified
pkgme/backend.py (+16/-0)
pkgme/bin/main.py (+22/-2)
pkgme/testing.py (+24/-0)
pkgme/tests/__init__.py (+1/-0)
pkgme/tests/test_backend.py (+17/-6)
pkgme/tests/test_main.py (+30/-0)
pkgme/tests/test_write_packaging.py (+4/-13)
To merge this branch: bzr merge lp:~jml/pkgme/more-information
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+80497@code.launchpad.net

Description of the change

Changes the --version option to dump more information about backends and where they come from, but only when the --debug option is also specified.

 * Extracts out a get_version_info function
 * Adds tests for it
 * Creates a StaticLoaderFixture so it's easier for tests to change which backends get loaded
 * Adds a describe() method to Backend and gives it an implementation for the base class and ExternalHelperBackend
 * Random docstring additions

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pkgme/backend.py'
2--- pkgme/backend.py 2011-10-26 18:30:07 +0000
3+++ pkgme/backend.py 2011-10-26 19:32:27 +0000
4@@ -98,6 +98,9 @@
5 def __init__(self, name):
6 self.name = name
7
8+ def describe(self):
9+ return self.name
10+
11 def want(self, path):
12 raise NotImplementedError(self.want)
13
14@@ -113,6 +116,9 @@
15 super(ExternalHelpersBackend, self).__init__(name)
16 self.basepath = basepath
17
18+ def describe(self):
19+ return "%s (%s)" % (self.name, self.basepath)
20+
21 def want(self, path):
22 try:
23 out = run_script(self.basepath, self.WANT_SCRIPT_NAME, path)
24@@ -143,6 +149,16 @@
25 class StaticBackend(Backend):
26
27 def __init__(self, name, score, info, expected_path=None):
28+ """Create a StaticBackend.
29+
30+ :param name: The name of the backend.
31+ :param score: A fixed score always returned in response to a 'want'
32+ call. (But see expected_path).
33+ :param info: A fixed dict of packaging information always returned in
34+ response to a 'want' call. (But see expected_path).
35+ :expected_path: If provided, then only return 'score' and 'info' if
36+ the backend is being called for this path.
37+ """
38 super(StaticBackend, self).__init__(name)
39 self.score = score
40 self.info = info
41
42=== modified file 'pkgme/bin/main.py'
43--- pkgme/bin/main.py 2011-08-11 08:54:56 +0000
44+++ pkgme/bin/main.py 2011-10-26 19:32:27 +0000
45@@ -5,6 +5,10 @@
46 import sys
47
48 from pkgme import __version__, write_packaging
49+from pkgme.backend import (
50+ EXTERNAL_BACKEND_PATHS,
51+ get_default_loader,
52+ )
53 from pkgme.debuild import build_source_package
54 from pkgme.upload import (
55 InvalidPPAName,
56@@ -39,8 +43,7 @@
57 parser = argparse.ArgumentParser(
58 description='pkgme - A Debian packaging generation framework.')
59 parser.add_argument(
60- '-v', '--version',
61- action='version', version='pkgme {0}'.format(__version__),
62+ '-v', '--version', action='store_true',
63 help='Print this version string and exit')
64 parser.add_argument('-D', '--debug', action='store_true')
65 parser.add_argument(
66@@ -52,11 +55,28 @@
67 return parser
68
69
70+def get_version_info(debug=False):
71+ version = 'pkgme %s' % (__version__,)
72+ if debug:
73+ ls = [version, '']
74+ ls.append('Backend paths: %s' % ', '.join(map(repr, EXTERNAL_BACKEND_PATHS)))
75+ ls.append("Available backends:")
76+ loader = get_default_loader()
77+ backends = loader.load()
78+ for backend in backends:
79+ ls.append(" %s" % backend.describe())
80+ version = '\n'.join(ls)
81+ return version
82+
83+
84 def main(argv=None, target_dir=None, interactive=True):
85 if argv is None:
86 argv = sys.argv[1:]
87 parser = make_arg_parser()
88 options = parser.parse_args(args=argv)
89+ if options.version:
90+ print get_version_info(options.debug)
91+ return 0
92 if options.debug:
93 trace.set_debug()
94 if target_dir is None:
95
96=== modified file 'pkgme/testing.py'
97--- pkgme/testing.py 2011-07-29 17:07:54 +0000
98+++ pkgme/testing.py 2011-10-26 19:32:27 +0000
99@@ -14,6 +14,11 @@
100 MismatchesAll,
101 )
102
103+from pkgme.backend import (
104+ StaticLoader,
105+ set_default_loader_factory,
106+ reset_default_loader_factory,
107+ )
108 from pkgme.write import write_file
109
110
111@@ -301,3 +306,22 @@
112 find_error = require_command(command_name)
113 if find_error is not None:
114 self.skipTest("'%s' not executable: %s" % (command_name, find_error))
115+
116+
117+class StaticLoaderFixture(Fixture):
118+ """Change the default loader to one that only loads the given backends."""
119+
120+ def __init__(self, backends):
121+ """Construct a ``StaticLoaderFixture``.
122+
123+ :param backends: A list of backends for the loader to load.
124+ """
125+ self.backends = backends
126+
127+ def setUp(self):
128+ super(StaticLoaderFixture, self).setUp()
129+ self.addCleanup(reset_default_loader_factory)
130+ set_default_loader_factory(self.make_loader)
131+
132+ def make_loader(self):
133+ return StaticLoader(self.backends)
134
135=== modified file 'pkgme/tests/__init__.py'
136--- pkgme/tests/__init__.py 2011-08-10 10:51:10 +0000
137+++ pkgme/tests/__init__.py 2011-10-26 19:32:27 +0000
138@@ -9,6 +9,7 @@
139 'pkgme.tests.test_backend',
140 'pkgme.tests.test_distutils_command',
141 'pkgme.tests.test_info_elements',
142+ 'pkgme.tests.test_main',
143 'pkgme.tests.test_package_files',
144 'pkgme.tests.test_project_info',
145 'pkgme.tests.test_python_backend',
146
147=== modified file 'pkgme/tests/test_backend.py'
148--- pkgme/tests/test_backend.py 2011-10-26 18:22:49 +0000
149+++ pkgme/tests/test_backend.py 2011-10-26 19:32:27 +0000
150@@ -5,6 +5,7 @@
151 from testtools import TestCase
152
153 from pkgme.backend import (
154+ Backend,
155 BackendSelector,
156 EXTERNAL_BACKEND_PATHS,
157 ExternalHelpersBackend,
158@@ -14,8 +15,6 @@
159 get_info_for,
160 NoBackend,
161 NoEligibleBackend,
162- reset_default_loader_factory,
163- set_default_loader_factory,
164 StaticBackend,
165 StaticLoader,
166 )
167@@ -25,10 +24,19 @@
168 )
169 from pkgme.testing import (
170 ExecutableFileFixture,
171+ StaticLoaderFixture,
172 TempdirFixture,
173 )
174
175
176+class TestBackend(TestCase):
177+
178+ def test_describe(self):
179+ # The default describe() just returns the name.
180+ backend = Backend(self.getUniqueString())
181+ self.assertEqual(backend.name, backend.describe())
182+
183+
184 class ExternalHelpersBackendTests(TestCase, TestWithFixtures):
185
186 def make_want_script(self, script):
187@@ -38,6 +46,12 @@
188 self.useFixture(ExecutableFileFixture(script_path, script))
189 return tempdir
190
191+ def test_describe(self):
192+ backend = ExternalHelpersBackend(
193+ self.getUniqueString(), self.getUniqueString())
194+ self.assertEqual(
195+ "%s (%s)" % (backend.name, backend.basepath), backend.describe())
196+
197 def test_want_runs_script(self):
198 script = "#!/bin/sh\necho 10\n"
199 tempdir = self.make_want_script(script)
200@@ -255,8 +269,5 @@
201 path = self.getUniqueString()
202 backend = StaticBackend(
203 self.getUniqueString(), 10, info, expected_path=path)
204- def make_loader():
205- return StaticLoader([backend])
206- self.addCleanup(reset_default_loader_factory)
207- set_default_loader_factory(make_loader)
208+ self.useFixture(StaticLoaderFixture([backend]))
209 self.assertEqual(info, get_info_for(path))
210
211=== added file 'pkgme/tests/test_main.py'
212--- pkgme/tests/test_main.py 1970-01-01 00:00:00 +0000
213+++ pkgme/tests/test_main.py 2011-10-26 19:32:27 +0000
214@@ -0,0 +1,30 @@
215+from testtools import TestCase
216+
217+from pkgme import __version__
218+from pkgme.backend import (
219+ EXTERNAL_BACKEND_PATHS,
220+ StaticBackend,
221+ )
222+from pkgme.bin.main import get_version_info
223+from pkgme.testing import StaticLoaderFixture
224+
225+class TestVersionInfo(TestCase):
226+
227+ def test_version_info(self):
228+ x = get_version_info()
229+ self.assertEqual("pkgme %s" % (__version__,), x)
230+
231+ def test_debug_version_info(self):
232+ backends = [StaticBackend(self.getUniqueString(), 0, {})]
233+ self.useFixture(StaticLoaderFixture(backends))
234+ x = get_version_info(debug=True)
235+ expected_backends = '\n'.join(" %s" % b.describe() for b in backends)
236+ expected = """pkgme %s
237+
238+Backend paths: %s
239+Available backends:
240+%s""" % (
241+ __version__,
242+ ', '.join(map(repr, EXTERNAL_BACKEND_PATHS)),
243+ expected_backends)
244+ self.assertEqual(expected, x)
245
246=== modified file 'pkgme/tests/test_write_packaging.py'
247--- pkgme/tests/test_write_packaging.py 2011-06-15 18:53:17 +0000
248+++ pkgme/tests/test_write_packaging.py 2011-10-26 19:32:27 +0000
249@@ -1,15 +1,9 @@
250 import os
251
252-from fixtures import TestWithFixtures
253 from testtools import TestCase
254
255 from pkgme import write_packaging
256-from pkgme.backend import (
257- reset_default_loader_factory,
258- set_default_loader_factory,
259- StaticBackend,
260- StaticLoader,
261- )
262+from pkgme.backend import StaticBackend
263 from pkgme.info_elements import (
264 Architecture,
265 Description,
266@@ -21,11 +15,12 @@
267 from pkgme.project_info import DictInfo
268 from pkgme.testing import (
269 ControlSourceStanzaHasField,
270+ StaticLoaderFixture,
271 TempdirFixture,
272 )
273
274
275-class WritePackagingTests(TestCase, TestWithFixtures):
276+class WritePackagingTests(TestCase):
277
278 def test_write_packaging(self):
279 name = self.getUniqueString()
280@@ -40,11 +35,7 @@
281 tempdir = self.useFixture(TempdirFixture())
282 backend = StaticBackend(
283 self.getUniqueString(), 10, info, expected_path=tempdir.path)
284- loader = StaticLoader([backend])
285- def get_loader():
286- return loader
287- self.addCleanup(reset_default_loader_factory)
288- set_default_loader_factory(get_loader)
289+ self.useFixture(StaticLoaderFixture([backend]))
290 write_packaging(tempdir.path)
291 control_path = os.path.join(
292 tempdir.path, DEBIAN_DIR, Control.filename)

Subscribers

People subscribed via source and target branches