Skip to content

Commit 963b251

Browse files
authored
TST: Use external repository for larger/more PDFs for testing (py-pdf#820)
* Use submodule so that the connection is clear. Ensure that Flake8 issues of the submodule don't show up here * As a first step, just try to get the number of pages from the non-encrypted PDFs * Create an "external" pytest marker which allows people to deactivate tests that need the submodule
1 parent 39ffc1d commit 963b251

File tree

6 files changed

+51
-2
lines changed

6 files changed

+51
-2
lines changed

.github/workflows/github-ci.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
steps:
2727
- name: Checkout Code
2828
uses: actions/checkout@v3
29+
with:
30+
submodules: 'recursive'
2931
- name: Setup Python
3032
uses: actions/setup-python@v3
3133
with:
@@ -46,7 +48,7 @@ jobs:
4648
pip install .
4749
- name: Test with flake8
4850
run: |
49-
flake8 . --ignore=E203,W503,W504,E,F403,F405 --exclude build
51+
flake8 . --ignore=E203,W503,W504,E,F403,F405 --exclude build,sample-files
5052
if: matrix.python-version != '2.7'
5153
- name: Test with pytest
5254
run: |

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "sample-files"]
2+
path = sample-files
3+
url = https://github.com/py-pdf/sample-files

Tests/test_page.py

+25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import json
23

34
import pytest
45

@@ -7,6 +8,30 @@
78
TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
89
PROJECT_ROOT = os.path.dirname(TESTS_ROOT)
910
RESOURCE_ROOT = os.path.join(PROJECT_ROOT, "Resources")
11+
EXTERNAL_ROOT = os.path.join(PROJECT_ROOT, "sample-files")
12+
13+
14+
def get_all_sample_files():
15+
with open(os.path.join(EXTERNAL_ROOT, "files.json")) as fp:
16+
data = fp.read()
17+
meta = json.loads(data)
18+
return meta
19+
20+
21+
all_files_meta = get_all_sample_files()
22+
23+
24+
@pytest.mark.external
25+
@pytest.mark.parametrize(
26+
"meta",
27+
[m for m in all_files_meta["data"] if not m["encrypted"]],
28+
ids=[m["path"] for m in all_files_meta["data"] if not m["encrypted"]],
29+
)
30+
def test_read(meta):
31+
pdf_path = os.path.join(EXTERNAL_ROOT, meta["path"])
32+
reader = PdfFileReader(pdf_path)
33+
reader.pages[0]
34+
assert len(reader.pages) == meta["pages"]
1035

1136

1237
@pytest.mark.parametrize(

docs/dev/intro.md

+17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ pip install -r requirements/dev.txt
1515
pytest .
1616
```
1717

18+
We have the following pytest markers defined:
19+
20+
* `no_py27`: Flag for tests that fail under Python 2.7 only
21+
* `external`: Tests which use files from [the `sample-files` git submodule](https://github.com/py-pdf/sample-files)
22+
23+
You can locally choose not to run those via `pytest -m "not external"`.
24+
25+
## The sample-files git submodule
26+
The reason for having the submodule `sample-files` is that we want to keep
27+
the size of the PyPDF2 repository small while we also want to have an extensive
28+
test suite. Those two goals contradict each other.
29+
30+
The `Resources` folder should contain a select set of core examples that cover
31+
most cases we typically want to test for. The `sample-files` might cover a lot
32+
more edge cases, the behavior we get when file sizes get bigger, different
33+
PDF producers.
34+
1835
## Tools: git and pre-commit
1936

2037
Git is a command line application for version control. If you don't know it,

pytest.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[pytest]
22
markers =
3-
no_py27: Flag for tests that fail under Python 2.7 only
3+
no_py27: Flag for tests that fail under Python 2.7 only
4+
external: Tests which use files from https://github.com/py-pdf/sample-files

sample-files

Submodule sample-files added at 6e3a1bb

0 commit comments

Comments
 (0)