From 096a89eab4664812c0b809e4f19148aa81d7fa75 Mon Sep 17 00:00:00 2001 From: Davide Romanini Date: Sat, 19 Oct 2019 23:57:49 +0200 Subject: [PATCH 1/6] add pytest --- comicapi/comicarchive.py | 6 ++---- requirements_dev.txt | 1 + tests/fake_cbr.cbr | Bin 0 -> 408 bytes tests/test_comicarchive.py | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 requirements_dev.txt create mode 100644 tests/fake_cbr.cbr create mode 100644 tests/test_comicarchive.py diff --git a/comicapi/comicarchive.py b/comicapi/comicarchive.py index 11ecd86..0fc6fee 100644 --- a/comicapi/comicarchive.py +++ b/comicapi/comicarchive.py @@ -24,7 +24,7 @@ import platform import time import io -from natsort import natsorted +from natsort import natsorted, ns from PyPDF2 import PdfFileReader from unrar.cffi import rarfile try: @@ -597,7 +597,6 @@ class ComicArchive: self.archiver = PdfArchiver(self.path) if ComicArchive.logo_data is None: - #fname = ComicTaggerSettings.getGraphic('nocover.png') fname = self.default_image_path with open(fname, 'rb') as fd: ComicArchive.logo_data = fd.read() @@ -804,7 +803,6 @@ class ComicArchive: if self.page_list is None: # get the list file names in the archive, and sort files = self.archiver.getArchiveFilenameList() - # seems like some archive creators are on Windows, and don't know # about case-sensitivity! if sort_list: @@ -815,7 +813,7 @@ class ComicArchive: # k = os.path.join(os.path.split(k)[0], "z" + basename) return k.lower() - files = natsorted(files, key=keyfunc, signed=False) + files = natsorted(files, key=keyfunc, alg=ns.UNSIGNED) # make a sub-list of image files self.page_list = [] diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..d7ac816 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1 @@ +pytest==5.2.1 \ No newline at end of file diff --git a/tests/fake_cbr.cbr b/tests/fake_cbr.cbr new file mode 100644 index 0000000000000000000000000000000000000000..1157aecbc8d43cea4472b39769d5a3277d80f210 GIT binary patch literal 408 zcmWGaEK-zWXJq*Nu<127BP%-t8zW;wLj%K0y*(GSn3%bn7+9JZwlp&Z{|QWQU|{6Y z%S_M9FG@|(%PL6cVitbUvO2a@;va({m&+{477a`dTmgycsfIw+sUYP)fXan5Pe~eb zg=R2is$(kWEC4DufExZDsCuz;o2DVx*EhRrH8E9l!yHpmQ35pmHBkM>JNZ0@Tt*2` zCSr38$aF)P@t=XpUr)(lGUS?Tc32pjV?b^<(ksXVIsG?KwVt%5kRjLNzkg@pQf;i4 zo|y(z{U50M$A>&^L#_(uySs5Y#YC?>HK_oooTYVj?Amf!VM8w2@~}W=Ru%>T4xoVg literal 0 HcmV?d00001 diff --git a/tests/test_comicarchive.py b/tests/test_comicarchive.py new file mode 100644 index 0000000..d6f0604 --- /dev/null +++ b/tests/test_comicarchive.py @@ -0,0 +1,18 @@ +from os.path import dirname, abspath, join +from comicapi.comicarchive import ComicArchive + +__dir__ = dirname(abspath(__file__)) + +def test_getPageNameList(): + ComicArchive.logo_data = b'' + c = ComicArchive(join(__dir__, "fake_cbr.cbr")) + pageNameList = c.getPageNameList() + + assert pageNameList == [ + "page0.jpg", + "Page1.jpeg", + "Page2.png", + "Page3.gif", + "page4.webp", + "page10.jpg" + ] \ No newline at end of file From 0adac47968929d155e2c31901ecb114af89e2533 Mon Sep 17 00:00:00 2001 From: Davide Romanini Date: Sun, 20 Oct 2019 00:02:03 +0200 Subject: [PATCH 2/6] add pytest run to travis ci --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7a17cfc..b03d5a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ matrix: - os: osx language: generic osx_image: xcode8.3 - env: PYTHON=python3 PIP=pip3 MACOSX_DEPLOYMENT_TARGET=10.11 + env: PYTHON=python3 PIP=pip3 - os: windows language: bash env: PATH=/C/Python37:/C/Python37/Scripts:$PATH MAKE=mingw32-make @@ -24,8 +24,9 @@ before_install: - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew upgrade python3 ; fi install: - $PIP install --upgrade setuptools - - $PIP install -r requirements.txt + - $PIP install -r requirements.txt -r requirements_dev.txt script: + - pytest - if [ "$TRAVIS_OS_NAME" != "linux" ]; then $MAKE dist ; fi deploy: From cdf9a4022739bb104eb9ce433874e86d964a9760 Mon Sep 17 00:00:00 2001 From: Davide Romanini Date: Sun, 20 Oct 2019 00:08:11 +0200 Subject: [PATCH 3/6] fix: add setup.py install before testing --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b03d5a8..d4b4d4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ install: - $PIP install --upgrade setuptools - $PIP install -r requirements.txt -r requirements_dev.txt script: + - $PYTHON setup.py install - pytest - if [ "$TRAVIS_OS_NAME" != "linux" ]; then $MAKE dist ; fi From 806b65db24386ef46bbceb810fe4517fd050f6cc Mon Sep 17 00:00:00 2001 From: Davide Romanini Date: Sun, 20 Oct 2019 00:20:57 +0200 Subject: [PATCH 4/6] freeze windows python version to 3.7.5 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d4b4d4f..b885e13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ matrix: language: bash env: PATH=/C/Python37:/C/Python37/Scripts:$PATH MAKE=mingw32-make before_install: - - if [ "$TRAVIS_OS_NAME" = "windows" ]; then choco install -y python mingw zip; fi + - if [ "$TRAVIS_OS_NAME" = "windows" ]; then choco install -y python --version=3.7.5 mingw zip; fi - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew upgrade python3 ; fi install: - $PIP install --upgrade setuptools From ce48730bd55c4862a29f104da51c49fbc0f89ff4 Mon Sep 17 00:00:00 2001 From: Davide Romanini Date: Sun, 20 Oct 2019 00:25:52 +0200 Subject: [PATCH 5/6] fix: choco install multiple packages breaks with version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b885e13..b63b278 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ matrix: language: bash env: PATH=/C/Python37:/C/Python37/Scripts:$PATH MAKE=mingw32-make before_install: - - if [ "$TRAVIS_OS_NAME" = "windows" ]; then choco install -y python --version=3.7.5 mingw zip; fi + - if [ "$TRAVIS_OS_NAME" = "windows" ]; then choco install -y python --version=3.7.5; choco install -y mingw zip; fi - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew upgrade python3 ; fi install: - $PIP install --upgrade setuptools From beb7c57a6b99f36ea2323976d8e318e37b800b68 Mon Sep 17 00:00:00 2001 From: Davide Romanini Date: Sun, 20 Oct 2019 00:36:13 +0200 Subject: [PATCH 6/6] fix: change accidental overwrite of reserved __dir__ --- tests/test_comicarchive.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_comicarchive.py b/tests/test_comicarchive.py index d6f0604..6a6b1e5 100644 --- a/tests/test_comicarchive.py +++ b/tests/test_comicarchive.py @@ -1,11 +1,11 @@ from os.path import dirname, abspath, join from comicapi.comicarchive import ComicArchive -__dir__ = dirname(abspath(__file__)) +thisdir = dirname(abspath(__file__)) def test_getPageNameList(): ComicArchive.logo_data = b'' - c = ComicArchive(join(__dir__, "fake_cbr.cbr")) + c = ComicArchive(join(thisdir, "fake_cbr.cbr")) pageNameList = c.getPageNameList() assert pageNameList == [