def test_lsp_diagnostic(self, rule): issues = [ Message( rule=rule, msg=rule.get_message(), source=r"C:\directory\file.robot", node=None, lineno=10, col=10, end_lineno=11, end_col=50, ), Message( rule=rule, msg=rule.get_message(), source=r"C:\directory\file.robot", node=None, lineno=1, col=1, end_lineno=None, end_col=None, ), ] expected_diagnostic = [ { "range": { "start": {"line": 9, "character": 9}, "end": {"line": 10, "character": 49}, }, "severity": 2, "code": "0101", "source": "robocop", "message": "Some description", "codeDescription": { "href": f"https://robocop.readthedocs.io/en/{__version__}/rules.html#some-message", }, }, { "range": { "start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 0}, }, "severity": 2, "code": "0101", "source": "robocop", "message": "Some description", "codeDescription": { "href": f"https://robocop.readthedocs.io/en/{__version__}/rules.html#some-message", }, }, ] diagnostic = issues_to_lsp_diagnostic(issues) assert diagnostic == expected_diagnostic
def test_lsp_diagnostic(self, rule): issues = [ Message(rule=rule, source=r'C:\directory\file.robot', node=None, lineno=10, col=10, end_lineno=11, end_col=50), Message(rule=rule, source=r'C:\directory\file.robot', node=None, lineno=1, col=1, end_lineno=None, end_col=None) ] expected_diagnostic = [{ 'range': { 'start': { 'line': 9, 'character': 10 }, 'end': { 'line': 10, 'character': 50 } }, 'severity': 2, 'code': '0101', 'source': 'robocop', 'message': 'Some description' }, { 'range': { 'start': { 'line': 0, 'character': 1 }, 'end': { 'line': 0, 'character': 1 } }, 'severity': 2, 'code': '0101', 'source': 'robocop', 'message': 'Some description' }] diagnostic = issues_to_lsp_diagnostic(issues) assert diagnostic == expected_diagnostic
def test_file_stats_report(self, files, files_with_issues, output, message): report = FileStatsReport() report.files_count = files report.files_with_issues = files_with_issues issue = Message(rule=message, source='some/path/file.robot', node=None, lineno=50, col=10) report.add_message(issue) assert report.get_report() == output
def test_timestamp_report(self, message): report = TimestampReport() issue = Message( rule=message, msg=message.get_message(), source="some/path/file.robot", node=None, lineno=50, col=10, end_lineno=None, end_col=None, ) report.add_message(issue) assert "Reported: " in report.get_report()
def test_version_report(self, message): report = RobocopVersionReport() issue = Message( rule=message, msg=message.get_message(), source="some/path/file.robot", node=None, lineno=50, col=10, end_lineno=None, end_col=None, ) report.add_message(issue) assert __version__ in report.get_report()
def test_json_report(self, message): report = JsonReport() issue = Message(rule=message, source='some/path/file.robot', node=None, lineno=50, col=10) report.add_message(issue) assert report.issues[0] == { 'source': 'some/path/file.robot', 'column': 10, 'line': 50, 'rule_id': '0101', 'rule_name': 'some-message', 'severity': 'W', 'description': 'Some description' }
def test_file_stats_report(self, files, files_with_issues, output, message): report = FileStatsReport() report.files_count = files report.files_with_issues = files_with_issues if files_with_issues: issue = Message( rule=message, msg=message.get_message(), source="some/path/file.robot", node=None, lineno=50, col=10, end_lineno=None, end_col=None, ) report.add_message(issue) assert report.get_report() == output
def message(): rule = Rule( RuleParam(name="param_name", converter=int, default=1, desc=""), rule_id="1010", name="somerule", msg="Some description", severity=RuleSeverity.WARNING, ) return Message( rule=rule, msg=rule.get_message(), source=None, node=None, lineno=None, col=None, end_lineno=None, end_col=None, )
def test_json_report(self, message): report = JsonReport() issue = Message( rule=message, msg=message.get_message(), source="some/path/file.robot", node=None, lineno=50, col=10, end_lineno=None, end_col=None, ) report.add_message(issue) assert report.issues[0] == { "source": "some/path/file.robot", "column": 10, "line": 50, "rule_id": "0101", "rule_name": "some-message", "severity": "W", "description": "Some description", }
def add_message(self, message: Message): # noqa self.message_counter[message.get_fullname()] += 1
def add_message(self, message: Message): self.issues.append(message.to_json())