Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Run CI with windows-latest #2258

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with this. I've prepared a PR to fix this test.
Actually currently all tests are passing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should have been xfail and the reason was phrases bad, but I did see your pr :-)

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
Loading