def test_run_with_return_status_0(self, robocop_instance): config = Config() config.parse_opts([ '-c', 'return_status:quality_gate:E=-1:W=-1', str(Path(Path(__file__).parent.parent, 'test_data')) ]) robocop_instance.config = config robocop_instance.configure_checkers_or_reports() with pytest.raises(SystemExit): robocop_instance.run() for report in robocop_instance.reports: if report.name == 'return_status': assert report.return_status == 0
def test_append_config_pyproject_file(self, path_to_test_data): src = path_to_test_data / "only_pyproject" with working_directory(src), patch.object(sys, "argv", [ "prog", "--configure", "too-many-calls-in-keyword:max_calls:20", "--exclude", "0810" ]): config = Config(from_cli=True) assert {"0203", "0810"} == config.exclude assert [ "line-too-long:line_length:150", "0201:severity:E", "too-many-calls-in-keyword:max_calls:20", ] == config.configure
def __init__(self, from_cli=False, config=None): self.files = {} self.checkers = [] self.rules = {} self.reports = dict() self.disabler = None self.root = os.getcwd() self.config = Config() if config is None else config self.from_cli = from_cli if from_cli: self.config.parse_opts() else: self.config.reports.add('json_report') self.out = self.set_output()
def test_ignore_file_with_pattern(self, robocop_instance): config = Config() config.parse_opts([ '--ignore', '*.robot', '--include', '0502', str(Path(Path(__file__).parent.parent, 'test_data')) ]) robocop_instance.config = config robocop_instance.checkers = [] robocop_instance.rules = {} robocop_instance.load_checkers() with pytest.raises(SystemExit): robocop_instance.run()
def __init__(self, from_cli=False): self.files = {} self.checkers = [] self.out = sys.stdout self.rules = {} self.reports = [] self.disabler = None self.config = Config() if from_cli: self.config.parse_opts() self.set_output() self.load_checkers() self.list_checkers() self.load_reports() self.configure_checkers_or_reports()
def configure_robocop_with_rule(args, runner, rule, path): runner.from_cli = True config = Config() config.parse_opts([ "--include", rule, "--format", "{source}:{line}:{col} [{severity}] {rule_id} {desc}", "--configure", "return_status:quality_gate:E=0:W=0:I=0", *args, str(path), ]) runner.config = config return runner
def configure_robocop_with_rule(runner, rule, path): config = Config() config.parse_opts([ '--include', rule, '--format', '{source}:{line}:{col} [{severity}] {rule_id} {desc}', '--configure', 'return_status:quality_gate:E=0:W=0:I=0', str(path) ]) runner.config = config runner.checkers = [] runner.rules = {} runner.load_checkers() runner.load_reports() runner.configure_checkers_or_reports() return runner
def __init__(self, from_cli=False, config=None): self.files = {} self.checkers = [] self.rules = {} self.reports = dict() self.disabler = None self.root = os.getcwd() self.config = Config(from_cli=from_cli) if config is None else config self.from_cli = from_cli self.config.parse_opts(from_cli=from_cli) if not from_cli: self.config.reports.add('json_report') self.out = self.set_output() if from_cli: print( "### DEPRECATION WARNING: The rule '0906' (redundant-equal-sign) is " "deprecated starting from Robocop 1.7.0 and is replaced by 0909 (inconsistent-assignment) and " "0910 (inconsistent-assignment-in-variables). " "Rule '0906' will be removed in the next release - update your configuration. ###\n" )
def test_argument_file_without_path(self): config = Config() with pytest.raises(ArgumentFileNotFoundError) as err: config.parse_opts(['--argumentfile']) assert 'Argument file "" does not exist' in str(err)
def test_load_config_with_comments(self, path_to_test_data): src = path_to_test_data / "config_with_comments" with working_directory(src), patch.object(sys, "argv", ["prog"]): Config()
def test_invalid_config(self): config_path = Path(Path(__file__).parent.parent, "test_data", "api_invalid_config") with pytest.raises(InvalidArgumentError) as exception: Config(root=config_path) assert r"Invalid configuration for Robocop:\nunrecognized arguments: --some" in str(exception)
def config(): return Config()
def test_set_rule_threshold(self, threshold, robocop_instance, test_data_dir): with mock.patch.object(sys, "argv", f"robocop --threshold {threshold}".split()): Config(from_cli=True)
def test_use_argument_file(self, robocop_instance, test_data_dir): config = Config() config.parse_opts( ["-A", str(test_data_dir / "argument_file" / "args.txt")])
def test_load_config_from_default_file(self, path_to_test_data): src = path_to_test_data / "default_config" with working_directory(src), patch.object(sys, "argv", ["prog"]): config = Config(from_cli=True) assert {"0810"} == config.include
def test_load_config_with_format_option(self, path_to_test_data): src = path_to_test_data / "config_with_format" with working_directory(src), patch.object(sys, "argv", ["prog"]): config = Config() assert '"{source}:{line}:{col} [{severity}] {rule_id} {desc} ({name})"' == config.format.strip( )
def test_paths_from_gitignore_ignored(self): test_dir = Path(__file__).parent.parent / "test_data" / "gitignore" config = Config() config.paths = {str(test_dir)} files = list(get_files(config)) assert sorted(files) == [test_dir / "allowed" / "allowed_file.robot", test_dir / "allowed_file.robot"]
def test_load_default_config_before_pyproject(self, path_to_test_data): src = path_to_test_data / "default_config_and_pyproject" with working_directory(src), patch.object(sys, "argv", ["prog"]): config = Config() assert {"0810"} == config.include
def test_run_all_checkers(self, robocop_instance): config = Config() config.parse_opts([str(Path(Path(__file__).parent.parent, 'test_data'))]) robocop_instance.config = config with pytest.raises(SystemExit): robocop_instance.run()
def setUp(self): self.config = Config()
def test_use_not_existing_argument_file(self): config = Config() with pytest.raises(ArgumentFileNotFoundError) as err: config.parse_opts(['--argumentfile', 'some_file', str(Path(Path(__file__).parent.parent, 'test_data'))]) assert 'Argument file "some_file" does not exist' in str(err)