diff --git a/.github/workflows/github-ci.yaml b/.github/workflows/github-ci.yaml index 236a0446e..72ffe3dd4 100644 --- a/.github/workflows/github-ci.yaml +++ b/.github/workflows/github-ci.yaml @@ -17,6 +17,39 @@ on: workflow_dispatch: jobs: + test_windows: + name: pytest on windows + runs-on: windows-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Setup Python (3.11+) + uses: actions/setup-python@v4 + with: + python-version: 3.12 # latest stable python + allow-prereleases: true + - name: Upgrade pip + run: | + python -m pip install --upgrade pip + - name: Install requirements (Python 3.11+) + run: | + pip install -r requirements/ci-3.11.txt + - name: Install cryptography + run: | + pip install cryptography + - name: Install pypdf + run: | + pip install . + - name: Prepare + run: | + python -c "from tests import download_test_pdfs; download_test_pdfs()" + - name: Test with pytest + run: | + python -m pytest tests --cov=pypdf --cov-append -n auto -vv + + tests: name: pytest on ${{ matrix.python-version }} runs-on: ubuntu-20.04 diff --git a/tests/test_filters.py b/tests/test_filters.py index 12819c43b..d6e184bde 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -2,6 +2,7 @@ import shutil import string import subprocess +import sys from io import BytesIO from itertools import product as cartesian_product from pathlib import Path @@ -259,6 +260,10 @@ def test_issue_399(): reader.pages[1].extract_text() +@pytest.mark.skipif( + sys.platform.startswith("win"), + reason="Supbrocess running python seems to linux-specific", +) @pytest.mark.enable_socket() def test_image_without_pillow(tmp_path): url = "https://corpora.tika.apache.org/base/docs/govdocs1/914/914102.pdf" @@ -267,7 +272,8 @@ def test_image_without_pillow(tmp_path): pdf_path = Path(__file__).parent / "pdf_cache" / name source_file = tmp_path / "script.py" - source_file.write_text(f""" + source_file.write_text( + f""" import sys from pypdf import PdfReader @@ -284,14 +290,18 @@ def test_image_without_pillow(tmp_path): "pillow is required to do image extraction. " "It can be installed via 'pip install pypdf[image]'" ), exc.value.args[0] -""") +""" + ) result = subprocess.run( # noqa: UP022 - [shutil.which("python"), source_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE # noqa: S603 + [shutil.which("python"), source_file], # noqa: S603 + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, ) assert result.returncode == 0 assert result.stdout == b"" assert result.stderr == b"Superfluous whitespace found in object header b'4' b'0'\n" + @pytest.mark.enable_socket() def test_issue_1737(): url = "https://github.com/py-pdf/pypdf/files/11068604/tt1.pdf" diff --git a/tests/test_workflows.py b/tests/test_workflows.py index df4b3e083..de43fe7a8 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -100,9 +100,10 @@ def test_pdfreader_file_load(): text = page.extract_text().encode("utf-8") # Compare the text of the PDF to a known source - for expected_line, actual_line in zip(text.split(b"\n"), pdftext.split(b"\n")): + for expected_line, actual_line in zip(text.splitlines(), pdftext.splitlines()): assert expected_line == actual_line + pdftext = pdftext.replace(b"\r\n", b"\n") # fix for windows assert text == pdftext, ( "PDF extracted text differs from expected value.\n\n" "Expected:\n\n%r\n\nExtracted:\n\n%r\n\n" % (pdftext, text)