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

TST: Replace pytest.mark.external by enable_socket #1657

Merged
merged 8 commits into from
Mar 2, 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
6 changes: 3 additions & 3 deletions docs/dev/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pypdf makes use of the following pytest markers:

* `slow`: Tests that require more than 5 seconds
* `samples`: Tests that require the [the `sample-files` git submodule](https:/py-pdf/sample-files) to be initialized. As of October 2022, this is about 25 MB.
* `external`: Tests that download PDF documents. They are stored locally and thus only need to be downloaded once. As of October 2022, this is about 200 MB.
* `enable_socket`: Tests that download PDF documents. They are stored locally and thus only need to be downloaded once. As of October 2022, this is about 200 MB.

You can disable them by `pytest -m "not external"` or `pytest -m "not samples"`.
You can even disable all of them: `pytest -m "not external" -m "not samples" -m "not slow"`.
You can disable them by `pytest -m "not enable_socket"` or `pytest -m "not samples"`.
You can even disable all of them: `pytest -m "not enable_socket" -m "not samples" -m "not slow"`.

Please note that this reduces test coverage. The CI will always test all files.

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ package = "./pypdf"
exclude = [".github/*", "docs/*", "resources/*", "sample-files/*", "sample-files/.github/*", "sample-files/.gitignore", "sample-files/.pre-commit-config.yaml", "requirements/*", "tests/*", ".flake8", ".gitignore", ".gitmodules", ".pylintrc", "tox.ini", "make_changelog.py", "mutmut-test.sh", ".pre-commit-config.yaml", ".gitblame-ignore-revs", "Makefile", "mutmut_config.py"]

[tool.pytest.ini_options]
addopts = "--disable-socket"
filterwarnings = ["error"]
markers = [
"slow: Test which require more than a second",
"samples: Tests which use files from https:/py-pdf/sample-files",
"external: Tests which need to download files"
"enable_socket: Tests which need to download files"
]
testpaths = ["tests"]
norecursedirs = ["tests/pdf_cache"]
Expand Down
7 changes: 5 additions & 2 deletions requirements/ci-3.11.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with python 3.11
# To update, run:
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --output-file=requirements/ci-3.11.txt requirements/ci.in
#
Expand Down Expand Up @@ -54,8 +54,11 @@ pytest==7.2.0
# via
# -r requirements/ci.in
# pytest-benchmark
# pytest-socket
pytest-benchmark==4.0.0
# via -r requirements/ci.in
pytest-socket==0.6.0
# via -r requirements/ci.in
ruff==0.0.252
# via -r requirements/ci.in
typeguard==2.13.3
Expand Down
1 change: 1 addition & 0 deletions requirements/ci.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pillow
pycryptodome
pytest
pytest-benchmark
pytest-socket
typeguard
types-dataclasses
types-Pillow
3 changes: 3 additions & 0 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ pytest==7.0.1
# via
# -r requirements/ci.in
# pytest-benchmark
# pytest-socket
pytest-benchmark==3.4.1
# via -r requirements/ci.in
pytest-socket==0.4.1
# via -r requirements/ci.in
six==1.16.0
# via flake8-print
tomli==1.2.3
Expand Down
20 changes: 10 additions & 10 deletions tests/test_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from . import get_pdf_from_url


@pytest.mark.external
@pytest.mark.enable_socket
@pytest.mark.slow
def test_compute_space_width():
url = "https://corpora.tika.apache.org/base/docs/govdocs1/923/923406.pdf"
Expand All @@ -21,7 +21,7 @@ def test_compute_space_width():
page.extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
@pytest.mark.slow
def test_parse_to_unicode_process_rg():
url = "https://corpora.tika.apache.org/base/docs/govdocs1/959/959173.pdf"
Expand All @@ -36,7 +36,7 @@ def test_parse_to_unicode_process_rg():
page.extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
def test_parse_encoding_advanced_encoding_not_implemented():
url = "https://corpora.tika.apache.org/base/docs/govdocs1/957/957144.pdf"
name = "tika-957144.pdf"
Expand All @@ -47,7 +47,7 @@ def test_parse_encoding_advanced_encoding_not_implemented():
page.extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
def test_get_font_width_from_default(): # L40
url = "https://corpora.tika.apache.org/base/docs/govdocs1/908/908104.pdf"
name = "tika-908104.pdf"
Expand All @@ -56,7 +56,7 @@ def test_get_font_width_from_default(): # L40
page.extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
def test_multiline_bfrange():
# non regression test for iss_1285
url = (
Expand All @@ -77,7 +77,7 @@ def test_multiline_bfrange():
page.extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
def test_bfchar_on_2_chars():
# iss #1293
url = (
Expand All @@ -90,7 +90,7 @@ def test_bfchar_on_2_chars():
page.extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
def test_ascii_charset():
# iss #1312
url = "https:/py-pdf/pypdf/files/9472500/main.pdf"
Expand All @@ -99,23 +99,23 @@ def test_ascii_charset():
assert "/a" not in reader.pages[0].extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
def test_iss1370():
url = "https:/py-pdf/pypdf/files/9667138/cmap1370.pdf"
name = "cmap1370.pdf"
reader = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
reader.pages[0].extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
def test_iss1379():
url = "https:/py-pdf/pypdf/files/9712729/02voc.pdf"
name = "02voc.pdf"
reader = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
reader.pages[2].extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
def test_iss1533():
url = "https:/py-pdf/pypdf/files/10376149/iss1533.pdf"
name = "iss1533.pdf"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_CCITTFaxDecode():
)


@pytest.mark.external
@pytest.mark.enable_socket
@patch("pypdf._reader.logger_warning")
def test_decompress_zlib_error(mock_logger_warning):
url = "https://corpora.tika.apache.org/base/docs/govdocs1/952/952445.pdf"
Expand All @@ -215,7 +215,7 @@ def test_decompress_zlib_error(mock_logger_warning):
)


@pytest.mark.external
@pytest.mark.enable_socket
def test_lzw_decode_neg1():
url = "https://corpora.tika.apache.org/base/docs/govdocs1/921/921632.pdf"
name = "tika-921632.pdf"
Expand All @@ -226,15 +226,15 @@ def test_lzw_decode_neg1():
assert exc.value.args[0] == "Missed the stop code in LZWDecode!"


@pytest.mark.external
@pytest.mark.enable_socket
def test_issue_399():
url = "https://corpora.tika.apache.org/base/docs/govdocs1/976/976970.pdf"
name = "tika-976970.pdf"
reader = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
reader.pages[1].extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
def test_image_without_imagemagic():
with patch.dict(sys.modules):
sys.modules["PIL"] = None
Expand Down
18 changes: 9 additions & 9 deletions tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def test_remove_child_in_tree():
tree.empty_tree()


@pytest.mark.external
@pytest.mark.enable_socket
def test_dict_read_from_stream(caplog):
url = "https://corpora.tika.apache.org/base/docs/govdocs1/984/984877.pdf"
name = "tika-984877.pdf"
Expand All @@ -597,7 +597,7 @@ def test_dict_read_from_stream(caplog):
)


@pytest.mark.external
@pytest.mark.enable_socket
def test_parse_content_stream_peek_percentage():
url = "https://corpora.tika.apache.org/base/docs/govdocs1/985/985770.pdf"
name = "tika-985770.pdf"
Expand All @@ -607,7 +607,7 @@ def test_parse_content_stream_peek_percentage():
page.extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
def test_read_inline_image_no_has_q():
# pdf/df7e1add3156af17a372bc165e47a244.pdf
url = "https://corpora.tika.apache.org/base/docs/govdocs1/998/998719.pdf"
Expand All @@ -618,7 +618,7 @@ def test_read_inline_image_no_has_q():
page.extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
def test_read_inline_image_loc_neg_1():
url = "https://corpora.tika.apache.org/base/docs/govdocs1/935/935066.pdf"
name = "tika-935066.pdf"
Expand All @@ -629,7 +629,7 @@ def test_read_inline_image_loc_neg_1():


@pytest.mark.slow
@pytest.mark.external
@pytest.mark.enable_socket
def test_text_string_write_to_stream():
url = "https://corpora.tika.apache.org/base/docs/govdocs1/924/924562.pdf"
name = "tika-924562.pdf"
Expand All @@ -639,7 +639,7 @@ def test_text_string_write_to_stream():
page.compress_content_streams()


@pytest.mark.external
@pytest.mark.enable_socket
def test_name_object_read_from_stream_unicode_error(): # L588
url = "https://corpora.tika.apache.org/base/docs/govdocs1/974/974966.pdf"
name = "tika-974966.pdf"
Expand All @@ -649,7 +649,7 @@ def test_name_object_read_from_stream_unicode_error(): # L588
page.extract_text()


@pytest.mark.external
@pytest.mark.enable_socket
def test_bool_repr(tmp_path):
url = "https://corpora.tika.apache.org/base/docs/govdocs1/932/932449.pdf"
name = "tika-932449.pdf"
Expand All @@ -669,7 +669,7 @@ def test_bool_repr(tmp_path):
)


@pytest.mark.external
@pytest.mark.enable_socket
@patch("pypdf._reader.logger_warning")
def test_issue_997(mock_logger_warning):
url = (
Expand Down Expand Up @@ -1046,7 +1046,7 @@ def test_cloning(caplog):
assert isinstance(obj21.get("/Test2"), IndirectObject)


@pytest.mark.external
@pytest.mark.enable_socket
def test_append_with_indirectobject_not_pointing(caplog):
"""
reported in #1631
Expand Down
Loading