def test_output_line_from_csv_error() -> None: with pytest.raises( MalformedOutputLineException, match="msg-symbolic-name:42:27:MyClass.my_function:The message", ): OutputLine.from_csv("'missing-docstring', 'line', 'column', 'obj', 'msg'") with pytest.raises( MalformedOutputLineException, match="symbol='missing-docstring' ?" ): csv = ("missing-docstring", "line", "column", "obj", "msg") OutputLine.from_csv(csv)
def test_output_line_from_csv() -> None: """Test that the OutputLine NamedTuple is instantiated correctly with from_csv. Test OutputLine of length 8. """ proper_csv = [ "missing-docstring", "1", "2", "1", "None", "obj", "msg", "HIGH", ] expected_column = 2 if PY38_PLUS else 0 output_line = OutputLine.from_csv(proper_csv) assert output_line == OutputLine( symbol="missing-docstring", lineno=1, column=expected_column, end_lineno=1, end_column=None, object="obj", msg="msg", confidence="HIGH", ) output_line_with_end = OutputLine.from_csv(proper_csv, True) assert output_line_with_end == OutputLine( symbol="missing-docstring", lineno=1, column=expected_column, end_lineno=1, end_column=None, object="obj", msg="msg", confidence="HIGH", ) output_line_without_end = OutputLine.from_csv(proper_csv, False) assert output_line_without_end == OutputLine( symbol="missing-docstring", lineno=1, column=expected_column, end_lineno=None, end_column=None, object="obj", msg="msg", confidence="HIGH", )
def test_output_line_from_csv_deprecated( confidence: Optional[str], expected_confidence: str ) -> None: """Test that the OutputLine NamedTuple is instantiated correctly with from_csv. Test OutputLine's of length 5 or 6. """ if confidence: proper_csv = [ "missing-docstring", "1", "2", "obj", "msg", confidence, ] else: proper_csv = ["missing-docstring", "1", "2", "obj", "msg"] with pytest.warns(DeprecationWarning) as records: output_line = OutputLine.from_csv(proper_csv, True) assert len(records) == 1 expected_column = 2 if PY38_PLUS else 0 assert output_line == OutputLine( symbol="missing-docstring", lineno=1, column=expected_column, end_lineno=None, end_column=None, object="obj", msg="msg", confidence=expected_confidence, )
def _get_expected(self): with self._open_source_file() as f: expected_msgs = self.get_expected_messages(f) if not expected_msgs: return Counter(), [] with self._open_expected_file() as f: expected_output_lines = [ OutputLine.from_csv(row) for row in csv.reader(f, "test") ] return expected_msgs, expected_output_lines
def _get_expected(self) -> Tuple["MessageCounter", List[OutputLine]]: with self._open_source_file() as f: expected_msgs = self.get_expected_messages(f) if not expected_msgs: expected_msgs = Counter() with self._open_expected_file() as f: expected_output_lines = [ OutputLine.from_csv(row) for row in csv.reader(f, "test") ] return expected_msgs, expected_output_lines
def _get_expected(self) -> tuple[MessageCounter, list[OutputLine]]: with self._open_source_file() as f: expected_msgs = self.get_expected_messages(f) if not expected_msgs: expected_msgs = Counter() with self._open_expected_file() as f: expected_output_lines = [ OutputLine.from_csv(row, self._check_end_position) for row in csv.reader(f, "test") ] return expected_msgs, expected_output_lines
def _get_expected(self): with self._open_source_file() as fobj: expected_msgs = self.get_expected_messages(fobj) if expected_msgs: with self._open_expected_file() as fobj: expected_output_lines = [ OutputLine.from_csv(row) for row in csv.reader(fobj, "test") ] else: expected_output_lines = [] return expected_msgs, expected_output_lines
def test_output_line_from_csv( confidence: Optional[str], expected_confidence: str ) -> None: if confidence: proper_csv = [ "missing-docstring", "1", "2", "obj", "msg", confidence, ] else: proper_csv = ["missing-docstring", "1", "2", "obj", "msg"] output_line = OutputLine.from_csv(proper_csv) expected_column = 2 if PY38_PLUS else 0 assert output_line == OutputLine( symbol="missing-docstring", lineno=1, column=expected_column, object="obj", msg="msg", confidence=expected_confidence, )
def test_output_line_from_csv_error() -> None: """Test that errors are correctly raised for incorrect OutputLine's.""" # Test a csv-string which does not have a number for line and column with pytest.warns( UserWarning, match="msg-symbolic-name:42:27:MyClass.my_function:The message", ): OutputLine.from_csv( "'missing-docstring', 'line', 'column', 'obj', 'msg'", True) # Test a tuple which does not have a number for line and column with pytest.warns(UserWarning, match="we got 'missing-docstring:line:column:obj:msg'"): csv = ("missing-docstring", "line", "column", "obj", "msg") OutputLine.from_csv(csv, True) # Test a csv-string that is too long with pytest.warns( UserWarning, match="msg-symbolic-name:42:27:MyClass.my_function:The message", ): OutputLine.from_csv( "'missing-docstring', 1, 2, 'obj', 'msg', 'func', 'message', 'conf', 'too_long'", True, )