From 5bda8092d400b40dfee152f6451bc84bab45a03e Mon Sep 17 00:00:00 2001 From: Nemo Date: Sun, 4 Jul 2021 02:31:56 +0530 Subject: [PATCH] [tests] Add tests for page-selection Changed the page-select file to keep older bookmarks since we need to test for some bookmarks being stripped --- tests/book-page-select.md | 5 +---- tests/test_integration.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/book-page-select.md b/tests/book-page-select.md index 83b9136..e5f6537 100644 --- a/tests/book-page-select.md +++ b/tests/book-page-select.md @@ -1,7 +1,4 @@ -existing_bookmarks: remove -author: Wiki, the Cat -subject: A book about adventures of Wiki, the cat. -keywords: wiki,potato,jelly +existing_bookmarks: keep # Super Potato Book # Volume 1 diff --git a/tests/test_integration.py b/tests/test_integration.py index 12bc2d1..a78bfe1 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -6,12 +6,24 @@ from itertools import chain ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) + "/../" +""" +Fixtures for the integration tests. Each test is a tuple consisting of 4 things: +- input name (used as book-{name}.md) +- total expected page count +- A dictionary of expected metadata. Leave empty if nothing is set +- A flattened list of expected bookmarks, with each bookmark as a tuple containing: + - Title + - Destination Page Number + - Bookmark Level (default = 0) +Each of the above 4 is passed to test_book as an argument +""" TEST_DATA = [ ("clean",6, {'Author': 'Wiki, the Cat', 'Title': 'Super Potato Book', 'Subject': 'A book about adventures of Wiki, the cat.', 'Keywords': 'wiki,potato,jelly'}, [('Super Potato Book', 0, 0), ('Volume 1', 0, 0), ('Part 1', 0, 1), ('Volume 2', 3, 0), ('Part 2', 3, 1)]), ("keep",6, {'Title': 'Super Potato Book'}, [('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 3', 3, 1), ('Chapter 3', 3, 2), ('Chapter 4', 4, 2), ('Scene 3', 4, 3), ('Scene 4', 5, 3)]), ("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)]) + ("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)]) ] def pdf_name(name): @@ -41,7 +53,7 @@ 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)