Esempio n. 1
0
    def getMessagesWithText(self, path, content):
        # type: (Path, AnyStr) -> Iterable[CheckerDiagnostic]
        """
        Dumps content to a temprary file and replaces the temporary file name
        for path on the diagnostics received
        """
        with self._lock:
            _logger.info("Getting messages for '%s' with content", path)

            ext = path.name.split(".")[-1]
            temporary_file = tempfile.NamedTemporaryFile(suffix="." + ext,
                                                         delete=False)

            temp_path = TemporaryPath(temporary_file.name)

            temporary_file.file.write(toBytes(content))  # type: ignore
            temporary_file.close()

            # If the reference path was added to the database, add the
            # temporary file with the same attributes
            if path in self.database.paths:
                library = self.database.getLibrary(path)
                self.database.addSource(
                    temp_path,
                    getattr(library, "display_name", None),
                    self.database.getFlags(path, BuildFlagScope.single),
                    self.database.getFlags(path, BuildFlagScope.dependencies),
                )

            diags = set()  # type: Set[CheckerDiagnostic]

            # Some messages may not include the filename field when checking a
            # file by content. In this case, we'll assume the empty filenames
            # refer to the same filename we got in the first place
            for diag in self.getMessagesByPath(temp_path):
                if diag.filename in (temp_path, None):
                    diag = diag.copy(
                        text=diag.text.replace(temporary_file.name, path.name),
                        filename=path,
                    )

                diags.add(diag)

            diags |= set(self.database.getDiagnosticsForPath(temporary_file))

            self.database.removeSource(temp_path)
            removeIfExists(temporary_file.name)

            if self.config_file and path not in self.database.paths:
                diags.add(PathNotInProjectFile(path))

        return diags
Esempio n. 2
0
    def test_IgnoresNonExistingFiles(self):
        incl_0 = self._path("incl_0.json")
        incl_1 = self._path("incl_1.json")

        search_paths = (incl_0, incl_1)

        removeIfExists(incl_0)
        json_dump({"name": "incl_1"}, open(incl_1, "w"))

        result = list(getIncludedConfigs(search_paths, self.base_path))

        _logger.info("Result:\n%s", pformat(result))
        self.assertCountEqual(result, ((self.base_path, {"name": "incl_1"}), ))
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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 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)