Пример #1
0
    def test_IgnoresJsonDecodingErrors(self):
        search_paths = (self._path("incl_0.json"), )

        open(self._path("incl_0.json"), "w").write("hello")

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

        _logger.info("Result:\n%s", pformat(result))
        self.assertCountEqual(result, ())
Пример #2
0
    def test_IncludeFolderShouldSearch(self):
        # type: (...) -> None
        folder = mkdtemp()

        with patch("hdl_checker.parser_utils.findRtlSourcesByPath") as meth:
            meth.return_value = ["sources.vhd"]
            result = list(getIncludedConfigs((folder, ), self.base_path))
            meth.assert_called_once_with(Path(folder))

        _logger.info("Result:\n%s", pformat(result))
        self.assertCountEqual(result, [(folder, {
            "sources": ("sources.vhd", )
        })])
Пример #3
0
    def test_IncludeFolderShouldUseConfigFileIfPossible(self):
        # type: (...) -> None
        folder = mkdtemp()
        config_file = p.join(folder, DEFAULT_PROJECT_FILE)
        open(config_file, "w").close()
        _logger.info("folder=%s, config_file=%s", folder, config_file)

        with patch("hdl_checker.parser_utils.json.load") as load:
            load.return_value = {"foo": "bar"}
            result = list(getIncludedConfigs((folder, ), self.base_path))

        _logger.info("Result:\n%s", pformat(result))
        self.assertCountEqual(result, [(folder, {"foo": "bar"})])
Пример #4
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"}), ))
Пример #5
0
    def test_DirectInclusion(self):
        incl_0 = self._path("incl_0.json")
        incl_1 = self._path("incl_1.json")
        incl_2 = self._path("incl_2.json")
        incl_3 = self._path("incl_3.json")
        #  incl_4 = self._path('incl_4.json')

        search_paths = (incl_0, "incl_1.json")

        # Direct inclusion
        json_dump({"include": (incl_1, ), "name": "incl_0"}, open(incl_0, "w"))
        # Direct multiple inclusion
        json_dump({
            "include": (incl_2, incl_3),
            "name": "incl_1"
        }, open(incl_1, "w"))
        # No inclusion (enpoints)
        json_dump({"name": "incl_2"}, open(incl_2, "w"))
        json_dump({"name": "incl_3"}, open(incl_3, "w"))

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

        _logger.info("Result:\n%s", pformat(result))
        self.assertCountEqual(
            result,
            (
                (self.base_path, {
                    "name": "incl_0"
                }),
                (self.base_path, {
                    "name": "incl_1"
                }),
                (self.base_path, {
                    "name": "incl_2"
                }),
                (self.base_path, {
                    "name": "incl_3"
                }),
            ),
        )
Пример #6
0
    def test_RecursiveInclusion(self):
        incl_0 = self._path("incl_0.json")
        incl_1 = self._path("incl_1.json")

        search_paths = (incl_0, )

        json_dump({"include": (incl_1, ), "name": "incl_0"}, open(incl_0, "w"))
        json_dump({"include": (incl_0, ), "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_0"
                }),
                (self.base_path, {
                    "name": "incl_1"
                }),
            ),
        )