Skip to content

Commit

Permalink
Fix page name list sort error
Browse files Browse the repository at this point in the history
Handle page name with mix of str & floats better
  • Loading branch information
bpepple committed Sep 30, 2020
1 parent a531614 commit a614e79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
12 changes: 2 additions & 10 deletions darkseid/comicarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pathlib import Path
from typing import List, Optional, Text

from natsort import natsorted
from natsort import natsorted, ns
from PIL import Image

from .comicinfoxml import ComicInfoXml
Expand Down Expand Up @@ -211,15 +211,7 @@ def get_page_name_list(self, sort_list: bool = True) -> List[str]:
# seems like some archive creators are on Windows, and don't know
# about case-sensitivity!
if sort_list:

def keyfunc(k):
# hack to account for some weird scanner ID pages
# basename=os.path.split(k)[1]
# if basename < '0':
# k = os.path.join(os.path.split(k)[0], "z" + basename)
return k.lower()

files = natsorted(files, key=keyfunc)
files = natsorted(files, alg=ns.IGNORECASE)

# make a sub-list of image files
self.page_list = []
Expand Down
13 changes: 8 additions & 5 deletions tests/test_darkseid_comicarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@ def test_metadata():

@pytest.fixture()
def fake_comic(tmp_path):
img_1 = tmp_path / "image-1.jpg"
img_1 = tmp_path / "MarvelTeam-Up058-00fc.jpg"
img_1.write_text(CONTENT)
img_2 = tmp_path / "image-2.jpg"
img_2 = tmp_path / "MarvelTeam-Up058-01.jpg"
img_2.write_text(CONTENT)
img_3 = tmp_path / "image-3.jpg"
img_3 = tmp_path / "MarvelTeam-Up058-02.jpg"
img_3.write_text(CONTENT)
img_4 = tmp_path / "MarvelTeam-Up058-LP.jpg"
img_4.write_text(CONTENT)

z_file = tmp_path / "Aquaman v1 #001 (of 08) (1994).cbz"
zf = zipfile.ZipFile(z_file, "w")
try:
zf.write(img_1)
zf.write(img_2)
zf.write(img_3)
zf.write(img_4)
finally:
zf.close()

Expand Down Expand Up @@ -63,7 +66,7 @@ def test_whether_text_file_is_comic_archive(tmp_path):
def test_archive_number_of_pages(fake_comic):
""" Test to determine number of pages in a comic archive """
res = fake_comic.get_number_of_pages()
assert res == 3
assert res == 4


def test_archive_is_writable(fake_comic):
Expand Down Expand Up @@ -138,4 +141,4 @@ def test_archive_apply_file_info_to_metadata(fake_comic):
test_md = GenericMetadata()
fake_comic.apply_archive_info_to_metadata(test_md)
# TODO: Need to test calculate page sizes
assert test_md.page_count == 3
assert test_md.page_count == 4

0 comments on commit a614e79

Please sign in to comment.