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
=== modified file 'desktopcouch/records/tests/test_field_registry.py'
--- desktopcouch/records/tests/test_field_registry.py 2010-04-05 17:46:53 +0000
+++ desktopcouch/records/tests/test_field_registry.py 2010-11-12 11:59:09 +0000
@@ -17,8 +17,10 @@
1717
18"""Test cases for field mapping"""18"""Test cases for field mapping"""
1919
20import copy, doctest20import copy, doctest, os
21from testtools import TestCase21from testtools import TestCase
22
23import desktopcouch
22from desktopcouch.records.field_registry import (24from desktopcouch.records.field_registry import (
23 SimpleFieldMapping, MergeableListFieldMapping, Transformer)25 SimpleFieldMapping, MergeableListFieldMapping, Transformer)
24from desktopcouch.records.record import Record26from desktopcouch.records.record import Record
@@ -40,7 +42,7 @@
40 'simpleField': 23,42 'simpleField': 23,
41 'strawberryField': 'the value',}43 'strawberryField': 'the value',}
4244
43field_registry = {45FIELD_REGISTRY = {
44 'simpleField': SimpleFieldMapping('simple_field'),46 'simpleField': SimpleFieldMapping('simple_field'),
45 'strawberryField': MergeableListFieldMapping(47 'strawberryField': MergeableListFieldMapping(
46 'Test App', 'test_field', 'test_fields', 'the_field'),}48 'Test App', 'test_field', 'test_fields', 'the_field'),}
@@ -50,7 +52,7 @@
50 """A test transformer class."""52 """A test transformer class."""
5153
52 def __init__(self):54 def __init__(self):
53 super(AppTransformer, self).__init__('Test App', field_registry)55 super(AppTransformer, self).__init__('Test App', FIELD_REGISTRY)
5456
5557
56class TestFieldMapping(TestCase):58class TestFieldMapping(TestCase):
@@ -81,6 +83,7 @@
8183
82 def test_mergeable_list_field_mapping1(self):84 def test_mergeable_list_field_mapping1(self):
83 """Test the MergeableListFieldMapping object."""85 """Test the MergeableListFieldMapping object."""
86 # pylint: disable-msg=W0212
84 record = Record(self.test_record)87 record = Record(self.test_record)
85 mapping = MergeableListFieldMapping(88 mapping = MergeableListFieldMapping(
86 'Test App', 'test_field', 'test_fields', 'the_field')89 'Test App', 'test_field', 'test_fields', 'the_field')
@@ -89,6 +92,7 @@
89 'e47455fb-da05-481e-a2c7-88f14d5cc163']92 'e47455fb-da05-481e-a2c7-88f14d5cc163']
90 mapping.deleteValue(record)93 mapping.deleteValue(record)
91 self.assertEqual(None, mapping.getValue(record))94 self.assertEqual(None, mapping.getValue(record))
95 # pylint: enable-msg=W0212
9296
93 def test_mergeable_list_field_mapping_empty_field(self):97 def test_mergeable_list_field_mapping_empty_field(self):
94 """Test setting empty values in the MergeableListFieldMapping object."""98 """Test setting empty values in the MergeableListFieldMapping object."""
@@ -109,6 +113,7 @@
109113
110 def test_from_app(self):114 def test_from_app(self):
111 """Test transformation from app to Ubuntu One."""115 """Test transformation from app to Ubuntu One."""
116 # pylint: disable-msg=W0212
112 record = Record(record_type="http://example.com/test")117 record = Record(record_type="http://example.com/test")
113 self.transformer.from_app(APP_RECORD, record)118 self.transformer.from_app(APP_RECORD, record)
114 underlying = record._data119 underlying = record._data
@@ -118,6 +123,7 @@
118 self.assertEqual(123 self.assertEqual(
119 {'the_field': 'the value'},124 {'the_field': 'the value'},
120 underlying['test_fields'][the_uuid])125 underlying['test_fields'][the_uuid])
126 # pylint: enable-msg=W0212
121127
122 def test_to_app(self):128 def test_to_app(self):
123 """Test transformation to app from Ubuntu One."""129 """Test transformation to app from Ubuntu One."""
@@ -128,5 +134,16 @@
128 {'simpleField': 23, 'strawberryField': 'the value'}, data)134 {'simpleField': 23, 'strawberryField': 'the value'}, data)
129135
130 def test_run_doctests(self):136 def test_run_doctests(self):
131 results = doctest.testfile('../doc/field_registry.txt')137 """We run doctests from here to give some context"""
138 field_registry_tests_path = os.path.dirname(
139 desktopcouch.__file__) + '/records/doc/field_registry.txt'
140 try:
141 results = doctest.testfile(field_registry_tests_path,
142 module_relative=False)
143 except IOError:
144 field_registry_tests_path = \
145 '../desktopcouch/records/doc/field_registry.txt'
146 results = doctest.testfile(field_registry_tests_path,
147 module_relative=False)
148
132 self.assertEqual(0, results.failed)149 self.assertEqual(0, results.failed)
133150
=== modified file 'desktopcouch/records/tests/test_record.py'
--- desktopcouch/records/tests/test_record.py 2010-11-03 23:50:38 +0000
+++ desktopcouch/records/tests/test_record.py 2010-11-12 11:59:09 +0000
@@ -19,11 +19,12 @@
1919
20"""Tests for the RecordDict object on which the Contacts API is built."""20"""Tests for the RecordDict object on which the Contacts API is built."""
2121
22import doctest, os
22from testtools import TestCase23from testtools import TestCase
23import doctest
2424
25# pylint does not like relative imports from containing packages25# pylint does not like relative imports from containing packages
26# pylint: disable-msg=F040126# pylint: disable-msg=F0401
27import desktopcouch
27from desktopcouch.records.server import CouchDatabase28from desktopcouch.records.server import CouchDatabase
28from desktopcouch.records.record import (Record, RecordDict, MergeableList,29from desktopcouch.records.record import (Record, RecordDict, MergeableList,
29 record_factory, IllegalKeyException, validate, NoRecordTypeSpecified)30 record_factory, IllegalKeyException, validate, NoRecordTypeSpecified)
@@ -313,8 +314,26 @@
313 """Run all doc tests from here to set the proper context (ctx)"""314 """Run all doc tests from here to set the proper context (ctx)"""
314 ctx = test_environment.test_context315 ctx = test_environment.test_context
315 globs = { "db": CouchDatabase('testing', create=True, ctx=ctx) }316 globs = { "db": CouchDatabase('testing', create=True, ctx=ctx) }
316 results = doctest.testfile('../doc/records.txt', globs=globs)317
317 results = doctest.testfile('../doc/an_example_application.txt')318 records_tests_path = os.path.dirname(
319 desktopcouch.__file__) + '/records/doc/records.txt'
320
321 app_tests_path = os.path.dirname(
322 desktopcouch.__file__) + '/records/doc/an_example_application.txt'
323 try:
324 results = doctest.testfile(records_tests_path,
325 globs=globs,
326 module_relative=False)
327 results = doctest.testfile(app_tests_path, module_relative=False)
328 except IOError:
329 results = doctest.testfile(
330 '../desktopcouch/records/doc/records.txt',
331 globs=globs,
332 module_relative=False)
333 results = doctest.testfile(
334 '../desktopcouch/records/doc/an_example_application.txt',
335 module_relative=False)
336
318 self.assertEqual(0, results.failed)337 self.assertEqual(0, results.failed)
319338
320 def test_record_id(self):339 def test_record_id(self):
321340
=== modified file 'runtests.py'
--- runtests.py 2010-11-02 18:59:50 +0000
+++ runtests.py 2010-11-12 11:59:09 +0000
@@ -2,11 +2,24 @@
22
3"""Run all tests of the module"""3"""Run all tests of the module"""
44
5import os, sys 5import os, subprocess, sys
6from twisted.trial import runner, itrial, reporter6import coverage
77from twisted.trial import runner, reporter
8dir, filename = os.path.split(__file__)8
9sys.path.insert(0, os.path.realpath(dir))9def ffind(path):
10 """find files in a subtree"""
11
12 def filter_code_files(file_name):
13 """Filters files we want to check for test coverage"""
14 if file_name.endswith(".py") and "test_" not in file_name:
15 return True
16 return False
17
18 file_list = []
19 for directories, _subdirs, files in os.walk(path):
20 file_list.extend('%s%s%s' % (directories, os.sep, f) for f in files)
21 file_list = [x for x in file_list if filter_code_files(x)]
22 return (file_list)
1023
11def get_test_suite():24def get_test_suite():
12 """Load the test suite"""25 """Load the test suite"""
@@ -20,10 +33,15 @@
20 return test_result.wasSuccessful()33 return test_result.wasSuccessful()
2134
22if __name__ == '__main__':35if __name__ == '__main__':
23 import subprocess
24 from desktopcouch.platform import set_application_name36 from desktopcouch.platform import set_application_name
25 37 # pylint: disable-msg=C0103
38 coverage.erase()
39 coverage.start()
26 set_application_name("desktopcouch test runner")40 set_application_name("desktopcouch test runner")
27 ret = run()41 return_code = run()
42 coverage.stop()
28 subprocess.call(["utilities/lint.sh", ""], shell=True)43 subprocess.call(["utilities/lint.sh", ""], shell=True)
29 sys.exit(not ret)44 source_files = ffind('desktopcouch')
45 coverage.report(source_files, ignore_errors=1, show_missing=0)
46 sys.exit(not return_code)
47 # pylint: enable-msg=C0103
3048
=== modified file 'utilities/lint.sh'
--- utilities/lint.sh 2010-11-03 23:50:38 +0000
+++ utilities/lint.sh 2010-11-12 11:59:09 +0000
@@ -20,8 +20,9 @@
20 exit 120 exit 1
21fi21fi
22files=`bzr st --short $rev_option | sed '/^.[MN]/!d; s/.* //'`22files=`bzr st --short $rev_option | sed '/^.[MN]/!d; s/.* //'`
23pyfiles=`echo "$files" | egrep '.py'`
2324
24if [ -z "$files" ]; then25if [ -z "$pyfiles" ]; then
25 echo ""26 echo ""
26 echo "No changed files detected."27 echo "No changed files detected."
27 echo ""28 echo ""
@@ -29,20 +30,13 @@
29else30else
30 echo ""31 echo ""
31 echo "Linting changed files:"32 echo "Linting changed files:"
32 for file in $files; do33 for file in $pyfiles; do
33 echo " $file"34 echo " $file"
34 done35 done
35 echo ""36 echo ""
36fi37fi
3738
38
39if [ -z "$files" ]; then
40 exit $EXIT
41fi
42
43
44export PYTHONPATH="/usr/share/pycentral/pylint/site-packages:desktopcouch:$PYTHONPATH"39export PYTHONPATH="/usr/share/pycentral/pylint/site-packages:desktopcouch:$PYTHONPATH"
45pyfiles=`echo "$files" | egrep '.py'`
46pylint="`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"40pylint="`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"
4741
48pylint_notices=`$pylint $pyfiles`42pylint_notices=`$pylint $pyfiles`

Subscribers

People subscribed via source and target branches