From 90a3408dfc9c17d7c4d11290cb1e4d6ce64401c2 Mon Sep 17 00:00:00 2001 From: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com> Date: Tue, 17 Oct 2023 19:50:10 +0200 Subject: [PATCH 1/2] TST: Fix test_image_without_pillow in windows environment fixes test failure in windows environment --- tests/test_filters.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/test_filters.py b/tests/test_filters.py index 12819c43b..9cfea57b5 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -265,9 +265,11 @@ def test_image_without_pillow(tmp_path): name = "tika-914102.pdf" _ = get_data_from_url(url, name=name) pdf_path = Path(__file__).parent / "pdf_cache" / name + pdf_path_str = str(pdf_path.resolve()).replace("\\", "/") source_file = tmp_path / "script.py" - source_file.write_text(f""" + source_file.write_text( + f""" import sys from pypdf import PdfReader @@ -275,7 +277,7 @@ def test_image_without_pillow(tmp_path): sys.modules["PIL"] = None -reader = PdfReader("{pdf_path.resolve()}", strict=True) +reader = PdfReader("{pdf_path_str}", strict=True) for page in reader.pages: with pytest.raises(ImportError) as exc: @@ -284,13 +286,20 @@ 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" + assert ( + result.stderr.replace(b"\r", b"") + == b"Superfluous whitespace found in object header b'4' b'0'\n" + ) + @pytest.mark.enable_socket() def test_issue_1737(): From 7a7b89e8e69eeb2e1a267e8b4b68e553d950d55a Mon Sep 17 00:00:00 2001 From: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com> Date: Tue, 17 Oct 2023 21:54:27 +0200 Subject: [PATCH 2/2] Update test_filters.py --- tests/test_filters.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_filters.py b/tests/test_filters.py index b52102b6b..38d38abd1 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -260,10 +260,6 @@ 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"