Exemplo n.º 1
0
    def test_get_file_from_repo_local(self):
        with tempfile.TemporaryDirectory() as tmp_dir:
            filename = Path(tmp_dir) / "a.txt"
            filename.touch()
            self.assertEqual(get_file_from_repo(tmp_dir, "a.txt"),
                             str(filename))

            self.assertIsNone(get_file_from_repo(tmp_dir, "b.txt"))
Exemplo n.º 2
0
    def test_get_file_from_repo_distant(self):
        # `get_file_from_repo` returns None if the file does not exist
        self.assertIsNone(get_file_from_repo("bert-base-cased", "ahah.txt"))

        # The function raises if the repository does not exist.
        with self.assertRaisesRegex(EnvironmentError,
                                    "is not a valid model identifier"):
            get_file_from_repo("bert-base-case", "config.json")

        # The function raises if the revision does not exist.
        with self.assertRaisesRegex(EnvironmentError,
                                    "is not a valid git identifier"):
            get_file_from_repo("bert-base-cased",
                               "config.json",
                               revision="ahaha")

        resolved_file = get_file_from_repo("bert-base-cased", "config.json")
        # The name is the cached name which is not very easy to test, so instead we load the content.
        config = json.loads(open(resolved_file, "r").read())
        self.assertEqual(config["hidden_size"], 768)