openplans / openblock

OpenBlock is a web application and RESTful service that allows users to browse and search their local area for "hyper-local news
61 stars 26 forks source link

Test coverage #211

Open slinkp opened 12 years ago

slinkp commented 12 years ago

Our test coverage is rather spotty. I for one have been inconsistent about writing tests for new code.

If you install "django-nose" and "coverage", and set settings.TEST_RUNNER = 'django_nose.NoseTestSuiteRunner', then you can get coverage reports. For example:


$ django-admin.py test ebpub -- --with-doctest --with-coverage --cover-package=ebpub 
--cover-erase -s

INFO __init__: version: 2.4.2
nosetests --verbosity 1 ebpub --with-doctest --with-coverage --cover-package=ebpub --cover-erase -s -- --with-doctest --with-coverage --cover-package=ebpub --cover-erase -s
Creating test database for alias 'default'...
Got an error creating the test database: database "openblock_test" already exists

Type 'yes' if you would like to try deleting the test database 'openblock_test', or 'no' to cancel: yes
Destroying old test database 'default'...

........................................................................................................................................................................................................................................................................................................EEEEE
======================================================================
ERROR: Failure: OSError (No such file /home/pw/builds/openblock/builds/20110519/src/openblock/--with-doctest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/pw/builds/openblock/builds/20110519/lib/python2.6/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_class(self.exc_val)
OSError: No such file /home/pw/builds/openblock/builds/20110519/src/openblock/--with-doctest

======================================================================
ERROR: Failure: OSError (No such file /home/pw/builds/openblock/builds/20110519/src/openblock/--with-coverage)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/pw/builds/openblock/builds/20110519/lib/python2.6/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_class(self.exc_val)
OSError: No such file /home/pw/builds/openblock/builds/20110519/src/openblock/--with-coverage

======================================================================
ERROR: Failure: OSError (No such file /home/pw/builds/openblock/builds/20110519/src/openblock/--cover-package=ebpub)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/pw/builds/openblock/builds/20110519/lib/python2.6/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_class(self.exc_val)
OSError: No such file /home/pw/builds/openblock/builds/20110519/src/openblock/--cover-package=ebpub

======================================================================
ERROR: Failure: OSError (No such file /home/pw/builds/openblock/builds/20110519/src/openblock/--cover-erase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/pw/builds/openblock/builds/20110519/lib/python2.6/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_class(self.exc_val)
OSError: No such file /home/pw/builds/openblock/builds/20110519/src/openblock/--cover-erase

======================================================================
ERROR: Failure: OSError (No such file /home/pw/builds/openblock/builds/20110519/src/openblock/-s)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/pw/builds/openblock/builds/20110519/lib/python2.6/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_class(self.exc_val)
OSError: No such file /home/pw/builds/openblock/builds/20110519/src/openblock/-s

Name                                                                                                   Stmts   Miss  Cover   Missing
------------------------------------------------------------------------------------------------------------------------------------
ebpub                                                                                                      0      0   100%   
ebpub.accounts                                                                                             0      0   100%   
ebpub.accounts.admin                                                                                       3      0   100%   
ebpub.accounts.callbacks                                                                                  17      9    47%   34, 37, 46-50, 53-65
ebpub.accounts.constants                                                                                   2      0   100%   
ebpub.accounts.context_processors                                                                          6      0   100%   
ebpub.accounts.forms                                                                                      50     26    48%   28-31, 41-45, 59-62, 69-70, 77-92
ebpub.accounts.management                                                                                 34     13    62%   49, 55, 58-69
ebpub.accounts.management.                                                                                34     13    62%   49, 55, 58-69
ebpub.accounts.management.commands                                                                         0      0   100%   
ebpub.accounts.management.commands.createsuperuser                                                        63     47    25%   44-45, 60-117
ebpub.accounts.middleware                                                                                 31      3    90%   34, 40-41
ebpub.accounts.migrations                                                                                  0      0   100%   
ebpub.accounts.migrations.                                                                                 0      0   100%   
ebpub.accounts.migrations.0001_initial                                                                    15      2    87%   32-35
ebpub.accounts.models                                                                                     58     12    79%   38-39, 50, 83-84, 87, 100, 108-111, 123
ebpub.accounts.urls                                                                                        5      0   100%   
ebpub.accounts.utils                                                                                      72     30    58%   36-38, 52-53, 56-58, 61-76, 89-93, 104, 112-115, 135, 157
ebpub.accounts.views                                                                                     140    116    17%   43-81, 84-102, 106-119, 136, 139-144, 147-164, 175-184, 187-213, 220-226, 229-249
ebpub.alerts                                                                                               0      0   100%   
ebpub.alerts.migrations                                                                                    0      0   100%   
ebpub.alerts.migrations.                                                                                   0      0   100%   
ebpub.alerts.migrations.0001_initial                                                                      13      1    92%   37
ebpub.alerts.models                                                                                       38     14    63%   25, 51, 54, 57-60, 63, 66-72
ebpub.alerts.sending                                                                                      55     41    25%   37-51, 58-84, 90-103
ebpub.alerts.views                                                                                        92     59    36%   43, 56-60, 64-76, 82-106, 117-159, 163-168
ebpub.constants                                                                                            5      0   100%   
ebpub.db                                                                                                   0      0   100%   
ebpub.db.admin                                                                                            63      2    97%   112-113
ebpub.db.bin                                                                                               0      0   100%   
ebpub.db.bin.activate_schema                                                                              27     19    30%   27-33, 39-46, 53-58, 61-67, 70
ebpub.db.bin.geocode_newsitems                                                                            54     48    11%   30-76, 79-85, 88
ebpub.db.bin.import_locations                                                                            121     90    26%   40-52, 56-63, 66-125, 128-133, 136, 148-163, 166-169, 173-183, 186-199, 202
ebpub.db.bin.import_zips                                                                                  75     59    21%   32-43, 50-72, 75-100, 103, 106-112, 115-126, 129-135, 138
ebpub.db.breadcrumbs                                                                                      65     22    66%   19-29, 32-40, 45, 71-74
ebpub.db.constants                                                                                         4      0   100%   
ebpub.db.context_processors                                                                               13      0   100%   
ebpub.db.feeds                                                                                            94     60    36%   44-61, 84-122, 125-130, 133-138, 141, 148-149, 152, 155, 158, 161-162, 168-169, 173, 176, 179, 182
ebpub.db.forms                                                                                             6      0   100%   
ebpub.db.migrations                                                                                        0      0   100%   
ebpub.db.migrations.                                                                                       0      0   100%   
ebpub.db.migrations.0001_initial                                                                          63     19    70%   257-311
ebpub.db.migrations.0002_initial_statistics                                                               41     14    66%   51-64
ebpub.db.migrations.0003_attribute_indices                                                                71     29    59%   49-77
ebpub.db.migrations.0004_st_intersects_patch                                                              21      4    81%   72-75
ebpub.db.migrations.0005_newsitem_location_trigger                                                        19      3    84%   92-94
ebpub.db.migrations.0006_add_location_synonym                                                             12      1    92%   24
ebpub.db.migrations.0007_load_default_schemas                                                             32      1    97%   239
ebpub.db.migrations.0008_bigger_attributes                                                                21      6    71%   38-53
ebpub.db.migrations.0009_add_real_slug_to_schemafield                                                     11      1    91%   18
ebpub.db.migrations.0010_populate_schemafield_slugs                                                       17      5    71%   15-19
ebpub.db.migrations.0011_delete_schemafield_name                                                          11      1    91%   18
ebpub.db.migrations.0012__undo_0011                                                                       11      1    91%   16
ebpub.db.migrations.0013__undo_0010                                                                       17      3    82%   17-19
ebpub.db.migrations.0014__undo_0009                                                                       11      1    91%   15
ebpub.db.migrations.0015_auto__add_field_schema_map_icon_url__add_field_schema_map_color                  28     17    39%   19-41
ebpub.db.migrations.0016_use_slug_fields_for_slugs                                                        21      6    71%   33-48
ebpub.db.migrations.0017_del_location_centroid                                                            11      1    91%   17
ebpub.db.models                                                                                          555     92    83%   73, 185, 234, 263-265, 269-271, 285, 302, 308, 318, 348-352, 355-363, 370, 396, 424-428, 431, 440, 448, 453-455, 501-502, 509-510, 568, 574-575, 581-584, 586-588, 673, 676, 679, 682, 759, 766-767, 776-778, 789-790, 805, 808, 810, 814-815, 847, 851, 853, 907, 913, 928, 930-932, 941-948, 950-955, 960-961, 984, 1002, 1067, 1085, 1088
ebpub.db.schemafilters                                                                                   570     20    96%   174, 177, 183, 413, 553, 611-612, 714, 808, 815, 880, 895, 939-940, 964, 972-973, 992-996
ebpub.db.templatetags                                                                                      0      0   100%   
ebpub.db.templatetags.dateutils                                                                            6      1    83%   26
ebpub.db.templatetags.eb                                                                                 170     73    57%   41, 45, 50, 54, 68, 77-80, 85-89, 96-97, 100, 102, 104, 110-111, 115, 120-121, 125, 130-131, 134-139, 143-146, 151-153, 156-162, 166-169, 174-178, 181-195, 200-206, 220, 240, 243
ebpub.db.templatetags.eb_filter                                                                           66      1    98%   59
ebpub.db.templatetags.eb_json                                                                             14      7    50%   31-37
ebpub.db.templatetags.full_links                                                                          20     12    40%   31-32, 35-38, 42-47
ebpub.db.templatetags.mapping                                                                             13      3    77%   36-37, 41
ebpub.db.templatetags.raw                                                                                 19     15    21%   31-56
ebpub.db.urlresolvers                                                                                     18      1    94%   37
ebpub.db.utils                                                                                           137     14    90%   71, 86, 93, 101, 113, 120, 143, 202, 210-211, 230-231, 237, 255
ebpub.db.views                                                                                           550    168    69%   77, 106, 121-126, 134-149, 183-184, 226, 240-242, 272-273, 285-307, 332-333, 343, 353-375, 383-386, 390-392, 402, 406-410, 422-424, 438-455, 475-486, 495, 504-506, 523-524, 535-545, 549-552, 586-598, 608-611, 796-802, 809-820, 823-839, 846-854, 861, 869-873, 898, 902, 919, 978, 995, 1018, 1027, 1049, 1056
ebpub.geoadmin                                                                                            36      6    83%   67-68, 108-111
ebpub.geocoder                                                                                             3      3     0%   19-21
ebpub.geocoder.base                                                                                      192     75    61%   19-36, 42-52, 57-59, 63, 67-69, 73-75, 78-117, 120, 139-141, 156, 160, 170-171, 175-176, 191-192, 197, 232, 255-257, 260, 273-274, 277, 281-282, 285, 306, 312, 324-325, 328, 355-356
ebpub.geocoder.migrations                                                                                  0      0   100%   
ebpub.geocoder.migrations.                                                                                 0      0   100%   
ebpub.geocoder.migrations.0001_initial                                                                    12      1    92%   30
ebpub.geocoder.models                                                                                     28      2    93%   36, 44
ebpub.geocoder.parser                                                                                      0      0   100%   
ebpub.geocoder.parser.cities                                                                               1      1     0%   19
ebpub.geocoder.parser.models                                                                               0      0   100%   
ebpub.geocoder.parser.numbered_streets                                                                     1      1     0%   19
ebpub.geocoder.parser.parsing                                                                            120     41    66%   19-64, 75, 81, 102-123, 144, 168, 204-229, 235, 238, 240, 243, 263-265, 300, 303-305
ebpub.geocoder.parser.states                                                                               1      1     0%   19
ebpub.geocoder.parser.suffixes                                                                             1      1     0%   19
ebpub.geocoder.reverse                                                                                    24     24     0%   19-82
ebpub.metros                                                                                               0      0   100%   
ebpub.metros.allmetros                                                                                     7      4    43%   19-24
ebpub.metros.loader                                                                                       52     43    17%   32-55, 58-78, 81-82
ebpub.metros.migrations                                                                                    0      0   100%   
ebpub.metros.migrations.                                                                                   0      0   100%   
ebpub.metros.migrations.0001_initial                                                                      14      2    86%   34-37
ebpub.metros.models                                                                                       35      3    91%   24, 45, 65
ebpub.metros.urls                                                                                          5      0   100%   
ebpub.metros.views                                                                                        18      2    89%   35-36
ebpub.monkeypatches                                                                                      110     43    61%   57-64, 103-111, 123, 146-153, 162-208, 236
ebpub.neighbornews                                                                                         0      0   100%   
ebpub.neighbornews.forms                                                                                  26      6    77%   7-15
ebpub.neighbornews.models                                                                                  1      0   100%   
ebpub.neighbornews.urls                                                                                    3      0   100%   
ebpub.neighbornews.utils                                                                                  23     10    57%   9-12, 15, 18, 25, 30-33
ebpub.neighbornews.views                                                                                  52     34    35%   15-17, 22-24, 27-50, 53-57, 60, 63-83
ebpub.openblockapi                                                                                         0      0   100%   
ebpub.openblockapi.apikey                                                                                  0      0   100%   
ebpub.openblockapi.apikey.admin                                                                           32     13    59%   43-65
ebpub.openblockapi.apikey.auth                                                                            40      3    93%   49, 74, 87
ebpub.openblockapi.apikey.migrations                                                                       0      0   100%   
ebpub.openblockapi.apikey.migrations.                                                                      0      0   100%   
ebpub.openblockapi.apikey.migrations.0001_initial                                                         12      1    92%   25
ebpub.openblockapi.apikey.models                                                                          37      4    89%   19-20, 37-38
ebpub.openblockapi.apikey.signals                                                                         15      4    73%   22-25
ebpub.openblockapi.apikey.urls                                                                             2      0   100%   
ebpub.openblockapi.apikey.views                                                                           66     42    36%   24-32, 35-37, 40-43, 51-66, 73, 78-83, 93-102
ebpub.openblockapi.itemquery                                                                             145     27    81%   139, 145-146, 164-179, 198, 203-204, 209, 213-214, 228-229, 234-236
ebpub.openblockapi.models                                                                                  0      0   100%   
ebpub.openblockapi.throttle                                                                               43     13    70%   60, 68, 108-111, 117-124
ebpub.openblockapi.urls                                                                                    3      0   100%   
ebpub.openblockapi.views                                                                                 372     25    93%   174, 206-208, 263, 344-346, 377-380, 392-393, 398, 400, 420-427, 498
ebpub.petitions                                                                                            0      0   100%   
ebpub.petitions.migrations                                                                                 0      0   100%   
ebpub.petitions.migrations.                                                                                0      0   100%   
ebpub.petitions.migrations.0001_initial                                                                   15      2    87%   42-45
ebpub.petitions.models                                                                                    27      5    81%   32, 35-37, 51
ebpub.petitions.views                                                                                     44     25    43%   30-38, 49-72, 75-79
ebpub.preferences                                                                                          0      0   100%   
ebpub.preferences.migrations                                                                               0      0   100%   
ebpub.preferences.migrations.                                                                              0      0   100%   
ebpub.preferences.migrations.0001_initial                                                                 12      1    92%   23
ebpub.preferences.migrations.0002_auto__add_profile                                                       13      1    92%   24
ebpub.preferences.migrations.0003_populate_profiles                                                       12      2    83%   12, 18
ebpub.preferences.migrations.0004_auto__add_field_profile_max_keys                                        11      1    91%   18
ebpub.preferences.models                                                                                  33     13    61%   30-36, 40, 58-59, 62-63, 66
ebpub.preferences.views                                                                                   33     28    15%   27-47, 53-66
ebpub.richmaps                                                                                             0      0   100%   
ebpub.richmaps.models                                                                                      1      0   100%   
ebpub.richmaps.urls                                                                                        3      0   100%   
ebpub.richmaps.views                                                                                     136    117    14%   18-20, 36-178, 186-200, 203-216, 224-248
ebpub.savedplaces                                                                                          0      0   100%   
ebpub.savedplaces.migrations                                                                               0      0   100%   
ebpub.savedplaces.migrations.                                                                              0      0   100%   
ebpub.savedplaces.migrations.0001_initial                                                                 12      1    92%   25
ebpub.savedplaces.models                                                                                  26     12    54%   34, 37, 41-47, 53-56
ebpub.savedplaces.views                                                                                   47     39    17%   29-60, 66-83, 90-94
ebpub.settings_default                                                                                    65     65     0%   19-416
ebpub.streets                                                                                              0      0   100%   
ebpub.streets.admin                                                                                      270     83    69%   55-57, 60-82, 86-87, 117-120, 133, 138, 159, 162, 167, 183-186, 191-193, 200-202, 212-215, 229-236, 241-248, 274-278, 304-306, 319-324, 329-333, 353-355, 433-434
ebpub.streets.bin                                                                                          0      0   100%   
ebpub.streets.bin.populate_streets                                                                       108     89    18%   76-97, 100-116, 123-138, 142-150, 157-211, 221-254, 257
ebpub.streets.blockimport                                                                                  0      0   100%   
ebpub.streets.blockimport.base                                                                            69     53    23%   33-35, 39-40, 43-129, 142, 148
ebpub.streets.blockimport.esri                                                                             0      0   100%   
ebpub.streets.blockimport.esri.importers                                                                   0      0   100%   
ebpub.streets.blockimport.esri.importers.blocks                                                           93     74    20%   65-71, 74-75, 79-161, 166-187, 190
ebpub.streets.blockimport.esri.importers.zipcodes                                                         42     34    19%   27-30, 43-92
ebpub.streets.blockimport.esri.management                                                                  0      0   100%   
ebpub.streets.blockimport.esri.management.commands                                                         0      0   100%   
ebpub.streets.blockimport.esri.management.commands.importesri                                             21     16    24%   26-42
ebpub.streets.blockimport.tiger                                                                            0      0   100%   
ebpub.streets.blockimport.tiger.import_blocks                                                            144    124    14%   119-150, 158-171, 174-182, 185-190, 193-219, 222-244, 248-292, 296
ebpub.streets.migrations                                                                                   0      0   100%   
ebpub.streets.migrations.                                                                                  0      0   100%   
ebpub.streets.migrations.0001_initial                                                                     37     10    73%   124-151
ebpub.streets.migrations.0002_add_place_misspellings                                                      12      1    92%   23
ebpub.streets.migrations.0003_refactor_misspellings                                                       15      3    80%   27-35
ebpub.streets.migrations.0004_fix_block_numbers                                                           30     10    67%   15, 17-20, 25, 27-28, 32, 34-35, 38
ebpub.streets.migrations.0005_auto__add_placetype                                                         12      1    92%   28
ebpub.streets.migrations.0006_initial_place_types                                                         19      0   100%   
ebpub.streets.migrations.0007_auto__add_field_place_place_type                                            12      1    92%   18
ebpub.streets.migrations.0008_auto__add_field_place_url                                                   11      1    91%   18
ebpub.streets.migrations.0009_auto__del_field_placetype_map_icon                                          11      1    91%   18
ebpub.streets.migrations.0010_auto__add_field_placetype_map_icon_url__add_field_placetype_map_color       28     17    39%   19-42
ebpub.streets.models                                                                                     408    277    32%   19-45, 63, 74-77, 81, 84-85, 107, 115-116, 136-137, 144, 147-226, 229, 234, 236, 238, 241, 263, 267, 274, 278, 282, 286-289, 292, 295, 310-311, 317, 319, 331, 335, 337-339, 343-345, 349-352, 354-481, 495-515, 518-531, 534-552, 554, 557, 563-564, 577-586, 591-633, 644, 648, 650, 652, 656, 658, 667-695, 698-701, 710-729
ebpub.streets.name_utils                                                                                  51     40    22%   27-30, 33-43, 46-54, 65, 72-78, 92-97, 100, 103-114
ebpub.streets.utils                                                                                       36      4    89%   70-71, 81-82
ebpub.urls                                                                                                18      5    72%   31-36, 80
ebpub.utils                                                                                                0      0   100%   
ebpub.utils.bunch                                                                                         13      6    54%   23-24, 27-28, 47-48
ebpub.utils.dates                                                                                         15      0   100%   
ebpub.utils.geodjango                                                                                     71     47    34%   35-38, 45, 51-66, 76-81, 84-100, 112-113, 124-126, 134-136, 143-144, 151, 157-158
ebpub.utils.logutils                                                                                       6      3    50%   27-29
ebpub.utils.mapmath                                                                                       46     26    43%   39, 45, 51, 54, 58-60, 64, 67, 70, 73, 76-78, 85-86, 89-94, 97-99, 105
ebpub.utils.models                                                                                         0      0   100%   
ebpub.utils.multidb                                                                                       27     18    33%   60-63, 66-72, 75, 78, 82, 85-93
ebpub.utils.script_utils                                                                                  34     23    32%   34, 39-46, 51-57, 63, 68-74
ebpub.utils.text                                                                                          44     17    61%   28-32, 138-148, 151-152
ebpub.utils.view_utils                                                                                    46      2    96%   63, 89
ebpub.widgets                                                                                              0      0   100%   
ebpub.widgets.admin                                                                                        9      0   100%   
ebpub.widgets.migrations                                                                                   0      0   100%   
ebpub.widgets.migrations.                                                                                  0      0   100%   
ebpub.widgets.migrations.0001_initial                                                                     19      3    84%   52-58
ebpub.widgets.migrations.0002_auto__del_field_widget_extra_link_parameters__add_field_widget_item_li      14      2    86%   26-29
ebpub.widgets.models                                                                                      40     15    63%   19, 38, 42, 45, 49-58, 61, 64
ebpub.widgets.urls                                                                                         3      0   100%   
ebpub.widgets.views                                                                                       66     53    20%   10-16, 20-25, 29-37, 42-82, 85-94, 97-98
------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                                                                   7733   3012    61%   
----------------------------------------------------------------------
Ran 301 tests in 40.013s

FAILED (errors=5)
Destroying test database for alias 'default'...

Not great; a lot is untested.

(note the test failres are due to somewhat broken option parsing in django-nose, it's treating options as module names. You can avoid this by putting the same options in settings.NOSE_ARGS.)

slinkp commented 12 years ago

Ticket imported from Trac: http://developer.openblockproject.org/ticket/218 Reported by: slinkp