Merge lp:~bjornt/launchpad/manuel into lp:launchpad

Proposed by Björn Tillenius
Status: Work in progress
Proposed branch: lp:~bjornt/launchpad/manuel
Merge into: lp:launchpad
Diff against target: 211 lines (+67/-24)
6 files modified
lib/canonical/launchpad/testing/systemdocs.py (+54/-15)
lib/canonical/launchpad/testing/tests/test_pages.py (+1/-1)
lib/canonical/launchpad/testing/tests/test_systemdocs.py (+5/-7)
lib/lp/bugs/browser/tests/buglinktarget-views.txt (+1/-1)
setup.py (+1/-0)
versions.cfg (+5/-0)
To merge this branch: bzr merge lp:~bjornt/launchpad/manuel
Reviewer Review Type Date Requested Status
Canonical Launchpad Engineering Pending
Review via email: mp+19083@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Björn Tillenius (bjornt) :

Unmerged revisions

10162. By Björn Tillenius

Merge RF.

10161. By Björn Tillenius

Merge RF.

10160. By Björn Tillenius

Revert changes to test.

10159. By Björn Tillenius

Provide more debug output in test.

10158. By Björn Tillenius

Possible fix for possible test failure.

10157. By Björn Tillenius

Merge RF.

10156. By Björn Tillenius

We don't need to monkeypatch to use our TestClass class.

10155. By Björn Tillenius

Use r85 of manuel branch.

10154. By Björn Tillenius

Use a fixed version of Manuel.

10153. By Björn Tillenius

Fix librarianformatter_noca.txt.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/testing/systemdocs.py'
2--- lib/canonical/launchpad/testing/systemdocs.py 2009-10-15 11:47:32 +0000
3+++ lib/canonical/launchpad/testing/systemdocs.py 2010-02-11 09:45:36 +0000
4@@ -19,11 +19,14 @@
5 import pprint
6 import sys
7
8+import manuel.doctest
9+import manuel.testing
10 import transaction
11 from zope.component import getUtility
12 from zope.testing import doctest
13 from zope.testing.loggingsupport import Handler
14
15+
16 from canonical.chunkydiff import elided_source
17 from canonical.config import config
18 from canonical.database.sqlbase import flush_database_updates
19@@ -52,17 +55,20 @@
20 return path
21
22
23-class FilePrefixStrippingDocTestParser(doctest.DocTestParser):
24- """A DocTestParser that strips a prefix from doctests."""
25- def get_doctest(self, string, globs, name, filename, lineno,
26- optionflags=0):
27- filename = strip_prefix(filename)
28- return doctest.DocTestParser.get_doctest(
29- self, string, globs, name, filename, lineno,
30- optionflags=optionflags)
31-
32-
33-default_parser = FilePrefixStrippingDocTestParser()
34+class FilePrefixStrippingTestCase(manuel.testing.TestCase):
35+
36+ def setUp(self):
37+ self.globs['__file__'] = self.regions.location
38+ super(FilePrefixStrippingTestCase, self).setUp()
39+
40+ def shortDescription(self):
41+ short_desc = super(
42+ FilePrefixStrippingTestCase, self).shortDescription()
43+ if short_desc.startswith('/'):
44+ short_desc = strip_prefix(short_desc)
45+ return short_desc
46+
47+ __str__ = __repr__ = id = shortDescription
48
49
50 class StdoutHandler(Handler):
51@@ -78,7 +84,20 @@
52 record.levelname, record.name, self.format(record))
53
54
55-def LayeredDocFileSuite(*args, **kw):
56+def get_manuel_instance(optionflags=None, checker=None,
57+ extra_manuel_plugins=None):
58+ """Set up a Manuel instance used for all doctests and return it."""
59+ manuel_instance = manuel.doctest.Manuel(
60+ optionflags=optionflags,
61+ checker=checker)
62+ if extra_manuel_plugins is None:
63+ extra_manuel_plugins = []
64+ for manuel_plugin in extra_manuel_plugins:
65+ manuel_instance += manuel_plugin
66+ return manuel_instance
67+
68+
69+def LayeredDocFileSuite(*paths, **kw):
70 """Create a DocFileSuite, optionally applying a layer to it.
71
72 In addition to the standard DocFileSuite arguments, the following
73@@ -89,12 +108,13 @@
74 :param stdout_logging_level: The logging level for the above.
75 :param layer: A Zope test runner layer to apply to the tests (by
76 default no layer is applied).
77+ :param extra_manuel_plugins: A list of extra Manuel plugins to use,
78+ in addition to manuel.doctest.Manuel.
79 """
80 kw.setdefault('optionflags', default_optionflags)
81- kw.setdefault('parser', default_parser)
82
83 # Make sure that paths are resolved relative to our caller
84- kw['package'] = doctest._normalize_module(kw.get('package'))
85+ package = doctest._normalize_module(kw.pop('package', None))
86
87 # Set stdout_logging keyword argument to True to make
88 # logging output be sent to stdout, forcing doctests to deal with it.
89@@ -123,7 +143,26 @@
90 kw['tearDown'] = tearDown
91
92 layer = kw.pop('layer', None)
93- suite = doctest.DocFileSuite(*args, **kw)
94+ normalized_paths = []
95+ for path in paths:
96+ if not path.startswith('/'):
97+ path = os.path.join(os.path.dirname(package.__file__), path)
98+ normalized_paths.append(path)
99+ kw['TestCase'] = FilePrefixStrippingTestCase
100+ # Make manuel use zope's doctest, which has a fixed _SpoofOut.write
101+ # that encodes the input using utf-8. Without this, tests that write
102+ # non-ascii output fail.
103+ manuel.doctest.doctest = doctest
104+ doctest_optionflags = kw.pop('optionflags', None)
105+ suite = manuel.testing.TestSuite(
106+ get_manuel_instance(
107+ optionflags=doctest_optionflags,
108+ checker=kw.pop('checker', None),
109+ extra_manuel_plugins=kw.pop('extra_manuel_plugins', None)),
110+ *normalized_paths, **kw)
111+ # Store the doctest flags on the suite, so that tests can make sure
112+ # which option flags were used.
113+ suite.doctest_optionflags = doctest_optionflags
114 if layer is not None:
115 suite.layer = layer
116 return suite
117
118=== modified file 'lib/canonical/launchpad/testing/tests/test_pages.py'
119--- lib/canonical/launchpad/testing/tests/test_pages.py 2009-06-25 05:30:52 +0000
120+++ lib/canonical/launchpad/testing/tests/test_pages.py 2010-02-11 09:45:36 +0000
121@@ -42,7 +42,7 @@
122 [bar_test, story] = list(suite)
123
124 # The unnumbered file appears as an independent test.
125- self.assertEqual(os.path.basename(bar_test.id()), 'xx-bar_txt')
126+ self.assertEqual(os.path.basename(bar_test.id()), 'xx-bar.txt')
127
128 # The two numbered tests become a story, which appears as a
129 # single test case rather than a test suite.
130
131=== modified file 'lib/canonical/launchpad/testing/tests/test_systemdocs.py'
132--- lib/canonical/launchpad/testing/tests/test_systemdocs.py 2009-06-25 05:30:52 +0000
133+++ lib/canonical/launchpad/testing/tests/test_systemdocs.py 2010-02-11 09:45:36 +0000
134@@ -60,9 +60,9 @@
135
136 [foo_test, bar_test] = list(suite)
137 self.assertTrue(isinstance(foo_test, unittest.TestCase))
138- self.assertEqual(os.path.basename(foo_test.id()), 'foo_txt')
139+ self.assertEqual(os.path.basename(foo_test.id()), 'foo.txt')
140 self.assertTrue(isinstance(bar_test, unittest.TestCase))
141- self.assertEqual(os.path.basename(bar_test.id()), 'bar_txt')
142+ self.assertEqual(os.path.basename(bar_test.id()), 'bar.txt')
143 self.runSuite(suite, num_tests=2)
144
145 def test_set_layer(self):
146@@ -107,13 +107,11 @@
147 self.makeTestFile('foo.txt')
148 base = os.path.basename(self.tempdir)
149 suite = LayeredDocFileSuite(os.path.join(base, 'foo.txt'))
150- [foo_test] = list(suite)
151- self.assertEqual(foo_test._dt_optionflags, default_optionflags)
152+ self.assertEqual(suite.doctest_optionflags, default_optionflags)
153 # If the optionflags argument is passed, it takes precedence:
154 suite = LayeredDocFileSuite(
155 os.path.join(base, 'foo.txt'), optionflags=doctest.ELLIPSIS)
156- [foo_test] = list(suite)
157- self.assertEqual(foo_test._dt_optionflags, doctest.ELLIPSIS)
158+ self.assertEqual(suite.doctest_optionflags, doctest.ELLIPSIS)
159
160 def test_strip_prefix(self):
161 """The Launchpad tree root is stripped from test names."""
162@@ -126,7 +124,7 @@
163 [foo_test] = list(suite)
164 # The test ID and string representation have the prefix
165 # stripped off.
166- self.assertEqual(foo_test.id(), 'foo_txt')
167+ self.assertEqual(foo_test.id(), 'foo.txt')
168 self.assertEqual(str(foo_test), 'foo.txt')
169 # Tests outside of the Launchpad tree root are left as is:
170 config.root = '/nonexistent'
171
172=== modified file 'lib/lp/bugs/browser/tests/buglinktarget-views.txt'
173--- lib/lp/bugs/browser/tests/buglinktarget-views.txt 2009-11-07 23:51:59 +0000
174+++ lib/lp/bugs/browser/tests/buglinktarget-views.txt 2010-02-11 09:45:36 +0000
175@@ -142,7 +142,7 @@
176 The notification contains the escaped bug title.
177
178 >>> for notification in request.response.notifications:
179- ... print notification.message.encode('utf8')
180+ ... print notification.message
181 Added link to bug #2:
182 ...<script>window.alert("Hello!")</script>....
183
184
185=== modified file 'setup.py'
186--- setup.py 2010-01-20 22:09:26 +0000
187+++ setup.py 2010-02-11 09:45:36 +0000
188@@ -42,6 +42,7 @@
189 'lazr.testing',
190 'lazr.uri',
191 'lazr-js',
192+ 'manuel',
193 'mechanize',
194 'mercurial',
195 'mocker',
196
197=== modified file 'versions.cfg'
198--- versions.cfg 2010-02-04 00:29:49 +0000
199+++ versions.cfg 2010-02-11 09:45:36 +0000
200@@ -35,6 +35,11 @@
201 lazr.testing = 0.1.1
202 lazr.uri = 1.0.2
203 lazr-js = 0.9.2
204+# r85 of lp:~bjornt/manuel/launchpad. It includes our patches to allow
205+# custom TestCase classes to be used, and not having it break when
206+# testing empty documents. Both patches have been submitted upstream,
207+# and should be in the next release.
208+manuel = 1.0.4-lp-r85
209 martian = 0.11
210 mechanize = 0.1.11
211 mercurial = 1.3.1