def test_rename_file_invalid_name(self): build_info = BuildInfo(files={ "file1.txt": "contents", }) with pytest.raises(ValueError): build_info.rename_file("bad_name", "new_name")
def test_rename_file_success(self): build_info = BuildInfo(files={ "file1.txt": "contents", }) build_info.rename_file("file1.txt", "file2.txt") assert build_info.files == { "file2.txt": "contents", }
def test_rename_file_same_name(self): mock_files = unittest.mock.MagicMock() mock_files.__contains__.return_value = True build_info = BuildInfo(files=mock_files) build_info.rename_file("name", "name") mock_files.__getitem__.assert_not_called() mock_files.__delitem__.assert_not_called() mock_files.__setitem__.assert_not_called()
def build(self, build_info: BuildInfo): for file_name, file_info in build_info.get_files_by_pattern( self._match_pattern): try: permalink = self._permalink_selector(file_info) except Exception: continue if permalink.startswith("/"): permalink = permalink[1:] if permalink.endswith("/") or permalink == "": permalink += "index.html" build_info.rename_file(file_name, permalink)