Skip to content

Commit

Permalink
Add remove_page() method to Comic class (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpepple authored Sep 15, 2023
1 parent 3be37cd commit 5a09934
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions darkseid/comic.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ def remove_metadata(self: "Comic") -> bool:
return self._successful_write(write_success, False, None)
return True

def remove_page(self: "Comic", page_idx: int) -> bool:
"""Remove page from the archive."""
page = self.get_page_name(page_idx)
write_success = self.archiver.remove_file(page)
return self._successful_write(write_success, False, None)

def _successful_write(
self: "Comic",
write_success: bool,
Expand Down
21 changes: 21 additions & 0 deletions tests/test_comic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@
#######
# CBZ #
#######
def test_archive_delete_page(tmp_path: Path, fake_metadata: Metadata) -> None:
z_file = tmp_path / "test.cbz"
with zipfile.ZipFile(z_file, "w") as zf:
for p in IMG_DIR.iterdir():
zf.write(p)
# Prep test file
ca = Comic(z_file)
test_md = Metadata()
test_md.set_default_page_list(ca.get_number_of_pages())
test_md.overlay(fake_metadata)
ca.write_metadata(test_md)

old_num_pages = ca.get_number_of_pages()
result = ca.remove_page(1)
ca.get_page_name_list()
num_pages = ca.get_number_of_pages()
assert result is True
assert old_num_pages - 1 == num_pages
assert ca.has_metadata()


def test_archive_from_img_dir(tmp_path: Path, fake_metadata: Metadata) -> None:
z_file: Path = tmp_path / "Aquaman v1 #001 (of 08) (1994).cbz"
with zipfile.ZipFile(z_file, "w") as zf:
Expand Down

0 comments on commit 5a09934

Please sign in to comment.