From 0677549ac381d2c7eb5f1d61be2dbbf2a6a8c5c8 Mon Sep 17 00:00:00 2001 From: Nemo Date: Sun, 4 Jul 2021 02:38:37 +0530 Subject: [PATCH] [ci] Run tests on GitHub Actions --- .github/workflows/tests.yml | 20 ++++++++++++++++++++ tests/test_integration.py | 13 ++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..12297cb --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,20 @@ +name: Run Tests +on: push +jobs: + all: + runs-on: ubuntu-latest + strategy: + matrix: + python: ["3.6", "3.7", "3.8", "3.9"] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{matrix.python}} + uses: actions/setup-python@v2 + with: + python-version: ${{matrix.python}} + - name: Install deps + run: | + python -m pip install --upgrade pip + pip install -e .[testing] + - name: Run pytest + run: pytest --cache-clear diff --git a/tests/test_integration.py b/tests/test_integration.py index a78bfe1..c942e85 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -2,6 +2,7 @@ import pytest import os import PyPDF3 from pystitcher.stitcher import Stitcher +from pystitcher import __version__ from itertools import chain ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) + "/../" @@ -23,7 +24,7 @@ TEST_DATA = [ ("flatten", 6, {}, [('Super Potato Book', 0, 0), ('Volume 1', 0, 0), ('Part 1', 0, 1), ('Chapter 1', 0, 2), ('Chapter 2', 1, 2), ('Scene 1', 1, 2), ('Scene 2', 2, 2), ('Volume 2', 3, 0), ('Part 3', 3, 1), ('Chapter 3', 3, 2), ('Chapter 4', 4, 2), ('Scene 3', 4, 2), ('Scene 4', 5, 2)]), ("rotate", 9, {}, [('Super Potato Book', 0, 0), ('Volume 1', 0, 0), ('Part 1', 0, 1), ('Volume 2', 3, 0), ('Part 2', 3, 1), ('Volume 3', 6, 0), ('Part 3', 6, 1)]), ("min",3, {}, [('Part 1', 0, 0), ('Chapter 1', 0, 1), ('Chapter 2', 1, 1), ('Scene 1', 1, 2), ('Scene 2', 2, 2)]), - ("page-select", 12, {}, [('Super Potato Book', 0, 0), ('Volume 1', 0, 0), ('Part 1', 0, 1), ('Chapter 1', 0, 2), ('Chapter 2', 1, 2), ('Scene 1', 1, 3), ('Scene 2', 2, 3), ('Volume 2', 3, 0), ('Part 2', 3, 1), ('Chapter 3', 3, 2), ('Chapter 4', 4, 2), ('Scene 3', 4, 3), ('Scene 4', 5, 3), ('Volume 3', 6, 0), ('Part 3', 6, 1), ('Chapter 1', 6, 2), ('Chapter 2', 7, 2), ('Scene 1', 7, 3), ('Scene 2', 8, 3), ('Volume 4', 9, 0), ('Part 4', 9, 1), ('Chapter 3', 9, 2), ('Chapter 4', 10, 2), ('Scene 3', 10, 3), ('Scene 4', 11, 3)]) + ("page-select", 9, {}, [('Super Potato Book', 0, 0), ('Volume 1', 0, 0), ('Part 1', 0, 1), ('Chapter 1', 0, 2), ('Chapter 2', 1, 2), ('Scene 1', 1, 3), ('Volume 2', 2, 0), ('Part 2', 2, 1), ('Scene 2', 2, 2), ('Chapter 3', 2, 2), ('Chapter 4', 3, 2), ('Scene 3', 3, 3), ('Volume 3', 4, 0), ('Part 3', 4, 1), ('Scene 4', 4, 2), ('Chapter 1', 4, 2), ('Chapter 2', 5, 2), ('Scene 1', 5, 3), ('Volume 4', 6, 0), ('Part 4', 6, 1), ('Scene 2', 6, 2), ('Chapter 3', 6, 2), ('Chapter 4', 7, 2), ('Scene 3', 7, 3), ('Scene 4', 8, 3)]) ] def pdf_name(name): @@ -53,21 +54,23 @@ def get_all_bookmarks(pdf): bookmarks = flatten_bookmarks(pdf.getOutlines()) return [(d[0]['/Title'], pdf.getDestinationPageNumber(d[0]), d[1]) for d in bookmarks] -@pytest.mark.parametrize("name, pages, metadata, bookmarks", TEST_DATA) +@pytest.mark.parametrize("name,pages,metadata,bookmarks", TEST_DATA) def test_book(name, pages, metadata, bookmarks): output_file = render(name) pdf = PyPDF3.PdfFileReader(output_file) assert pages == pdf.getNumPages() assert bookmarks == get_all_bookmarks(pdf) info = pdf.getDocumentInfo() - assert 'pystitcher/1.0.1' == info['/Producer'] - assert 'pystitcher/1.0.1' == info['/Creator'] + identity = "pystitcher/%s" % __version__ + assert identity == info['/Producer'] + assert identity == info['/Creator'] for key in metadata: assert info["/%s" % key] == metadata[key] def test_rotation(): """ Validates the book-rotate.pdf with pages rotated.""" - pdf = PyPDF3.PdfFileReader("tests/book-rotate.pdf") + output_file = render("rotate") + pdf = PyPDF3.PdfFileReader(output_file) # Note that inputs to getPage are 0-indexed assert 90 == pdf.getPage(3)['/Rotate'] assert 90 == pdf.getPage(4)['/Rotate']