Example #1
0
    def test(parse_builtins):
        # type: (...) -> None
        root = tempfile.mkdtemp()
        server = DummyServer(Path(root))

        with tempfile.NamedTemporaryFile(suffix=".vhd") as filename:
            diags = server.getMessagesWithText(
                Path(filename.name),
                "library lib; use lib.pkg.all; library builtin; use builtin.foo;",
            )

            parse_builtins.assert_called()

            logIterable("Diags", diags, _logger.info)

            it.assertCountEqual(
                diags,
                [
                    UnresolvedDependency(
                        RequiredDesignUnit(
                            name=Identifier("pkg"),
                            library=Identifier("lib"),
                            owner=Path(filename.name),
                            locations=[Location(0, 17)],
                        ),
                        Location(0, 17),
                    )
                ],
            )
Example #2
0
        def test(handle_ui_warning):
            it.project._saveCache()
            # Copy parameters of the object we're checking against
            root_dir = it.project.root_dir
            cache_filename = it.project._getCacheFilename()

            # Corrupt the cache file
            open(cache_filename.name, "w").write("corrupted cache contents")

            # Try to recreate
            project = DummyServer(root_dir)

            if six.PY2:
                it.assertIn(
                    call("Unable to recover cache from '{}': "
                         "No JSON object could be decoded".format(
                             cache_filename)),
                    handle_ui_warning.mock_calls,
                )
                it.assertIn(
                    call(hdl_checker.base_server._PYTHON_27_WARNING_MSG),
                    handle_ui_warning.mock_calls,
                )
            else:
                handle_ui_warning.assert_called_once_with(
                    "Unable to recover cache from '{}': "
                    "Expecting value: line 1 column 1 (char 0)".format(
                        cache_filename))

            it.assertIsInstance(project.builder, Fallback)
Example #3
0
        def test():
            it.project._saveCache()

            _ = DummyServer(_Path(TEST_TEMP_PATH))

            # Setting the config file should not trigger reparsing
            with patch("hdl_checker.base_server.WatchedFile.__init__",
                       side_effect=[None]) as watched_file:
                old = it.project.config_file
                it.project.setConfig(it.config_file)
                it.project._updateConfigIfNeeded()
                it.assertEqual(it.project.config_file, old)
                watched_file.assert_not_called()
                it.assertIsNotNone(it.project.config_file)
Example #4
0
        def setup(handle_ui_info):
            setupTestSuport(TEST_TEMP_PATH)

            removeIfExists(p.join(TEST_TEMP_PATH, WORK_PATH, CACHE_NAME))

            with PatchBuilder():
                it.project = DummyServer(_Path(TEST_TEMP_PATH))
                it.project.setConfig(Path(p.join(TEST_PROJECT, "vimhdl.prj")))
                it.project._updateConfigIfNeeded()
                handle_ui_info.assert_called_once_with("Added 10 sources")

            _logger.info("Database state:\n%s",
                         pformat(it.project.database.__jsonEncode__()))

            it.assertTrue(it.project.database.paths)
            it.assertIsInstance(it.project.builder, MockBuilder)
Example #5
0
        def setup():
            setupTestSuport(TEST_TEMP_PATH)

            it.project = DummyServer(_Path(TEST_TEMP_PATH))

            it.config_file = _makeConfigFromDict({
                "builder": MockBuilder.builder_name,
                FileType.vhdl.value: {
                    "flags": {
                        BuildFlagScope.all.value: (
                            "-globalvhdl",
                            "-global-vhdl-flag",
                        ),
                        BuildFlagScope.dependencies.value: ("--vhdl-batch", ),
                        BuildFlagScope.single.value:
                        ("-single_build_flag_0", ),
                    }
                },
                FileType.verilog.value: {
                    "flags": {
                        BuildFlagScope.all.value: (
                            "-globalverilog",
                            "-global-verilog-flag",
                        ),
                        BuildFlagScope.dependencies.value:
                        ("--verilog-batch", ),
                        BuildFlagScope.single.value:
                        ("-single_build_flag_0", ),
                    }
                },
                FileType.systemverilog.value: {
                    "flags": {
                        BuildFlagScope.all.value: (
                            "-globalsystemverilog",
                            "-global-systemverilog-flag",
                        ),
                        BuildFlagScope.dependencies.value:
                        ("--systemverilog-batch", ),
                        BuildFlagScope.single.value:
                        ("-single_build_flag_0", ),
                    }
                },
            })

            it.project.setConfig(it.config_file)
Example #6
0
    def test(handle_ui_info):
        path = tempfile.mkdtemp()

        config = p.join(path, "config.json")
        source = p.join(path, "source.vhd")

        # Make sure the files exists
        open(config, "w").write("")
        open(source, "w").write("")

        project = DummyServer(_Path(path))
        project.setConfig(Path(config))
        # Get messages of anything to trigger reading the config
        project.getMessagesByPath(Path(source))

        handle_ui_info.assert_called_once_with("No sources were added")

        removeIfExists(path)
    def test(handle_ui_info):

        path = tempfile.mkdtemp()

        config = p.join(path, "config.json")
        source = p.join(path, "source.vhd")

        # Make sure the files exist
        open(config, "w").write("")
        open(source, "w").write("")

        project = DummyServer(_Path(path))
        project.setConfig(_Path(config), origin=ConfigFileOrigin.generated)
        # Get messages of anything to trigger reading the config
        project.getMessagesByPath(Path(source))

        handle_ui_info.assert_called_once_with(
            hdl_checker.base_server._HOW_LONG_IS_TOO_LONG_MSG)

        removeIfExists(path)
Example #8
0
        def test(set_state):
            source = _SourceMock(library="some_lib",
                                 design_units=[{
                                     "name": "target",
                                     "type": "entity"
                                 }])

            it.project.getMessagesByPath(source.filename)

            _ = DummyServer(_Path(TEST_TEMP_PATH))

            set_state.assert_called_once()

            # Setting the config file should not trigger reparsing
            with patch("hdl_checker.base_server.WatchedFile.__init__",
                       side_effect=[None]) as watched_file:
                old = it.project.config_file
                it.project.setConfig(it.config_file)
                it.project._updateConfigIfNeeded()
                it.assertEqual(it.project.config_file, old)
                watched_file.assert_not_called()
                it.assertIsNotNone(it.project.config_file)
Example #9
0
 def setup():
     it.project = DummyServer(Path(TEST_PROJECT))
Example #10
0
 def test():
     project = DummyServer(_Path("nonexisting"))
     with it.assertRaises(FileNotFoundError):
         project.setConfig(str(it.project_file))