Skip to content

Commit

Permalink
DEV: Run CI with windows-latest (#2258)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma authored Oct 17, 2023
1 parent 8aef1de commit 2a3c1fb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/github-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2a3c1fb

Please sign in to comment.