def test_LintFileOnOpening(self): source = p.join(TEST_PROJECT, "basic_library", "clk_en_generator.vhd") with patch( "hdl_checker.lsp.Server.getMessagesByPath", return_value=[CheckerDiagnostic(filename=Path(source), text="some text")], ) as meth: self.assertCountEqual( self._checkLintFileOnOpen(source), [lsp.checkerDiagToLspDict(CheckerDiagnostic(text="some text"))], ) meth.assert_called_once_with(Path(source))
def test(): source = p.join(TEST_PROJECT, "another_library", "foo.vhd") with patch( "hdl_checker.lsp.Server.getMessagesByPath", return_value=[ CheckerDiagnostic(filename=Path(source), text="some text") ], ) as meth: it.assertCountEqual( checkLintFileOnOpen(source), [lsp.checkerDiagToLspDict(CheckerDiagnostic(text="some text"))], ) meth.assert_called_once_with(Path(source))
def test(): data = { "project_file": it.project_file, "path": p.join(TEST_PROJECT, "another_library", "foo.vhd"), "content": "-- TODO: Nothing to see here", } ui_reply = it.app.post("/get_ui_messages", data) reply = it.app.post("/get_messages_by_path", data) _logger.info("UI reply: %s", ui_reply) _logger.info("Reply: %s", reply) messages = [ CheckerDiagnostic.fromDict(x) for x in reply.json["messages"] ] it.assertIn(data["path"], [x.filename for x in messages]) expected = StaticCheckerDiag( filename=data["path"], line_number=0, column_number=3, text="TODO: Nothing to see here", severity=DiagType.STYLE_INFO, ) it.assertIn(expected, messages)
def test_converting_to_lsp(self, diag_type, severity): # type: (...) -> Any _logger.info("Running %s and %s", diag_type, severity) diag = CheckerDiagnostic( checker="hdl_checker test", text="some diag", filename=Path("filename"), line_number=0, column_number=0, error_code="error code", severity=diag_type, ) self.assertEqual( lsp.checkerDiagToLspDict(diag), { "source": "hdl_checker test", "range": { "start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 0}, }, "message": "some diag", "severity": severity, "code": "error code", }, )
def test(meth): filename = p.join(TEST_PROJECT, "basic_library", "clock_divider.vhd") data = {"project_file": it.project_file, "path": filename} ui_reply = it.app.post("/get_ui_messages", data) reply = it.app.post("/get_messages_by_path", data) meth.assert_called_once() _logger.info("UI reply: %s", ui_reply) _logger.info("Reply: %s", reply) it.assertCountEqual(reply.json["messages"], [CheckerDiagnostic(text="some text").toDict()])
def test(meth): _logger.info("Files: %s", it.project.database._paths) source = _SourceMock( filename=_path("some_lib_target.vhd"), library="some_lib", design_units=[{ "name": "target", "type": "entity" }], dependencies={("work", "foo")}, ) it.assertIn( CheckerDiagnostic(filename=Path(source.filename), text="some text"), it.project.getMessagesByPath(source.filename), ) # Will be called with the file's contents meth.assert_called_once()
it.assertIn(data["path"], [x.filename for x in messages]) expected = StaticCheckerDiag( filename=data["path"], line_number=0, column_number=3, text="TODO: Nothing to see here", severity=DiagType.STYLE_INFO, ) it.assertIn(expected, messages) @it.should("get messages by path") # type: ignore @patch( "hdl_checker.handlers.Server.getMessagesByPath", return_value=[CheckerDiagnostic(text="some text")], ) def test(meth): filename = p.join(TEST_PROJECT, "basic_library", "clock_divider.vhd") data = {"project_file": it.project_file, "path": filename} ui_reply = it.app.post("/get_ui_messages", data) reply = it.app.post("/get_messages_by_path", data) meth.assert_called_once() _logger.info("UI reply: %s", ui_reply) _logger.info("Reply: %s", reply) it.assertCountEqual(reply.json["messages"], [CheckerDiagnostic(text="some text").toDict()])
def test(_): with PatchBuilder(): it.project.setConfig(Path(p.join(TEST_PROJECT, "vimhdl.prj"))) it.project._updateConfigIfNeeded() entity_a = _SourceMock( filename=_path("entity_a.vhd"), library="some_lib", design_units=[{ "name": "entity_a", "type": "entity" }], dependencies={("work", "foo")}, ) path_to_foo = Path( p.join(TEST_PROJECT, "another_library", "foo.vhd")) diags = { # entity_a.vhd is the path we're compiling, inject a diagnostic # from the builder str(entity_a.filename): [[ CheckerDiagnostic(filename=entity_a.filename, checker=None, text="some text") ]], # foo.vhd is on the build sequence, check that diagnostics from # the build sequence are only included when their severity is # DiagType.ERROR str(path_to_foo): [[ CheckerDiagnostic( filename=path_to_foo, checker=None, text="should not be included", severity=DiagType.WARNING, ), CheckerDiagnostic( filename=path_to_foo, checker=None, text="style error should be included", severity=DiagType.STYLE_ERROR, ), CheckerDiagnostic( filename=path_to_foo, checker=None, text="should be included", severity=DiagType.ERROR, ), ]], } def build( # pylint: disable=unused-argument path, library, scope, forced=False): _logger.debug("Building library=%s, path=%s", library, path) path_diags = diags.get(str(path), []) if path_diags: return path_diags.pop(), [] return [], [] with patch.object(it.project.builder, "build", build): _logger.info("Project paths: %s", it.project.database._paths) messages = list(it.project.getMessagesByPath( entity_a.filename)) logIterable("Messages", messages, _logger.info) it.assertCountEqual( messages, [ LibraryShouldBeOmited( library="work", filename=entity_a.filename, column_number=8, line_number=0, ), PathNotInProjectFile(entity_a.filename), CheckerDiagnostic(filename=entity_a.filename, checker=None, text="some text"), CheckerDiagnostic( filename=path_to_foo, checker=None, text="style error should be included", severity=DiagType.STYLE_ERROR, ), CheckerDiagnostic( filename=path_to_foo, checker=None, text="should be included", severity=DiagType.ERROR, ), ], )