Skip to content

Commit

Permalink
FIX: Add simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Jan 27, 2016
1 parent cb9b82f commit 049b295
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Fix loading packages from capitalised package on Windows
Patch by Thomas Kluyver
- Add option to suppress printing of coverage report
Patch by Eric Larson.

1.3.6

Expand Down Expand Up @@ -32,8 +34,6 @@

1.3.3

- Add option to suppress printing of coverage report
Patch by Eric Larson.
- Fixed a minor issue with the reported version number.

1.3.2
Expand Down
18 changes: 16 additions & 2 deletions nose/plugins/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def configure(self, options, conf):
if options.cover_xml:
self.coverXmlFile = options.cover_xml_file
log.debug('Will put XML coverage report in %s', self.coverXmlFile)
# Coverage uses True to mean default
self.coverConfigFile = True
if options.cover_config_file:
self.coverConfigFile = options.cover_config_file
self.coverPrint = not options.cover_no_print
if self.enabled:
self.status['active'] = True
Expand All @@ -156,7 +160,18 @@ def configure(self, options, conf):
self.coverInstance.is_worker = conf.worker
self.coverInstance.exclude('#pragma[: ]+[nN][oO] [cC][oO][vV][eE][rR]')

def begin(self):
log.debug("Coverage begin")
self.skipModules = sys.modules.keys()[:]
if self.coverErase:
log.debug("Clearing previously collected coverage statistics")
self.coverInstance.combine()
self.coverInstance.erase()

if not self.coverInstance.is_worker:
self.coverInstance.load()
self.coverInstance.start()

def beforeTest(self, *args, **kwargs):
"""
Begin recording coverage information.
"""
Expand All @@ -174,7 +189,6 @@ def afterTest(self, *args, **kwargs):
self.coverInstance.stop()
self.coverInstance.save()


def report(self, stream):
"""
Output code coverage report.
Expand Down
8 changes: 6 additions & 2 deletions unit_tests/test_cover_plugin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import os
import sys
from optparse import OptionParser
from nose.config import Config
from nose.plugins.cover import Coverage
from nose.tools import eq_
import unittest


class TestCoveragePlugin(object):
Expand All @@ -14,6 +12,11 @@ def test_cover_options_packages(self):
['pkg1', 'pkg2', 'pkg3'], [],
'pkg1,pkg2,pkg3', 'NOSE_COVER_PACKAGE')

def test_cover_options_noprint(self):
_test_options_helper('--cover-no-print', 'coverPrint',
False, True,
env_key='NOSE_COVER_NO_PRINT')

def test_cover_options_erase(self):
_test_options_helper('--cover-erase', 'coverErase',
True, False,
Expand Down Expand Up @@ -63,6 +66,7 @@ def get_config_files(cov_info):
finally:
os.unlink('not_default_config_file')


def _test_options_helper(arg_option, cover_option,
expected_set, expected_not_set,
arg_value=None, env_key=None):
Expand Down

0 comments on commit 049b295

Please # to comment.