Merge lp:~elopio/u1-test-utils/static-tests into lp:u1-test-utils

Proposed by Leo Arias
Status: Merged
Approved by: Natalia Bidart
Approved revision: 22
Merged at revision: 16
Proposed branch: lp:~elopio/u1-test-utils/static-tests
Merge into: lp:u1-test-utils
Diff against target: 330 lines (+182/-19)
8 files modified
u1testutils/__init__.py (+1/-1)
u1testutils/django.py (+0/-2)
u1testutils/logging.py (+0/-1)
u1testutils/selftests/test_static_code_analysis.py (+34/-0)
u1testutils/sst/mail.py (+4/-4)
u1testutils/static/test_pep8_conformance.py (+56/-0)
u1testutils/static/test_pyflakes_analysis.py (+73/-0)
u1testutils/wsgi_intercept.py (+14/-11)
To merge this branch: bzr merge lp:~elopio/u1-test-utils/static-tests
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Ricardo Kirkner (community) Approve
Review via email: mp+137923@code.launchpad.net

Commit message

Added the tests for pep8 conformance and pyflakes analysis to static test utils.
Added the selftests for static code analysis.

Description of the change

Added the test pep8 conformance to static test utils.

To run the selftests:
python -m unittest discover u1testutils/selftests

To post a comment you must log in.
17. By Leo Arias

Fixed the pyflakes test.

18. By Leo Arias

Added the static code analysis self tests.

19. By Leo Arias

Fixed pep8 errors.

20. By Leo Arias

Bumped the version.

21. By Leo Arias

Started the analysis from the top package and fixed errors.

22. By Leo Arias

Cleaned a little.

Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

Looks good enough to me

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks pretty good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'u1testutils/__init__.py'
2--- u1testutils/__init__.py 2012-10-30 16:31:44 +0000
3+++ u1testutils/__init__.py 2012-12-04 20:07:23 +0000
4@@ -1,1 +1,1 @@
5-__version__ = '0.1'
6+__version__ = '0.2'
7
8=== modified file 'u1testutils/django.py'
9--- u1testutils/django.py 2011-10-24 12:34:32 +0000
10+++ u1testutils/django.py 2012-12-04 20:07:23 +0000
11@@ -79,5 +79,3 @@
12 result &= int(v) > 0
13 break
14 return result
15-
16-
17
18=== modified file 'u1testutils/logging.py'
19--- u1testutils/logging.py 2011-02-08 14:03:09 +0000
20+++ u1testutils/logging.py 2012-12-04 20:07:23 +0000
21@@ -48,4 +48,3 @@
22 # XXX michaeln 2010-08-18 Convert this to use testtools matchers
23 # for much better failure output.
24 self.assertTrue(self.memento_handler.check(level, message))
25-
26
27=== added directory 'u1testutils/selftests'
28=== added file 'u1testutils/selftests/__init__.py'
29=== added file 'u1testutils/selftests/test_static_code_analysis.py'
30--- u1testutils/selftests/test_static_code_analysis.py 1970-01-01 00:00:00 +0000
31+++ u1testutils/selftests/test_static_code_analysis.py 2012-12-04 20:07:23 +0000
32@@ -0,0 +1,34 @@
33+# -*- coding: utf-8 -*-
34+
35+# Copyright 2012 Canonical Ltd.
36+#
37+# This program is free software: you can redistribute it and/or modify it
38+# under the terms of the GNU Lesser General Public License version 3, as
39+# published by the Free Software Foundation.
40+#
41+# This program is distributed in the hope that it will be useful, but
42+# WITHOUT ANY WARRANTY; without even the implied warranties of
43+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
44+# PURPOSE. See the GNU Lesser General Public License for more details.
45+#
46+# You should have received a copy of the GNU General Public License along
47+# with this program. If not, see <http://www.gnu.org/licenses/>.
48+
49+import u1testutils
50+
51+from u1testutils.static import (
52+ test_pep8_conformance,
53+ test_pyflakes_analysis,
54+)
55+
56+
57+class Pep8ConformanceTestCase(
58+ test_pep8_conformance.Pep8ConformanceTestCase):
59+
60+ packages = [u1testutils]
61+
62+
63+class PyflakesAnalysisTestCase(
64+ test_pyflakes_analysis.PyflakesAnalysisTestCase):
65+
66+ packages = [u1testutils]
67
68=== modified file 'u1testutils/sst/mail.py'
69--- u1testutils/sst/mail.py 2012-06-29 11:43:54 +0000
70+++ u1testutils/sst/mail.py 2012-12-04 20:07:23 +0000
71@@ -18,10 +18,10 @@
72 self.password = password
73 if settings.IMAP_USE_SSL:
74 self.imap = imaplib.IMAP4_SSL(
75- settings.IMAP_SERVER, settings.IMAP_PORT)
76+ settings.IMAP_SERVER, settings.IMAP_PORT)
77 else:
78 self.imap = imaplib.IMAP4(
79- settings.IMAP_SERVER, settings.IMAP_PORT)
80+ settings.IMAP_SERVER, settings.IMAP_PORT)
81
82 def __enter__(self):
83 self.imap.login(self.user, self.password)
84@@ -82,7 +82,8 @@
85 time.sleep(poll)
86
87 raise AssertionError("No email sent to '%s' found in inbox "
88- "after polling for %s seconds." % (email_address, timeout))
89+ "after polling for %s seconds." %
90+ (email_address, timeout))
91
92 def delete_msgs_sent_to(self, email_address):
93 self.imap.select('Inbox')
94@@ -112,4 +113,3 @@
95
96 def email_body_includes(email_msg, text):
97 assert text in email_msg.get_payload(), "'%s' was not in email body."
98-
99
100=== added directory 'u1testutils/static'
101=== added file 'u1testutils/static/__init__.py'
102=== added file 'u1testutils/static/test_pep8_conformance.py'
103--- u1testutils/static/test_pep8_conformance.py 1970-01-01 00:00:00 +0000
104+++ u1testutils/static/test_pep8_conformance.py 2012-12-04 20:07:23 +0000
105@@ -0,0 +1,56 @@
106+# -*- coding: utf-8 -*-
107+
108+# Copyright 2012 Canonical Ltd.
109+#
110+# This program is free software: you can redistribute it and/or modify it
111+# under the terms of the GNU Lesser General Public License version 3, as
112+# published by the Free Software Foundation.
113+#
114+# This program is distributed in the hope that it will be useful, but
115+# WITHOUT ANY WARRANTY; without even the implied warranties of
116+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
117+# PURPOSE. See the GNU Lesser General Public License for more details.
118+#
119+# You should have received a copy of the GNU General Public License along
120+# with this program. If not, see <http://www.gnu.org/licenses/>.
121+
122+import os
123+import pep8
124+import unittest
125+from collections import defaultdict
126+
127+
128+class Pep8ConformanceTestCase(unittest.TestCase):
129+
130+ packages = []
131+ exclude = []
132+
133+ def message(self, text):
134+ self.errors.append(text)
135+
136+ def setUp(self):
137+ self.errors = {}
138+ self.pep8style = pep8.StyleGuide(
139+ counters=defaultdict(int),
140+ doctest='',
141+ exclude=self.exclude,
142+ filename=['*.py'],
143+ ignore=[],
144+ messages=self.errors,
145+ repeat=True,
146+ select=[],
147+ show_pep8=False,
148+ show_source=False,
149+ max_line_length=79,
150+ quiet=0,
151+ statistics=False,
152+ testsuite='',
153+ verbose=0
154+ )
155+
156+ def test_pep8_conformance(self):
157+ for package in self.packages:
158+ self.pep8style.input_dir(os.path.dirname(package.__file__))
159+ # FIXME: When this fails, the offending lines are not displayed, they
160+ # should. -- vila 2012-10-19
161+ self.assertEqual(self.pep8style.options.report.total_errors, 0)
162
163=== added file 'u1testutils/static/test_pyflakes_analysis.py'
164--- u1testutils/static/test_pyflakes_analysis.py 1970-01-01 00:00:00 +0000
165+++ u1testutils/static/test_pyflakes_analysis.py 2012-12-04 20:07:23 +0000
166@@ -0,0 +1,73 @@
167+# -*- coding: utf-8 -*-
168+
169+# Copyright 2012 Canonical Ltd.
170+#
171+# This program is free software: you can redistribute it and/or modify it
172+# under the terms of the GNU Lesser General Public License version 3, as
173+# published by the Free Software Foundation.
174+#
175+# This program is distributed in the hope that it will be useful, but
176+# WITHOUT ANY WARRANTY; without even the implied warranties of
177+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
178+# PURPOSE. See the GNU Lesser General Public License for more details.
179+#
180+# You should have received a copy of the GNU General Public License along
181+# with this program. If not, see <http://www.gnu.org/licenses/>.
182+
183+import os
184+import unittest
185+import cStringIO
186+
187+from mock import patch
188+from pyflakes.scripts.pyflakes import checkPath
189+
190+
191+class PyflakesAnalysisTestCase(unittest.TestCase):
192+
193+ packages = []
194+ exclude_file = None
195+
196+ def test_pyflakes_analysis(self):
197+ string_out = cStringIO.StringIO()
198+ with patch('sys.stdout', string_out):
199+ for package in self.packages:
200+ self._run_pyflakes_analysis(package)
201+ results = string_out.getvalue().splitlines()
202+ unexpected_errors = self._get_unexpected_errors(results)
203+ self.assertEqual(unexpected_errors, [],
204+ '\n'.join(unexpected_errors))
205+
206+ def _run_pyflakes_analysis(self, package):
207+ package_path = os.path.dirname(package.__file__)
208+ for dir_path, dir_names, file_names in os.walk(package_path):
209+ for file_name in file_names:
210+ if file_name.endswith('.py'):
211+ file_path = os.path.join(dir_path, file_name)
212+ checkPath(file_path)
213+
214+ def _get_unexpected_errors(self, results):
215+ unexpected_errors = []
216+ expected_errors = self._parse_exclude_file()
217+ if not expected_errors:
218+ unexpected_errors = results
219+ else:
220+ for line in results:
221+ found = False
222+ for file_, error in expected_errors:
223+ if file_ in line and error in line:
224+ found = True
225+ break
226+ if not found:
227+ unexpected_errors.append(line)
228+ return unexpected_errors
229+
230+ def _parse_exclude_file(self):
231+ excluded_errors = []
232+ if self.exclude_file is not None:
233+ with open(self.exclude_file) as file_:
234+ for line in file_:
235+ if line.strip():
236+ source_file, error = [data.strip() for data in
237+ line.split(':', 1)]
238+ excluded_errors.append((source_file, error))
239+ return excluded_errors
240
241=== modified file 'u1testutils/wsgi_intercept.py'
242--- u1testutils/wsgi_intercept.py 2011-02-08 19:45:30 +0000
243+++ u1testutils/wsgi_intercept.py 2012-12-04 20:07:23 +0000
244@@ -11,24 +11,24 @@
245 remove_wsgi_intercept,
246 wsgi_fake_socket,
247 WSGI_HTTPConnection,
248- )
249+)
250 from wsgi_intercept.httplib2_intercept import (
251 install,
252 uninstall,
253- )
254+)
255 from wsgi_intercept.urllib2_intercept import (
256 install_opener,
257 uninstall_opener,
258 WSGI_HTTPHandler,
259 WSGI_HTTPSHandler,
260- )
261+)
262
263
264 class WSGIInterceptedTestCase(TestCase):
265 def setup_intercept(self, callbacks, intercept_api=False):
266 """Setup the WSGI intercepts.
267
268- `callbacks` have to be provided to call upon request of the
269+ `callbacks` have to be provided to call upon request of the
270 intercepted urls. They should be supplied as a dictionary of
271 ((hostname, port), callback).
272
273@@ -68,7 +68,8 @@
274
275 def patch_wsgi_intercept(self):
276 # fix handler order to have highest priority
277- self.old_WSGI_HTTPHandler_handler_order = WSGI_HTTPHandler.handler_order
278+ self.old_WSGI_HTTPHandler_handler_order = \
279+ WSGI_HTTPHandler.handler_order
280 WSGI_HTTPHandler.handler_order = 1
281
282 if WSGI_HTTPSHandler is not None:
283@@ -76,7 +77,8 @@
284 return self.do_open(WSGI_HTTPSConnection, req)
285
286 # use HTTPSHandler for https connections
287- self.old_WSGI_HTTPSHandler_https_open = WSGI_HTTPSHandler.https_open
288+ self.old_WSGI_HTTPSHandler_https_open = \
289+ WSGI_HTTPSHandler.https_open
290 WSGI_HTTPSHandler.https_open = https_open
291
292 # fix handler order to have highest priority
293@@ -85,10 +87,12 @@
294 WSGI_HTTPSHandler.handler_order = 1
295
296 def unpatch_wsgi_intercept(self):
297- WSGI_HTTPHandler.handler_order = self.old_WSGI_HTTPHandler_handler_order
298+ WSGI_HTTPHandler.handler_order = \
299+ self.old_WSGI_HTTPHandler_handler_order
300
301 if WSGI_HTTPSHandler is not None:
302- WSGI_HTTPSHandler.https_open = self.old_WSGI_HTTPSHandler_https_open
303+ WSGI_HTTPSHandler.https_open = \
304+ self.old_WSGI_HTTPSHandler_https_open
305
306 WSGI_HTTPSHandler.handler_order = \
307 self.old_WSGI_HTTPSHandler_handler_order
308@@ -97,7 +101,7 @@
309 parsed = []
310 for url in urls:
311 scheme = url.find('://')
312- hostport = url[scheme+3:]
313+ hostport = url[scheme + 3:]
314 parts = hostport.split(':')
315 host = parts[0]
316 if len(parts) == 1:
317@@ -133,7 +137,7 @@
318 (app, script_name) = self.get_app(self.host, self.port)
319 if app:
320 if debuglevel:
321- sys.stderr.write('INTERCEPTING call to %s:%s\n' % \
322+ sys.stderr.write('INTERCEPTING call to %s:%s\n' %
323 (self.host, self.port,))
324 self.sock = wsgi_fake_socket(app, self.host, self.port,
325 script_name)
326@@ -144,4 +148,3 @@
327 if debuglevel: # intercept & print out tracebacks
328 traceback.print_exc()
329 raise
330-

Subscribers

People subscribed via source and target branches

to all changes: