Merge lp:~vds/desktopcouch/add_test_coverage into lp:desktopcouch

Proposed by Vincenzo Di Somma
Status: Merged
Approved by: Eric Casteleijn
Approved revision: 204
Merged at revision: 203
Proposed branch: lp:~vds/desktopcouch/add_test_coverage
Merge into: lp:desktopcouch
Diff against target: 221 lines (+73/-25)
4 files modified
desktopcouch/records/tests/test_field_registry.py (+21/-4)
desktopcouch/records/tests/test_record.py (+22/-3)
runtests.py (+27/-9)
utilities/lint.sh (+3/-9)
To merge this branch: bzr merge lp:~vds/desktopcouch/add_test_coverage
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Chad Miller (community) Approve
Review via email: mp+40661@code.launchpad.net

Commit message

Add script runtest.sh that now runs both lint and coverage check.

Description of the change

Add script runtest.sh that now runs both lint and coverage check.

To post a comment you must log in.
Revision history for this message
Chad Miller (cmiller) wrote :

I don't especially like the new "runtests.sh". I think all its contents should be in "runtests.py" instead.

subprocess.call() for all the lines except "pyfiles=".

find is

source_files = list()
for dir, filenames in os.walk:
   for filename in filenames:
       if filename.endswith(".py") and "test_" not in filename:
            source_files.append(os.join(dir, filename))

or something like that.

then subprocess.call(['python-coverage', '-r'] + source_files)

review: Needs Fixing
Revision history for this message
Vincenzo Di Somma (vds) wrote :

Moved everything to the runtests.py.

204. By Vincenzo Di Somma

removed shell script and moved averything into runtests.py

Revision history for this message
Chad Miller (cmiller) wrote :

Nice!

review: Approve
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Awesome!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/records/tests/test_field_registry.py'
2--- desktopcouch/records/tests/test_field_registry.py 2010-04-05 17:46:53 +0000
3+++ desktopcouch/records/tests/test_field_registry.py 2010-11-12 11:59:09 +0000
4@@ -17,8 +17,10 @@
5
6 """Test cases for field mapping"""
7
8-import copy, doctest
9+import copy, doctest, os
10 from testtools import TestCase
11+
12+import desktopcouch
13 from desktopcouch.records.field_registry import (
14 SimpleFieldMapping, MergeableListFieldMapping, Transformer)
15 from desktopcouch.records.record import Record
16@@ -40,7 +42,7 @@
17 'simpleField': 23,
18 'strawberryField': 'the value',}
19
20-field_registry = {
21+FIELD_REGISTRY = {
22 'simpleField': SimpleFieldMapping('simple_field'),
23 'strawberryField': MergeableListFieldMapping(
24 'Test App', 'test_field', 'test_fields', 'the_field'),}
25@@ -50,7 +52,7 @@
26 """A test transformer class."""
27
28 def __init__(self):
29- super(AppTransformer, self).__init__('Test App', field_registry)
30+ super(AppTransformer, self).__init__('Test App', FIELD_REGISTRY)
31
32
33 class TestFieldMapping(TestCase):
34@@ -81,6 +83,7 @@
35
36 def test_mergeable_list_field_mapping1(self):
37 """Test the MergeableListFieldMapping object."""
38+ # pylint: disable-msg=W0212
39 record = Record(self.test_record)
40 mapping = MergeableListFieldMapping(
41 'Test App', 'test_field', 'test_fields', 'the_field')
42@@ -89,6 +92,7 @@
43 'e47455fb-da05-481e-a2c7-88f14d5cc163']
44 mapping.deleteValue(record)
45 self.assertEqual(None, mapping.getValue(record))
46+ # pylint: enable-msg=W0212
47
48 def test_mergeable_list_field_mapping_empty_field(self):
49 """Test setting empty values in the MergeableListFieldMapping object."""
50@@ -109,6 +113,7 @@
51
52 def test_from_app(self):
53 """Test transformation from app to Ubuntu One."""
54+ # pylint: disable-msg=W0212
55 record = Record(record_type="http://example.com/test")
56 self.transformer.from_app(APP_RECORD, record)
57 underlying = record._data
58@@ -118,6 +123,7 @@
59 self.assertEqual(
60 {'the_field': 'the value'},
61 underlying['test_fields'][the_uuid])
62+ # pylint: enable-msg=W0212
63
64 def test_to_app(self):
65 """Test transformation to app from Ubuntu One."""
66@@ -128,5 +134,16 @@
67 {'simpleField': 23, 'strawberryField': 'the value'}, data)
68
69 def test_run_doctests(self):
70- results = doctest.testfile('../doc/field_registry.txt')
71+ """We run doctests from here to give some context"""
72+ field_registry_tests_path = os.path.dirname(
73+ desktopcouch.__file__) + '/records/doc/field_registry.txt'
74+ try:
75+ results = doctest.testfile(field_registry_tests_path,
76+ module_relative=False)
77+ except IOError:
78+ field_registry_tests_path = \
79+ '../desktopcouch/records/doc/field_registry.txt'
80+ results = doctest.testfile(field_registry_tests_path,
81+ module_relative=False)
82+
83 self.assertEqual(0, results.failed)
84
85=== modified file 'desktopcouch/records/tests/test_record.py'
86--- desktopcouch/records/tests/test_record.py 2010-11-03 23:50:38 +0000
87+++ desktopcouch/records/tests/test_record.py 2010-11-12 11:59:09 +0000
88@@ -19,11 +19,12 @@
89
90 """Tests for the RecordDict object on which the Contacts API is built."""
91
92+import doctest, os
93 from testtools import TestCase
94-import doctest
95
96 # pylint does not like relative imports from containing packages
97 # pylint: disable-msg=F0401
98+import desktopcouch
99 from desktopcouch.records.server import CouchDatabase
100 from desktopcouch.records.record import (Record, RecordDict, MergeableList,
101 record_factory, IllegalKeyException, validate, NoRecordTypeSpecified)
102@@ -313,8 +314,26 @@
103 """Run all doc tests from here to set the proper context (ctx)"""
104 ctx = test_environment.test_context
105 globs = { "db": CouchDatabase('testing', create=True, ctx=ctx) }
106- results = doctest.testfile('../doc/records.txt', globs=globs)
107- results = doctest.testfile('../doc/an_example_application.txt')
108+
109+ records_tests_path = os.path.dirname(
110+ desktopcouch.__file__) + '/records/doc/records.txt'
111+
112+ app_tests_path = os.path.dirname(
113+ desktopcouch.__file__) + '/records/doc/an_example_application.txt'
114+ try:
115+ results = doctest.testfile(records_tests_path,
116+ globs=globs,
117+ module_relative=False)
118+ results = doctest.testfile(app_tests_path, module_relative=False)
119+ except IOError:
120+ results = doctest.testfile(
121+ '../desktopcouch/records/doc/records.txt',
122+ globs=globs,
123+ module_relative=False)
124+ results = doctest.testfile(
125+ '../desktopcouch/records/doc/an_example_application.txt',
126+ module_relative=False)
127+
128 self.assertEqual(0, results.failed)
129
130 def test_record_id(self):
131
132=== modified file 'runtests.py'
133--- runtests.py 2010-11-02 18:59:50 +0000
134+++ runtests.py 2010-11-12 11:59:09 +0000
135@@ -2,11 +2,24 @@
136
137 """Run all tests of the module"""
138
139-import os, sys
140-from twisted.trial import runner, itrial, reporter
141-
142-dir, filename = os.path.split(__file__)
143-sys.path.insert(0, os.path.realpath(dir))
144+import os, subprocess, sys
145+import coverage
146+from twisted.trial import runner, reporter
147+
148+def ffind(path):
149+ """find files in a subtree"""
150+
151+ def filter_code_files(file_name):
152+ """Filters files we want to check for test coverage"""
153+ if file_name.endswith(".py") and "test_" not in file_name:
154+ return True
155+ return False
156+
157+ file_list = []
158+ for directories, _subdirs, files in os.walk(path):
159+ file_list.extend('%s%s%s' % (directories, os.sep, f) for f in files)
160+ file_list = [x for x in file_list if filter_code_files(x)]
161+ return (file_list)
162
163 def get_test_suite():
164 """Load the test suite"""
165@@ -20,10 +33,15 @@
166 return test_result.wasSuccessful()
167
168 if __name__ == '__main__':
169- import subprocess
170 from desktopcouch.platform import set_application_name
171-
172+ # pylint: disable-msg=C0103
173+ coverage.erase()
174+ coverage.start()
175 set_application_name("desktopcouch test runner")
176- ret = run()
177+ return_code = run()
178+ coverage.stop()
179 subprocess.call(["utilities/lint.sh", ""], shell=True)
180- sys.exit(not ret)
181+ source_files = ffind('desktopcouch')
182+ coverage.report(source_files, ignore_errors=1, show_missing=0)
183+ sys.exit(not return_code)
184+ # pylint: enable-msg=C0103
185
186=== modified file 'utilities/lint.sh'
187--- utilities/lint.sh 2010-11-03 23:50:38 +0000
188+++ utilities/lint.sh 2010-11-12 11:59:09 +0000
189@@ -20,8 +20,9 @@
190 exit 1
191 fi
192 files=`bzr st --short $rev_option | sed '/^.[MN]/!d; s/.* //'`
193+pyfiles=`echo "$files" | egrep '.py'`
194
195-if [ -z "$files" ]; then
196+if [ -z "$pyfiles" ]; then
197 echo ""
198 echo "No changed files detected."
199 echo ""
200@@ -29,20 +30,13 @@
201 else
202 echo ""
203 echo "Linting changed files:"
204- for file in $files; do
205+ for file in $pyfiles; do
206 echo " $file"
207 done
208 echo ""
209 fi
210
211-
212-if [ -z "$files" ]; then
213- exit $EXIT
214-fi
215-
216-
217 export PYTHONPATH="/usr/share/pycentral/pylint/site-packages:desktopcouch:$PYTHONPATH"
218-pyfiles=`echo "$files" | egrep '.py'`
219 pylint="`which pylint` -r n -i y --variable-rgx=[a-z_][a-z0-9_]{0,30} --method-rgx=[a-z_][a-z0-9_]{2,} -d I0011,R0904,R0913"
220
221 pylint_notices=`$pylint $pyfiles`

Subscribers

People subscribed via source and target branches