コード例 #1
0
ファイル: test.py プロジェクト: lvcargnini/hammer
    def test_prepend_dir_path(self) -> None:
        tech_json = {
            "name":
            "My Technology Library",
            "installs": [{
                "path": "test",
                "base var": ""  # means relative to tech dir
            }],
            "libraries": []
        }

        tech_dir = "/tmp/path"  # should not be used
        tech = hammer_tech.HammerTechnology.load_from_json(
            "dummy28", json.dumps(tech_json, indent=2), tech_dir)

        # Check that a tech-provided prefix works fine
        self.assertEqual("{0}/water".format(tech_dir),
                         tech.prepend_dir_path("test/water"))
        self.assertEqual("{0}/fruit".format(tech_dir),
                         tech.prepend_dir_path("test/fruit"))

        # Check that a non-existent prefix gives an error
        with self.assertRaises(ValueError):
            tech.prepend_dir_path("badprefix/file")

        # Check that a lib's custom prefix works
        from hammer_vlsi.hammer_tool import ExtraLibrary
        lib = ExtraLibrary(library=hammer_tech.library_from_json(
            """{"milkyway techfile": "custom/chair"}"""),
                           prefix=hammer_tech.PathPrefix(
                               prefix="custom",
                               path="/tmp/custom")).store_into_library()
        self.assertEqual("{0}/hat".format("/tmp/custom"),
                         tech.prepend_dir_path("custom/hat", lib))
コード例 #2
0
    def test_extra_prefixes(self) -> None:
        """
        Test that extra_prefixes works properly as a property.
        """
        lib = hammer_tech.library_from_json('{"openaccess techfile": "test/oa"}')  # type: hammer_tech.Library

        prefixes_orig = [hammer_tech.PathPrefix(prefix="test", path="/tmp/test")]

        prefixes = [hammer_tech.PathPrefix(prefix="test", path="/tmp/test")]
        lib.extra_prefixes = prefixes
        # Check that we get the original back even after mutating the original list.
        prefixes.append(hammer_tech.PathPrefix(prefix="bar", path="/tmp/bar"))
        self.assertEqual(lib.extra_prefixes, prefixes_orig)

        prefixes2 = lib.extra_prefixes
        # Check that we don't mutate the copy stored in the lib if we mutate after getting it
        prefixes2.append(hammer_tech.PathPrefix(prefix="bar", path="/tmp/bar"))
        self.assertEqual(lib.extra_prefixes, prefixes_orig)