def run_check_on_string(in_memory, root='.'): config = robocop.Config(root=root) robocop_runner = robocop.Robocop(config=config) robocop_runner.reload_config() ast_model = get_model(in_memory) return robocop_runner.run_check(ast_model, r'C:\directory\file.robot', in_memory)
def run_check_on_string(in_memory, root="."): config = robocop.Config(root=root) robocop_runner = robocop.Robocop(config=config) robocop_runner.reload_config() ast_model = get_model(in_memory) file_path = str(Path(Path.home(), "directory", "file.robot")) return robocop_runner.run_check(ast_model, file_path, in_memory)
def test_invalid_config(self): config_path = Path( Path(__file__).parent.parent, 'test_data', 'api_invalid_config') config = robocop.Config(root=config_path) with pytest.raises(InvalidArgumentError) as exception: robocop.Robocop(config=config) assert r'Invalid configuration for Robocop:\nunrecognized arguments: --some' in str( exception)
def test_robocop_api_no_trailing_blank_line_message(self): """ Bug from #307 """ source = "*** Test Cases ***\nTest\n Fail\n \nTest\n Fail\n" ast = get_model(source) config = robocop.Config() robocop_runner = robocop.Robocop(config=config) robocop_runner.reload_config() issues = robocop_runner.run_check(ast, 'target.robot', source) diag_issues = issues_to_lsp_diagnostic(issues) assert all( d["message"] != "Missing trailing blank line at the end of file" for d in diag_issues)
def test_run_check_in_memory(self): config = robocop.Config(root='.') robocop_runner = robocop.Robocop(config=config) robocop_runner.reload_config() in_memory = "*** Settings ***\n\n" ast_model = get_model(in_memory) issues = robocop_runner.run_check(ast_model, r'C:\directory\file.robot', in_memory) expected_issues = { 'Missing documentation in suite', 'Section is empty' } assert all(issue.desc in expected_issues for issue in issues)
def test_ignore_sys_argv(self, monkeypatch): monkeypatch.setattr("sys.argv", ["robocorp", "--some", "args.robot"]) config = robocop.Config() robocop_runner = robocop.Robocop(config=config) robocop_runner.reload_config() in_memory = "*** Settings ***\n\n" ast_model = get_model(in_memory) issues = robocop_runner.run_check(ast_model, r'C:\directory\file.robot', in_memory) expected_issues = { 'Missing documentation in suite', 'Section is empty' } assert all(issue.desc in expected_issues for issue in issues)
def test_run_check_in_memory_with_config(self): config_path = Path( Path(__file__).parent.parent, 'test_data', 'api_config') config = robocop.Config(root=config_path) robocop_runner = robocop.Robocop(config=config) robocop_runner.reload_config() in_memory = "*** Settings ***\n\n" ast_model = get_model(in_memory) issues = robocop_runner.run_check(ast_model, r'C:\directory\file.robot', in_memory) issues_by_desc = [issue.desc for issue in issues] assert 'Missing documentation in suite' in issues_by_desc assert 'Section is empty' not in issues_by_desc
def test_run_check_in_memory(self): config = robocop.Config(root='.') robocop_runner = robocop.Robocop(config=config) robocop_runner.reload_config() in_memory = "*** Settings ***\n\n" ast_model = get_model(in_memory) issues = robocop_runner.run_check(ast_model, r'C:\directory\file.robot', in_memory) expected_issues = { 'Missing documentation in suite', 'Section is empty', 'Too many blank lines at the end of file' } actual_issues = {issue.desc for issue in issues} assert expected_issues == actual_issues