예제 #1
0
 def test_get_configured_plugins_with_dotfile_set_should_return_plugins(
         self, mockPath, mockOpen):
     mockPath.isfile.side_effect = lambda p: p == '.vigilance'
     mockOpen.return_value.__enter__.return_value = StringIO(
         '[vigilance]\n'
         'plugins = justone')
     self.assertEqual(['justone'], get_configured_plugins())
예제 #2
0
 def test_get_configured_plugins_with_setupcfg_set_should_return_plugins(
         self, mockPath, mockOpen):
     mockPath.isfile.side_effect = lambda p: p == 'setup.cfg'
     mockOpen.return_value.__enter__.return_value = StringIO(
         '[vigilance]\n'
         'plugins = one,andtwo')
     self.assertEqual(['one', 'andtwo'], get_configured_plugins())
예제 #3
0
 def test_get_configured_plugins_with_environment_variable_set_should_return_plugins(
         self, mockPath, _):
     mockPath.isfile.return_value = False
     with mock.patch.dict(
             os.environ, {'VIGILANCE_PLUGINS': 'firstone:cool,another:one'},
             clear=True):
         self.assertEqual(['firstone:cool', 'another:one'],
                          get_configured_plugins())
예제 #4
0
 def test_get_configured_plugins_with_malformed_setupcfg_should_log_warning(
         self, mockPath, mockOpen):
     mockPath.isfile.side_effect = lambda p: p == 'setup.cfg'
     mockOpen.return_value.__enter__.return_value = StringIO(
         '{uh oh not ini}')
     self.assertEqual([], get_configured_plugins())
     self.log.warning.assert_called_once_with(
         'Skipping malformed configuration file "%s"', 'setup.cfg')
예제 #5
0
 def test_get_configured_plugins_with_no_plugins_should_return_empty_list(self, mockPath, _):
     mockPath.isfile.return_value = False
     self.assertEqual([], get_configured_plugins())
     self.log.warning.assert_not_called()
예제 #6
0
"""@ingroup vigilance
@file
Contains the console API for Vigilance.
"""
import click
import six
import yaml

from voluptuous import Schema, Required, ALLOW_EXTRA
from voluptuous.error import Invalid
from vigilance.error import ConfigurationParsingError, UnknownSuite, ReportParsingError
from vigilance.plugin import get_configured_plugins, load_suites
from vigilance.suite import QualitySuite

load_suites(get_configured_plugins())

ConfigurationSchema = Schema({Required('suites'): {str:
                                                   Schema({Required('report'): str,
                                                           Required('constraints'):
                                                           Schema([Schema({Required('type'): str}, extra=ALLOW_EXTRA)])})}})

@click.command(short_help='Verify code coverage metrics against a set of constraints')
@click.option('--config', 'configFile', type=click.File(), default='vigilance.yaml', help='Path to the vigilance configuration file')
def main(configFile): #pylint: disable=missing-docstring, invalid-name
    """Runs Vigilance with the specified configuration file.
    The default configuration file if no options are passed is vigilance.yaml within the current working directory.
    """
    try:
        suites = ConfigurationSchema(yaml.full_load(configFile))['suites']
    except yaml.YAMLError:
        raise ConfigurationParsingError('Could not load configuration file as yaml')