Example #1
0
    def test_cover_packages_option(self):
        parser = OptionParser()
        c = Coverage()
        c.addOptions(parser)
        options, args = parser.parse_args(['test_can_be_disabled',
                                           '--cover-package=pkg1,pkg2,pkg3'])
        c.configure(options, Config())
        eq_(['pkg1', 'pkg2', 'pkg3'], c.coverPackages)

        env = {'NOSE_COVER_PACKAGE': 'pkg1,pkg2,pkg3'}
        c = Coverage()
        parser = OptionParser()
        c.addOptions(parser, env)
        options, args = parser.parse_args(['test_can_be_disabled'])
        c.configure(options, Config())
        eq_(['pkg1', 'pkg2', 'pkg3'], c.coverPackages)
Example #2
0
    def test_cover_packages_option(self):
        parser = OptionParser()
        c = Coverage()
        c.addOptions(parser)
        options, args = parser.parse_args(
            ['test_can_be_disabled', '--cover-package=pkg1,pkg2,pkg3'])
        c.configure(options, Config())
        eq_(['pkg1', 'pkg2', 'pkg3'], c.coverPackages)

        env = {'NOSE_COVER_PACKAGE': 'pkg1,pkg2,pkg3'}
        c = Coverage()
        parser = OptionParser()
        c.addOptions(parser, env)
        options, args = parser.parse_args(['test_can_be_disabled'])
        c.configure(options, Config())
        eq_(['pkg1', 'pkg2', 'pkg3'], c.coverPackages)
Example #3
0
    def test_cover_package_suppress_stdout(self):
        """regression test to check that nose can run coverage with and 
        without suppression of stdout reporting"""
        parser = OptionParser()
        c = Coverage()
        c.addOptions(parser)
        options, args = parser.parse_args(['test_can_be_disabled',
                                           '--cover-package=pkg1,pkg2,pkg3'])
        c.configure(options, Config())
        eq_(['pkg1', 'pkg2', 'pkg3'], c.coverPackages)

        env = {'NOSE_COVER_PACKAGE': 'pkg1,pkg2,pkg3'}
        c = Coverage()
        parser = OptionParser()
        c.addOptions(parser, env)
        options, args = parser.parse_args(['test_can_be_disabled'])
        c.configure(options, Config())
        eq_(['pkg1', 'pkg2', 'pkg3'], c.coverPackages)

        env = {'NOSE_COVER_PACKAGE' : 'pkg1,pkg2,pkg3',
                'NOSE_COVER_SUPPRESS_STDOUT': True}
        c = Coverage()
        parser = OptionParser()
        c.addOptions(parser, env)
        options, args = parser.parse_args(['test_can_be_disabled'])
        c.configure(options, Config())
        eq_(['pkg1', 'pkg2', 'pkg3'], c.coverPackages)
Example #4
0
def _test_options_helper(arg_option,
                         cover_option,
                         expected_set,
                         expected_not_set,
                         arg_value=None,
                         env_key=None):
    prefix_args = ['test_can_be_disabled', '--with-coverage']

    # Assert that the default works as expected
    parser = OptionParser()
    c_arg_not_set = Coverage()
    c_arg_not_set.addOptions(parser)
    options, _ = parser.parse_args(prefix_args)
    c_arg_not_set.configure(options, Config())
    eq_(expected_not_set, getattr(c_arg_not_set, cover_option))

    # Assert that the argument parser picks up the expected value
    parser = OptionParser()
    c_arg_set = Coverage()
    c_arg_set.addOptions(parser)

    args = arg_option
    if arg_value is not None:
        args += '=' + arg_value

    options, _ = parser.parse_args(prefix_args + [args])
    c_arg_set.configure(options, Config())
    eq_(expected_set, getattr(c_arg_set, cover_option))

    # If the option supports environment variables, check that too
    if env_key is not None:
        args = 'true'
        if arg_value is not None:
            args = arg_value

        env = {env_key: args}
        c = Coverage()
        parser = OptionParser()
        c.addOptions(parser, env)
        options, _ = parser.parse_args(prefix_args)
        c.configure(options, Config())
        eq_(expected_set, getattr(c, cover_option))

    return c_arg_not_set, c_arg_set
Example #5
0
def _test_options_helper(arg_option, cover_option,
                         expected_set, expected_not_set,
                         arg_value=None, env_key=None):
    prefix_args = ['test_can_be_disabled', '--with-coverage']

    # Assert that the default works as expected
    parser = OptionParser()
    c_arg_not_set = Coverage()
    c_arg_not_set.addOptions(parser)
    options, _ = parser.parse_args(prefix_args)
    c_arg_not_set.configure(options, Config())
    eq_(expected_not_set, getattr(c_arg_not_set, cover_option))

    # Assert that the argument parser picks up the expected value
    parser = OptionParser()
    c_arg_set = Coverage()
    c_arg_set.addOptions(parser)

    args = arg_option
    if arg_value is not None:
        args += '=' + arg_value

    options, _ = parser.parse_args(prefix_args + [args])
    c_arg_set.configure(options, Config())
    eq_(expected_set, getattr(c_arg_set, cover_option))

    # If the option supports environment variables, check that too
    if env_key is not None:
        args = 'true'
        if arg_value is not None:
            args = arg_value

        env = {env_key: args}
        c = Coverage()
        parser = OptionParser()
        c.addOptions(parser, env)
        options, _ = parser.parse_args(prefix_args)
        c.configure(options, Config())
        eq_(expected_set, getattr(c, cover_option))

    return c_arg_not_set, c_arg_set
 def configure(self, options, config):
     Coverage.configure(self, options, config)
     self.coverage_summary = options.coverage_summary