Merge lp:~jml/pkgme-devportal/use-description into lp:pkgme-devportal

Proposed by Jonathan Lange
Status: Merged
Approved by: Jonathan Lange
Approved revision: 36
Merged at revision: 26
Proposed branch: lp:~jml/pkgme-devportal/use-description
Merge into: lp:pkgme-devportal
Diff against target: 536 lines (+213/-59)
13 files modified
acceptance/data/gtk/devportal-metadata.json (+2/-1)
devportalbinary/backends/binary/description (+19/-0)
devportalbinary/backends/binary/extra_files (+2/-3)
devportalbinary/backends/binary/package_name (+2/-4)
devportalbinary/backends/pdf/depends (+0/-2)
devportalbinary/backends/pdf/description (+2/-5)
devportalbinary/backends/pdf/extra_files (+2/-3)
devportalbinary/backends/pdf/package_name (+2/-4)
devportalbinary/binary.py (+25/-0)
devportalbinary/testing.py (+28/-0)
devportalbinary/tests/test_binary.py (+59/-4)
devportalbinary/tests/test_binary_backend.py (+65/-32)
devportalbinary/tests/test_database.py (+5/-1)
To merge this branch: bzr merge lp:~jml/pkgme-devportal/use-description
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+86224@code.launchpad.net

Commit message

Actually use the 'description' field from metadata to set the package description.

Description of the change

Simple branch to use the description field from the metadata.

Factors out a matcher to help with tests.

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

Hi,

Here's the things we spoke about on the phone:

17 + with open(METADATA_FILE) as f:
18 + metadata = json.load(f)
19 + print metadata[DESCRIPTION]

There should be a helper method to do that in devportalbinary.binary as it's repeated a lot.

Also, this should be the same for the pdf backend, which you added a card for.

The description needs specific formatting, but that should be done in pkgme.

135 -from sqlite3 import IntegrityError
136 +from pysqlite2.dbapi2 import IntegrityError

That doesn't work on my oneiric install, so I think we'll need at least try_import or similar.
However, sqlite3 is shipped in the python2.7 package here, so I'm not sure why you don't
have it on precise.

I think that only the last is a blocker.

Thanks,

James

review: Needs Fixing
Revision history for this message
Jonathan Lange (jml) wrote :

On Mon, Dec 19, 2011 at 7:51 PM, James Westby <email address hidden> wrote:
> Review: Needs Fixing
>
> Hi,
>
> Here's the things we spoke about on the phone:
>
> 17      + with open(METADATA_FILE) as f:
> 18      + metadata = json.load(f)
> 19      + print metadata[DESCRIPTION]
>
> There should be a helper method to do that in devportalbinary.binary as it's repeated a lot.
>
> Also, this should be the same for the pdf backend, which you added a card for.
>

I've added the helper method and made both backends use it. The card
can be for reducing the amount of shared code between the backends
now.

> The description needs specific formatting, but that should be done in pkgme.
>

Check.

> 135     -from sqlite3 import IntegrityError
> 136     +from pysqlite2.dbapi2 import IntegrityError
>
> That doesn't work on my oneiric install, so I think we'll need at least try_import or similar.
> However, sqlite3 is shipped in the python2.7 package here, so I'm not sure why you don't
> have it on precise.
>

It's not an import problem on precise. I have sqlite3. The problem is
that the IntegrityError raised by Storm is a different integrity error
on precise. Will find some sort of compatibility work-around.

> I think that only the last is a blocker.
>

Thanks,
jml

Revision history for this message
James Westby (james-w) wrote :

Looks great, thanks for the bonus clean-ups.

review: Approve
Revision history for this message
Canonical CA Tarmac (ca-tarmac) wrote :
Download full text (3.7 KiB)

The attempt to merge lp:~jml/pkgme-binary/use-description into lp:pkgme-binary failed. Below is the output from the failed tests.

Tests running...

Ran 68 tests in 10.906s
OK
Tests running...
======================================================================
ERROR: acceptance.tests.AcceptanceTests.test_gtk
----------------------------------------------------------------------
Traceback (most recent call last):
  File "acceptance/tests/__init__.py", line 57, in test_gtk
    self.run_pkgme(test_data)
  File "acceptance/tests/__init__.py", line 39, in run_pkgme
    test_data.path, allowed_backend_names=["binary"])
  File "/tmp/tmp4KAwG0/pkgme/pkgme/__init__.py", line 45, in write_packaging
    files = default_package_file_group.get_files(info)
  File "/tmp/tmp4KAwG0/pkgme/pkgme/package_files.py", line 93, in get_files
    values = project_info.get_all(keys)
  File "/tmp/tmp4KAwG0/pkgme/pkgme/project_info.py", line 90, in get_all
    values[key] = self._get(key)
  File "/tmp/tmp4KAwG0/pkgme/pkgme/project_info.py", line 79, in _get
    out = run_script(self.basepath, key, self.cwd)
  File "/tmp/tmp4KAwG0/pkgme/pkgme/run_script.py", line 100, in run_script
    output = run_subprocess([script_path], cwd=cwd, env=env, to_write=to_write)
  File "/tmp/tmp4KAwG0/pkgme/pkgme/run_script.py", line 84, in run_subprocess
    raise ScriptFailed(cmd, retcode, output)
ScriptFailed: /tmp/tmp4KAwG0/devportalbinary/backends/binary/description failed with returncode 1. Output:
 | Traceback (most recent call last):
 | File "/tmp/tmp4KAwG0/devportalbinary/backends/binary/description", line 17, in <module>
 | main()
 | File "/tmp/tmp4KAwG0/devportalbinary/backends/binary/description", line 13, in main
 | print get_metadata(DESCRIPTION)
 | File "/tmp/tmp4KAwG0/devportalbinary/binary.py", line 141, in get_metadata
 | return metadata[field_name]
 | KeyError: 'description'

Ran 3 tests in 3.053s
FAILED (failures=1)

Branched 93 revision(s).
/tmp/tmp4KAwG0/virtualenv/lib/python2.6/site-packages/distribute-0.6.10-py2.6.egg/setuptools/command/bdist_egg.py:422: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  symbols = dict.fromkeys(iter_symbols(code))
bzrlib/_readdir_pyx.c: In function '__pyx_f_6bzrlib_12_readdir_pyx__read_dir':
bzrlib/_readdir_pyx.c:992: warning: '__pyx_exc_lineno' may be used uninitialized in this function
bzrlib/_readdir_pyx.c:1035: warning: '__pyx_exc_lineno' may be used uninitialized in this function
bzrlib/_chk_map_pyx.c: In function '__pyx_f_6bzrlib_12_chk_map_pyx_safe_interned_string_from_size':
bzrlib/_chk_map_pyx.c:282: warning: cast from pointer to integer of different size
In file included from /usr/include/python2.6/Python.h:8,
                 from bzrlib/_patiencediff_c.c:28:
/usr/include/python2.6/pyconfig.h:1031:1: warning: "_POSIX_C_SOURCE" redefined
In file included from /usr/include/stdlib.h:25,
                 from bzrlib/_patiencediff_c.c:26:
/usr/include/features.h:210:1: warning: this is the location of the previous definition
bzrlib/_btree_serializer_pyx.c: In function '__pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size':
bzr...

Read more...

Revision history for this message
Canonical CA Tarmac (ca-tarmac) wrote :
Download full text (3.7 KiB)

The attempt to merge lp:~jml/pkgme-binary/use-description into lp:pkgme-binary failed. Below is the output from the failed tests.

Tests running...

Ran 68 tests in 6.038s
OK
Tests running...
======================================================================
ERROR: acceptance.tests.AcceptanceTests.test_gtk
----------------------------------------------------------------------
Traceback (most recent call last):
  File "acceptance/tests/__init__.py", line 57, in test_gtk
    self.run_pkgme(test_data)
  File "acceptance/tests/__init__.py", line 39, in run_pkgme
    test_data.path, allowed_backend_names=["binary"])
  File "/tmp/tmp9jChdC/pkgme/pkgme/__init__.py", line 45, in write_packaging
    files = default_package_file_group.get_files(info)
  File "/tmp/tmp9jChdC/pkgme/pkgme/package_files.py", line 93, in get_files
    values = project_info.get_all(keys)
  File "/tmp/tmp9jChdC/pkgme/pkgme/project_info.py", line 90, in get_all
    values[key] = self._get(key)
  File "/tmp/tmp9jChdC/pkgme/pkgme/project_info.py", line 79, in _get
    out = run_script(self.basepath, key, self.cwd)
  File "/tmp/tmp9jChdC/pkgme/pkgme/run_script.py", line 100, in run_script
    output = run_subprocess([script_path], cwd=cwd, env=env, to_write=to_write)
  File "/tmp/tmp9jChdC/pkgme/pkgme/run_script.py", line 84, in run_subprocess
    raise ScriptFailed(cmd, retcode, output)
ScriptFailed: /tmp/tmp9jChdC/devportalbinary/backends/binary/description failed with returncode 1. Output:
 | Traceback (most recent call last):
 | File "/tmp/tmp9jChdC/devportalbinary/backends/binary/description", line 17, in <module>
 | main()
 | File "/tmp/tmp9jChdC/devportalbinary/backends/binary/description", line 13, in main
 | print get_metadata(DESCRIPTION)
 | File "/tmp/tmp9jChdC/devportalbinary/binary.py", line 141, in get_metadata
 | return metadata[field_name]
 | KeyError: 'description'

Ran 3 tests in 3.862s
FAILED (failures=1)

Branched 93 revision(s).
/tmp/tmp9jChdC/virtualenv/lib/python2.6/site-packages/distribute-0.6.10-py2.6.egg/setuptools/command/bdist_egg.py:422: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  symbols = dict.fromkeys(iter_symbols(code))
bzrlib/_readdir_pyx.c: In function '__pyx_f_6bzrlib_12_readdir_pyx__read_dir':
bzrlib/_readdir_pyx.c:992: warning: '__pyx_exc_lineno' may be used uninitialized in this function
bzrlib/_readdir_pyx.c:1035: warning: '__pyx_exc_lineno' may be used uninitialized in this function
bzrlib/_chk_map_pyx.c: In function '__pyx_f_6bzrlib_12_chk_map_pyx_safe_interned_string_from_size':
bzrlib/_chk_map_pyx.c:282: warning: cast from pointer to integer of different size
In file included from /usr/include/python2.6/Python.h:8,
                 from bzrlib/_patiencediff_c.c:28:
/usr/include/python2.6/pyconfig.h:1031:1: warning: "_POSIX_C_SOURCE" redefined
In file included from /usr/include/stdlib.h:25,
                 from bzrlib/_patiencediff_c.c:26:
/usr/include/features.h:210:1: warning: this is the location of the previous definition
bzrlib/_btree_serializer_pyx.c: In function '__pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size':
bzrl...

Read more...

Revision history for this message
Canonical CA Tarmac (ca-tarmac) wrote :
Download full text (4.4 KiB)

The attempt to merge lp:~jml/pkgme-binary/use-description into lp:pkgme-binary failed. Below is the output from the failed tests.

Tests running...

Ran 71 tests in 6.028s
OK
Tests running...
======================================================================
ERROR: acceptance.tests.AcceptanceTests.test_gtk
----------------------------------------------------------------------
Traceback (most recent call last):
  File "acceptance/tests/__init__.py", line 57, in test_gtk
    self.run_pkgme(test_data)
  File "acceptance/tests/__init__.py", line 39, in run_pkgme
    test_data.path, allowed_backend_names=["binary"])
  File "/tmp/tmp7fjXSx/pkgme/pkgme/__init__.py", line 45, in write_packaging
    files = default_package_file_group.get_files(info)
  File "/tmp/tmp7fjXSx/pkgme/pkgme/package_files.py", line 93, in get_files
    values = project_info.get_all(keys)
  File "/tmp/tmp7fjXSx/pkgme/pkgme/project_info.py", line 90, in get_all
    values[key] = self._get(key)
  File "/tmp/tmp7fjXSx/pkgme/pkgme/project_info.py", line 79, in _get
    out = run_script(self.basepath, key, self.cwd)
  File "/tmp/tmp7fjXSx/pkgme/pkgme/run_script.py", line 100, in run_script
    output = run_subprocess([script_path], cwd=cwd, env=env, to_write=to_write)
  File "/tmp/tmp7fjXSx/pkgme/pkgme/run_script.py", line 84, in run_subprocess
    raise ScriptFailed(cmd, retcode, output)
ScriptFailed: /tmp/tmp7fjXSx/devportalbinary/backends/binary/extra_files failed with returncode 1. Output:
 | Traceback (most recent call last):
 | File "/tmp/tmp7fjXSx/devportalbinary/backends/binary/extra_files", line 37, in <module>
 | main()
 | File "/tmp/tmp7fjXSx/devportalbinary/backends/binary/extra_files", line 20, in main
 | metadata = get_metadata()
 | File "/tmp/tmp7fjXSx/devportalbinary/binary.py", line 141, in get_metadata
 | metadata = json.load(f)
 | File "/usr/lib/python2.6/json/__init__.py", line 267, in load
 | parse_constant=parse_constant, **kw)
 | File "/usr/lib/python2.6/json/__init__.py", line 307, in loads
 | return _default_decoder.decode(s)
 | File "/usr/lib/python2.6/json/decoder.py", line 319, in decode
 | obj, end = self.raw_decode(s, idx=_w(s, 0).end())
 | File "/usr/lib/python2.6/json/decoder.py", line 336, in raw_decode
 | obj, end = self._scanner.iterscan(s, **kw).next()
 | File "/usr/lib/python2.6/json/scanner.py", line 55, in iterscan
 | rval, next_pos = action(m, context)
 | File "/usr/lib/python2.6/json/decoder.py", line 193, in JSONObject
 | raise ValueError(errmsg("Expecting , delimiter", s, end - 1))
 | ValueError: Expecting , delimiter: line 3 column 5 (char 32)

Ran 3 tests in 3.777s
FAILED (failures=1)

Branched 93 revision(s).
/tmp/tmp7fjXSx/virtualenv/lib/python2.6/site-packages/distribute-0.6.10-py2.6.egg/setuptools/command/bdist_egg.py:422: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  symbols = dict.fromkeys(iter_symbols(code))
bzrlib/_readdir_pyx.c: In function '__pyx_f_6bzrlib_12_readdir_pyx__read_dir':
bzrlib/_readdir_pyx.c:992: warning: '__pyx_exc_lineno' may be used uninitialized in this function
bzrlib/_readdir...

Read more...

Revision history for this message
Canonical CA Tarmac (ca-tarmac) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'acceptance/data/gtk/devportal-metadata.json'
2--- acceptance/data/gtk/devportal-metadata.json 2011-11-15 17:27:30 +0000
3+++ acceptance/data/gtk/devportal-metadata.json 2011-12-20 19:38:24 +0000
4@@ -1,3 +1,4 @@
5 {
6- "package_name": "gtk"
7+ "package_name": "gtk",
8+ "description": "A trivial GTK+ program"
9 }
10
11=== added file 'devportalbinary/backends/binary/description'
12--- devportalbinary/backends/binary/description 1970-01-01 00:00:00 +0000
13+++ devportalbinary/backends/binary/description 2011-12-20 19:38:24 +0000
14@@ -0,0 +1,19 @@
15+#!/usr/bin/env python
16+# Copyright 2011 Canonical Ltd. This software is licensed under the
17+# GNU Affero General Public License version 3 (see the file LICENSE).
18+
19+import json
20+from devportalbinary.binary import (
21+ DESCRIPTION,
22+ get_metadata,
23+ )
24+
25+
26+def main():
27+ description = get_metadata(DESCRIPTION, None)
28+ if description:
29+ print description
30+
31+
32+if __name__ == '__main__':
33+ main()
34
35=== modified file 'devportalbinary/backends/binary/extra_files'
36--- devportalbinary/backends/binary/extra_files 2011-12-05 22:20:24 +0000
37+++ devportalbinary/backends/binary/extra_files 2011-12-20 19:38:24 +0000
38@@ -10,15 +10,14 @@
39 CATEGORIES,
40 get_binary_desktop_file,
41 get_install_file,
42- METADATA_FILE,
43+ get_metadata,
44 PACKAGE_NAME,
45 TAGLINE,
46 )
47
48
49 def main():
50- with open(METADATA_FILE) as f:
51- metadata = json.load(f)
52+ metadata = get_metadata()
53 package_name = metadata[PACKAGE_NAME]
54 path = os.getcwd()
55 install_file = get_install_file(package_name, path, True)
56
57=== modified file 'devportalbinary/backends/binary/package_name'
58--- devportalbinary/backends/binary/package_name 2011-11-21 16:16:36 +0000
59+++ devportalbinary/backends/binary/package_name 2011-12-20 19:38:24 +0000
60@@ -4,15 +4,13 @@
61
62 import json
63 from devportalbinary.binary import (
64- METADATA_FILE,
65+ get_metadata,
66 PACKAGE_NAME,
67 )
68
69
70 def main():
71- with open(METADATA_FILE) as f:
72- metadata = json.load(f)
73- print metadata[PACKAGE_NAME]
74+ print get_metadata(PACKAGE_NAME)
75
76
77 if __name__ == '__main__':
78
79=== modified file 'devportalbinary/backends/pdf/depends'
80--- devportalbinary/backends/pdf/depends 2011-12-05 22:20:24 +0000
81+++ devportalbinary/backends/pdf/depends 2011-12-20 19:38:24 +0000
82@@ -2,8 +2,6 @@
83 # Copyright 2011 Canonical Ltd. This software is licensed under the
84 # GNU Affero General Public License version 3 (see the file LICENSE).
85
86-from devportalbinary.binary import DEPENDS
87-
88
89 def main():
90 print 'xdg-utils, ${misc:Depends}'
91
92=== modified file 'devportalbinary/backends/pdf/description'
93--- devportalbinary/backends/pdf/description 2011-12-13 04:23:22 +0000
94+++ devportalbinary/backends/pdf/description 2011-12-20 19:38:24 +0000
95@@ -4,16 +4,13 @@
96
97 import json
98 from devportalbinary.binary import (
99- METADATA_FILE,
100+ get_metadata,
101 TAGLINE
102 )
103
104
105 def main():
106- with open(METADATA_FILE) as f:
107- metadata = json.load(f)
108- description = metadata[TAGLINE]
109- print description
110+ print get_metadata(TAGLINE)
111 # Not included in metadata yet.
112 #long_description = metadata["description"]
113 #lines = long_description.split("\n")
114
115=== modified file 'devportalbinary/backends/pdf/extra_files'
116--- devportalbinary/backends/pdf/extra_files 2011-12-13 04:23:22 +0000
117+++ devportalbinary/backends/pdf/extra_files 2011-12-20 19:38:24 +0000
118@@ -10,15 +10,14 @@
119 CATEGORIES,
120 get_pdf_desktop_file,
121 get_install_file,
122- METADATA_FILE,
123+ get_metadata,
124 PACKAGE_NAME,
125 TAGLINE,
126 )
127
128
129 def main():
130- with open(METADATA_FILE) as f:
131- metadata = json.load(f)
132+ metadata = get_metadata()
133 package_name = metadata[PACKAGE_NAME]
134 path = os.getcwd()
135 install_file = get_install_file(package_name, path, True)
136
137=== modified file 'devportalbinary/backends/pdf/package_name'
138--- devportalbinary/backends/pdf/package_name 2011-12-05 22:20:24 +0000
139+++ devportalbinary/backends/pdf/package_name 2011-12-20 19:38:24 +0000
140@@ -4,15 +4,13 @@
141
142 import json
143 from devportalbinary.binary import (
144- METADATA_FILE,
145+ get_metadata,
146 PACKAGE_NAME,
147 )
148
149
150 def main():
151- with open(METADATA_FILE) as f:
152- metadata = json.load(f)
153- print metadata[PACKAGE_NAME]
154+ print get_metadata(PACKAGE_NAME)
155
156
157 if __name__ == '__main__':
158
159=== modified file 'devportalbinary/binary.py'
160--- devportalbinary/binary.py 2011-12-13 12:53:41 +0000
161+++ devportalbinary/binary.py 2011-12-20 19:38:24 +0000
162@@ -38,6 +38,7 @@
163 ]
164
165
166+import json
167 import os
168 import subprocess
169
170@@ -61,8 +62,10 @@
171
172 METADATA_FILE = 'devportal-metadata.json'
173
174+# XXX: These duplicate the schema found in pkgme-service.
175 # Keys found in the metadata file.
176 CATEGORIES = 'categories'
177+DESCRIPTION = 'description'
178 # It's called package_name in the database, so this probably makes sense.
179 PACKAGE_NAME = 'package_name'
180 TAGLINE = 'tagline'
181@@ -122,6 +125,28 @@
182 yield os.path.relpath(file_path, path)
183
184
185+_no_field = object()
186+def get_metadata(field_name=None, default=_no_field, path=METADATA_FILE):
187+ """Return the value of ``field_name`` in metadata.
188+
189+ :param field_name: The field to look up. If None, then return all the
190+ metadata as a dict.
191+ :param default: If provided, then this value will be returned if
192+ 'field_name' is not present in the metadata.
193+ :param path: The path to the metadata file, if unspecified, look for
194+ METADATA_FILE in the current working directory.
195+ :return: The value of the field.
196+ """
197+ with open(path) as f:
198+ metadata = json.load(f)
199+ if field_name is None:
200+ return metadata
201+ value = metadata.get(field_name, default)
202+ if value is _no_field:
203+ raise KeyError(field_name)
204+ return value
205+
206+
207 def get_install_file(package_name, path, include_desktop=False):
208 """Generate the install file for 'package_name'."""
209 lines = []
210
211=== modified file 'devportalbinary/testing.py'
212--- devportalbinary/testing.py 2011-12-05 20:53:13 +0000
213+++ devportalbinary/testing.py 2011-12-20 19:38:24 +0000
214@@ -1,3 +1,4 @@
215+import json
216 import os
217
218 from fixtures import (
219@@ -6,6 +7,9 @@
220 TempDir,
221 )
222
223+from pkgme.testing import TempdirFixture
224+
225+from devportalbinary.binary import METADATA_FILE
226 from devportalbinary.database import PackageDatabase
227
228
229@@ -42,3 +46,27 @@
230 tempdir = self.useFixture(TempDir())
231 self.path = tempdir.path
232 self.useFixture(EnvironmentVariableFixture("HOME", self.path))
233+
234+
235+class MetadataFixture(Fixture):
236+ """Create a metadata file to use.
237+
238+ :ivar tempdir: The ``TempdirFixture`` used to create the temporary
239+ directory.
240+ :ivar path: The path to the directory containing the metadata file.
241+ """
242+
243+ def __init__(self, metadata):
244+ """Create a ``MetadataFixture``.
245+
246+ :param metadata: A dict of metadata.
247+ """
248+ self._metadata = metadata
249+
250+ def setUp(self):
251+ super(MetadataFixture, self).setUp()
252+ self.tempdir = self.useFixture(TempdirFixture())
253+ self.path = self.tempdir.path
254+ self.metadata_path = os.path.join(self.path, METADATA_FILE)
255+ with open(self.metadata_path, 'w') as fp:
256+ json.dump(self._metadata, fp)
257
258=== modified file 'devportalbinary/tests/test_binary.py'
259--- devportalbinary/tests/test_binary.py 2011-12-13 12:53:41 +0000
260+++ devportalbinary/tests/test_binary.py 2011-12-20 19:38:24 +0000
261@@ -17,6 +17,7 @@
262 get_file_type,
263 get_file_types,
264 get_install_file,
265+ get_metadata,
266 get_pdf_desktop_file,
267 get_shared_library_dependencies,
268 guess_dependencies,
269@@ -27,14 +28,68 @@
270 needed_libraries_from_objdump,
271 NoBinariesFound,
272 )
273-from devportalbinary.testing import DatabaseFixture
274-
275-
276-class BinaryTests(TestCase):
277+from devportalbinary.testing import (
278+ DatabaseFixture,
279+ MetadataFixture,
280+ )
281+
282+
283+class MetadataTests(TestCase):
284
285 def test_metadata_file(self):
286 self.assertEqual('devportal-metadata.json', METADATA_FILE)
287
288+ def test_get_metadata_field_present(self):
289+ # get_metadata returns the metadata value of the requested field.
290+ metadata = {
291+ 'foo': self.getUniqueString(),
292+ 'bar': self.getUniqueInteger(),
293+ }
294+ path = self.useFixture(MetadataFixture(metadata)).metadata_path
295+ foo = get_metadata('foo', path=path)
296+ self.assertEqual(metadata['foo'], foo)
297+
298+ def test_get_metadata_default_file(self):
299+ # By default, get_metadata looks for the METADATA_FILE in the current
300+ # working directory.
301+ metadata = {
302+ 'foo': self.getUniqueString(),
303+ 'bar': self.getUniqueInteger(),
304+ }
305+ path = self.useFixture(MetadataFixture(metadata)).path
306+ self.addCleanup(os.chdir, os.getcwd())
307+ os.chdir(path)
308+ foo = get_metadata('foo')
309+ self.assertEqual(metadata['foo'], foo)
310+
311+ def test_get_metadata_field_not_present_default_provided(self):
312+ # get_metadata returns the provided default value if the field is not
313+ # present in the metadata.
314+ metadata = {}
315+ path = self.useFixture(MetadataFixture(metadata)).metadata_path
316+ default = object()
317+ foo = get_metadata('foo', default, path=path)
318+ self.assertIs(default, foo)
319+
320+ def test_get_metadata_field_not_present_no_default(self):
321+ # get_metadata raises an exception if the field isn't there and no
322+ # default was provided.
323+ metadata = {}
324+ field = self.getUniqueString()
325+ path = self.useFixture(MetadataFixture(metadata)).metadata_path
326+ e = self.assertRaises(KeyError, get_metadata, field, path=path)
327+ self.assertEqual(repr(field), str(e))
328+
329+ def test_get_metadata_all_fields(self):
330+ # get_metadata returns the metadata value of the requested field.
331+ metadata = {
332+ 'foo': self.getUniqueString(),
333+ 'bar': self.getUniqueInteger(),
334+ }
335+ path = self.useFixture(MetadataFixture(metadata)).metadata_path
336+ found_metadata = get_metadata(path=path)
337+ self.assertEqual(metadata, found_metadata)
338+
339
340 class TestObjDump(TestCase):
341
342
343=== modified file 'devportalbinary/tests/test_binary_backend.py'
344--- devportalbinary/tests/test_binary_backend.py 2011-12-13 01:52:36 +0000
345+++ devportalbinary/tests/test_binary_backend.py 2011-12-20 19:38:24 +0000
346@@ -5,29 +5,36 @@
347 import os
348 import shutil
349
350-from fixtures import TestWithFixtures
351+from fixtures import TempDir
352 from testtools import TestCase
353+from testtools.matchers import (
354+ Equals,
355+ Matcher,
356+ )
357
358 from pkgme.backend import ExternalHelpersBackend, get_backend_dir
359 from pkgme.info_elements import (
360 BuildDepends,
361+ Description,
362 Depends,
363 ExtraFiles,
364 PackageName,
365 )
366-from pkgme.testing import TempdirFixture
367
368 from devportalbinary.binary import (
369 CATEGORIES,
370+ DESCRIPTION,
371 DEPENDS,
372 get_binary_desktop_file,
373 get_install_file,
374 guess_dependencies,
375- METADATA_FILE,
376 PACKAGE_NAME,
377 TAGLINE,
378 )
379-from devportalbinary.testing import DatabaseFixture
380+from devportalbinary.testing import (
381+ DatabaseFixture,
382+ MetadataFixture,
383+ )
384
385
386 BACKEND_NAME = 'binary'
387@@ -35,72 +42,98 @@
388 backend_dir = get_backend_dir(__file__, BACKEND_NAME)
389
390
391-class BinaryBackendTests(TestCase, TestWithFixtures):
392+class HasField(Matcher):
393+ """Matches if 'info' has a field with the given value."""
394+
395+ def __init__(self, field, field_value):
396+ super(HasField, self).__init__()
397+ self.field = field
398+ self.field_value = field_value
399+
400+ def match(self, info):
401+ return Equals(
402+ {self.field.name: self.field_value}).match(
403+ info.get_all([self.field.name]))
404+
405+
406+class BinaryBackendTests(TestCase):
407
408 def test_want_with_metadata(self):
409 # If we detect a binary, then we score 10. The way we determine if
410 # something is a binary is if it has a devportal-metadata.json in its
411 # top-level.
412- tempdir = self.useFixture(TempdirFixture())
413- tempdir.touch(METADATA_FILE)
414+ path = self.useFixture(MetadataFixture({})).path
415 backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir)
416- self.assertEqual(10, backend.want(tempdir.path))
417+ self.assertEqual(10, backend.want(path))
418
419 def test_want_without_metadata(self):
420 # If we do *not* detect a binary, then we score 0. The way we
421 # determine if something is a binary is if it has a
422 # devportal-metadata.json in its top-level.
423- tempdir = self.useFixture(TempdirFixture())
424+ tempdir = self.useFixture(TempDir())
425 backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir)
426 self.assertEqual(0, backend.want(tempdir.path))
427
428 def test_package_name(self):
429 # The binary backend gets the package name from the metadata file.
430- tempdir = self.useFixture(TempdirFixture())
431- tempdir.create_file(METADATA_FILE, json.dumps({PACKAGE_NAME: 'foo'}))
432- backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir)
433- info = backend.get_info(tempdir.path)
434- self.assertEqual(
435- {PackageName.name: "foo"}, info.get_all([PackageName.name]))
436+ path = self.useFixture(MetadataFixture({PACKAGE_NAME: 'foo'})).path
437+ backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir)
438+ info = backend.get_info(path)
439+ self.assertThat(info, HasField(PackageName, 'foo'))
440+
441+ def test_description(self):
442+ # The binary backend uses the package description that's in the
443+ # metadata.
444+ description = self.getUniqueString()
445+ path = self.useFixture(MetadataFixture({
446+ PACKAGE_NAME: 'foo',
447+ DESCRIPTION: description,
448+ })).path
449+ backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir)
450+ info = backend.get_info(path)
451+ self.assertThat(info, HasField(Description, description))
452+
453+ def test_no_description(self):
454+ # If no description is provided in the metadata then the description
455+ # in the package info is just an empty string.
456+ path = self.useFixture(MetadataFixture({PACKAGE_NAME: 'foo'})).path
457+ backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir)
458+ info = backend.get_info(path)
459+ self.assertThat(info, HasField(Description, ''))
460
461 def test_build_depends(self):
462 # Make sure there's a database.
463 self.useFixture(DatabaseFixture())
464- tempdir = self.useFixture(TempdirFixture())
465- tempdir.create_file(METADATA_FILE, json.dumps({PACKAGE_NAME: 'foo'}))
466+ path = self.useFixture(MetadataFixture({PACKAGE_NAME: 'foo'})).path
467 shutil.copy(
468 os.path.join(os.path.dirname(__file__), 'hello'),
469- tempdir.path)
470+ path)
471 backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir)
472- info = backend.get_info(tempdir.path)
473- deps = ', '.join(guess_dependencies(tempdir.path))
474- self.assertEqual(
475- {BuildDepends.name: deps}, info.get_all([BuildDepends.name]))
476+ info = backend.get_info(path)
477+ deps = ', '.join(guess_dependencies(path))
478+ self.assertThat(info, HasField(BuildDepends, deps))
479
480 def test_depends(self):
481- tempdir = self.useFixture(TempdirFixture())
482- tempdir.create_file(METADATA_FILE, json.dumps({PACKAGE_NAME: 'foo'}))
483+ path = self.useFixture(MetadataFixture({PACKAGE_NAME: 'foo'})).path
484 backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir)
485- info = backend.get_info(tempdir.path)
486- self.assertEqual({Depends.name: DEPENDS}, info.get_all([Depends.name]))
487+ info = backend.get_info(path)
488+ self.assertThat(info, HasField(Depends, DEPENDS))
489
490 def test_extra_files_install_file(self):
491 # We create an 'install' file that tells debhelper to just copy
492 # everything to opt.
493- tempdir = self.useFixture(TempdirFixture())
494 package_name = self.getUniqueString()
495- tempdir.create_file(METADATA_FILE, json.dumps({PACKAGE_NAME: package_name}))
496+ path = self.useFixture(MetadataFixture({PACKAGE_NAME: package_name})).path
497 backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir)
498- info = backend.get_info(tempdir.path)
499+ info = backend.get_info(path)
500 extra_files = info.get_all([ExtraFiles.name])[ExtraFiles.name]
501 install_file = json.loads(extra_files)['debian/install']
502 self.assertEqual(
503- get_install_file(package_name, tempdir.path, True),
504+ get_install_file(package_name, path, True),
505 install_file)
506
507 def test_extra_files_desktop_file(self):
508 # We create an 'desktop' file that launches the guessed binary
509- tempdir = self.useFixture(TempdirFixture())
510 package_name = self.getUniqueString()
511 tagline = self.getUniqueString()
512 categories = self.getUniqueString()
513@@ -109,7 +142,7 @@
514 TAGLINE: tagline,
515 CATEGORIES: categories,
516 }
517- tempdir.create_file(METADATA_FILE, json.dumps(metadata))
518+ tempdir = self.useFixture(MetadataFixture(metadata)).tempdir
519 # We need to create an executable in order to be able to generate a
520 # desktop.
521 tempdir.touch('executable', 0755)
522
523=== modified file 'devportalbinary/tests/test_database.py'
524--- devportalbinary/tests/test_database.py 2011-12-09 16:02:24 +0000
525+++ devportalbinary/tests/test_database.py 2011-12-20 19:38:24 +0000
526@@ -1,5 +1,9 @@
527 import os
528-from sqlite3 import IntegrityError
529+
530+from testtools import try_imports
531+
532+IntegrityError = try_imports(
533+ ['pysqlite2.dbapi2.IntegrityError', 'sqlite3.IntegrityError'])
534
535 from fixtures import (
536 EnvironmentVariableFixture,

Subscribers

People subscribed via source and target branches