From 6e47986cce0f98cad15fffcd405d2799d3805e35 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 20 Apr 2022 16:32:40 +0300 Subject: [PATCH 01/15] Infra: add tests --- .github/workflows/test.yml | 51 ++++++++ .gitignore | 2 + .pre-commit-config.yaml | 19 +++ Makefile | 3 + .../pep_processor/transforms/pep_headers.py | 2 +- .../pep_zero_generator/author.py | 9 +- pep_sphinx_extensions/tests/__init__.py | 0 .../transform/test_pep_footer.py | 38 ++++++ .../transform/test_pep_headers.py | 114 ++++++++++++++++++ .../pep_processor/transform/test_pep_zero.py | 25 ++++ .../tests/pep_zero_generator/test_author.py | 70 +++++++++++ .../tests/pep_zero_generator/test_parser.py | 84 +++++++++++++ .../test_pep_index_generator.py | 12 ++ .../tests/pep_zero_generator/test_writer.py | 76 ++++++++++++ pep_sphinx_extensions/tests/peps/pep-9000.rst | 7 ++ pep_sphinx_extensions/tests/peps/pep-9001.rst | 7 ++ pep_sphinx_extensions/tests/utils.py | 6 + requirements.txt | 4 + tox.ini | 11 ++ 19 files changed, 537 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 pep_sphinx_extensions/tests/__init__.py create mode 100644 pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py create mode 100644 pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py create mode 100644 pep_sphinx_extensions/tests/pep_processor/transform/test_pep_zero.py create mode 100644 pep_sphinx_extensions/tests/pep_zero_generator/test_author.py create mode 100644 pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py create mode 100644 pep_sphinx_extensions/tests/pep_zero_generator/test_pep_index_generator.py create mode 100644 pep_sphinx_extensions/tests/pep_zero_generator/test_writer.py create mode 100644 pep_sphinx_extensions/tests/peps/pep-9000.rst create mode 100644 pep_sphinx_extensions/tests/peps/pep-9001.rst create mode 100644 pep_sphinx_extensions/tests/utils.py create mode 100644 tox.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000000..6cb91b77db2 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,51 @@ +name: Test + +on: + push: + paths: + - ".github/workflows/test.yml" + - "pep_sphinx_extensions/**" + - "tox.ini" + pull_request: + paths: + - ".github/workflows/test.yml" + - "pep_sphinx_extensions/**" + - "tox.ini" + workflow_dispatch: + +env: + FORCE_COLOR: 1 + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10"] + os: [macos-latest, ubuntu-latest] + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + cache: pip + + - name: Install dependencies + run: | + python -m pip install -U pip + python -m pip install -U wheel + python -m pip install -U tox + + - name: tox tests + run: | + tox -e py + + - name: Upload coverage + uses: codecov/codecov-action@v3 + with: + flags: ${{ matrix.os }} + name: ${{ matrix.os }} Python ${{ matrix.python-version }} diff --git a/.gitignore b/.gitignore index b9c89215748..d633618272c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ __pycache__ *.pyo *~ *env +.coverage +.tox .vscode *.swp /build diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a07ab6cd830..e793feb40f0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -42,6 +42,25 @@ repos: - id: check-yaml name: "Check YAML" + - repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black + args: [--target-version=py39] + files: "pep_sphinx_extensions/tests/.*" + + - repo: https://github.com/PyCQA/isort + rev: 5.10.1 + hooks: + - id: isort + args: [--profile=black] + files: "pep_sphinx_extensions/tests/.*" + + - repo: https://github.com/tox-dev/tox-ini-fmt + rev: 0.5.2 + hooks: + - id: tox-ini-fmt + # RST checks - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.9.0 diff --git a/Makefile b/Makefile index a6cc86c2f26..5b88177ed6e 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,9 @@ lint: venv $(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install pre-commit $(VENVDIR)/bin/python3 -m pre_commit run --all-files +test: venv + $(VENVDIR)/bin/python3 -m pytest --cov pep_sphinx_extensions --cov-report html --cov-report term --cov-report xml + spellcheck: venv $(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install pre-commit $(VENVDIR)/bin/python3 -m pre_commit run --all-files --hook-stage manual codespell diff --git a/pep_sphinx_extensions/pep_processor/transforms/pep_headers.py b/pep_sphinx_extensions/pep_processor/transforms/pep_headers.py index 3e237c27eb9..497545720a7 100644 --- a/pep_sphinx_extensions/pep_processor/transforms/pep_headers.py +++ b/pep_sphinx_extensions/pep_processor/transforms/pep_headers.py @@ -204,7 +204,7 @@ def _process_pretty_url(url: str) -> tuple[str, str]: item_name, item_type = LINK_PRETTIFIERS[parts[2]](parts) except KeyError as error: raise ValueError( - "{url} not a link to a recognized domain to prettify") from error + f"{url} not a link to a recognized domain to prettify") from error item_name = item_name.title().replace("Sig", "SIG") return item_name, item_type diff --git a/pep_sphinx_extensions/pep_zero_generator/author.py b/pep_sphinx_extensions/pep_zero_generator/author.py index 22299b056af..24b2240255b 100644 --- a/pep_sphinx_extensions/pep_zero_generator/author.py +++ b/pep_sphinx_extensions/pep_zero_generator/author.py @@ -35,7 +35,12 @@ def parse_author_email(author_email_tuple: tuple[str, str], authors_overrides: d if name_parts.surname[1] == ".": # Add an escape to avoid docutils turning `v.` into `22.`. - name_parts.surname = f"\\{name_parts.surname}" + name_parts = _Name( + mononym=name_parts.mononym, + forename=name_parts.forename, + surname=f"\\{name_parts.surname}", + suffix=name_parts.suffix, + ) if name_parts.suffix: last_first = f"{name_parts.surname}, {name_parts.forename}, {name_parts.suffix}" @@ -63,7 +68,7 @@ def _parse_name(full_name: str) -> _Name: num_parts = len(name_parts) suffix = raw_suffix.strip() - if num_parts == 0: + if name_parts == [""]: raise ValueError("Name is empty!") elif num_parts == 1: return _Name(mononym=name_parts[0], suffix=suffix) diff --git a/pep_sphinx_extensions/tests/__init__.py b/pep_sphinx_extensions/tests/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py new file mode 100644 index 00000000000..2d19608f72d --- /dev/null +++ b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py @@ -0,0 +1,38 @@ +from pathlib import Path + +from pep_sphinx_extensions.pep_processor.transforms import pep_footer + + +def test_add_source_link(): + out = pep_footer._add_source_link(Path("pep-0008.txt")) + + assert ( + str(out) == "Source: " + '' + "https://github.com/python/peps/blob/main/pep-0008.txt" + "" + ) + + +def test_add_commit_history_info(): + out = pep_footer._add_commit_history_info(Path("pep-0008.txt")) + + assert str(out).startswith( + "Last modified: " + '' + ) + # A variable timestamp comes next, don't test that + assert str(out).endswith("") + + +def test_add_commit_history_info_invalid(): + out = pep_footer._add_commit_history_info(Path("pep-not-found.txt")) + + assert str(out) == "" + + +def test_get_last_modified_timestamps(): + out = pep_footer._get_last_modified_timestamps() + + assert len(out) >= 585 + assert out["pep-0008.txt"] >= 1643124055 diff --git a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py new file mode 100644 index 00000000000..00d86855d88 --- /dev/null +++ b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py @@ -0,0 +1,114 @@ +import pytest + +from pep_sphinx_extensions.pep_processor.transforms import pep_headers + + +@pytest.mark.parametrize( + "test_input, expected", + [ + ("my-mailing-list@example.com", "my-mailing-list@example.com"), + ("python-tulip@googlegroups.com", "https://groups.google.com/g/python-tulip"), + ("db-sig@python.org", "https://mail.python.org/mailman/listinfo/db-sig"), + ("import-sig@python.org", "https://mail.python.org/pipermail/import-sig/"), + ( + "python-announce@python.org", + "https://mail.python.org/archives/list/python-announce@python.org/", + ), + ], +) +def test_generate_list_url(test_input, expected): + out = pep_headers._generate_list_url(test_input) + + assert out == expected + + +@pytest.mark.parametrize( + "test_input, expected", + [ + ( + "https://mail.python.org/pipermail/python-3000/2006-November/004190.html", + ("Python-3000", "message"), + ), + ( + "https://mail.python.org/archives/list/python-dev@python.org/thread/HW2NFOEMCVCTAFLBLC3V7MLM6ZNMKP42/", + ("Python-Dev", "thread"), + ), + ( + "https://mail.python.org/mailman3/lists/capi-sig.python.org/", + ("Capi-SIG", "list"), + ), + ( + "https://mail.python.org/mailman/listinfo/web-sig", + ("Web-SIG", "list"), + ), + ( + "https://discuss.python.org/t/pep-643-metadata-for-package-source-distributions/5577", + ("Discourse", "thread"), + ), + ( + "https://discuss.python.org/c/peps/", + ("Peps Discourse", "category"), + ), + ], +) +def test_process_pretty_url(test_input, expected): + out = pep_headers._process_pretty_url(test_input) + + assert out == expected + + +@pytest.mark.parametrize( + "test_input, expected", + [ + ( + "https://example.com/", + "https://example.com/ not a link to a recognized domain to prettify", + ), + ( + "https://mail.python.org", + "https://mail.python.org not a link to a list, message or thread", + ), + ( + "https://discuss.python.org/", + "https://discuss.python.org not a link to a Discourse thread or category", + ), + ], +) +def test_process_pretty_url_invalid(test_input, expected): + with pytest.raises(ValueError, match=expected): + pep_headers._process_pretty_url(test_input) + + +@pytest.mark.parametrize( + "test_input, expected", + [ + ( + "https://mail.python.org/pipermail/python-3000/2006-November/004190.html", + "Python-3000 message", + ), + ( + "https://mail.python.org/archives/list/python-dev@python.org/thread/HW2NFOEMCVCTAFLBLC3V7MLM6ZNMKP42/", + "Python-Dev thread", + ), + ( + "https://mail.python.org/mailman3/lists/capi-sig.python.org/", + "Capi-SIG list", + ), + ( + "https://mail.python.org/mailman/listinfo/web-sig", + "Web-SIG list", + ), + ( + "https://discuss.python.org/t/pep-643-metadata-for-package-source-distributions/5577", + "Discourse thread", + ), + ( + "https://discuss.python.org/c/peps/", + "Peps Discourse category", + ), + ], +) +def test_make_link_pretty(test_input, expected): + out = pep_headers._make_link_pretty(test_input) + + assert out == expected diff --git a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_zero.py b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_zero.py new file mode 100644 index 00000000000..09b2effead1 --- /dev/null +++ b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_zero.py @@ -0,0 +1,25 @@ +import pytest +from docutils import nodes + +from pep_sphinx_extensions.pep_processor.transforms import pep_zero + + +@pytest.mark.parametrize( + "test_input, expected", + [ + ( + nodes.reference( + "", text="user@example.com", refuri="mailto:user@example.com" + ), + 'user at example.com', + ), + ( + nodes.reference("", text="Introduction", refid="introduction"), + 'Introduction', + ), + ], +) +def test_generate_list_url(test_input, expected): + out = pep_zero._mask_email(test_input) + + assert str(out) == expected diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_author.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_author.py new file mode 100644 index 00000000000..302fde9b1d0 --- /dev/null +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_author.py @@ -0,0 +1,70 @@ +import pytest + +from pep_sphinx_extensions.pep_zero_generator import author +from pep_sphinx_extensions.tests.utils import AUTHORS_OVERRIDES + + +@pytest.mark.parametrize( + "test_input, expected", + [ + ( + ("First Last", "first@example.com"), + author.Author( + last_first="Last, First", nick="Last", email="first@example.com" + ), + ), + ( + ("Guido van Rossum", "guido@example.com"), + author.Author( + last_first="van Rossum, Guido (GvR)", + nick="GvR", + email="guido@example.com", + ), + ), + ( + ("Hugo van Kemenade", "hugo@example.com"), + author.Author( + last_first="van Kemenade, Hugo", + nick="van Kemenade", + email="hugo@example.com", + ), + ), + ( + ("Eric N. Vander Weele", "eric@example.com"), + author.Author( + last_first="Vander Weele, Eric N.", + nick="Vander Weele", + email="eric@example.com", + ), + ), + ( + ("Bob v. Smith", "bob@example.com"), + author.Author( + last_first="\\v. Smith, Bob", + nick="\\v. Smith", + email="bob@example.com", + ), + ), + ( + ("Mariatta", "mariatta@example.com"), + author.Author( + last_first="Mariatta", nick="Mariatta", email="mariatta@example.com" + ), + ), + ( + ("First Last Jr.", "first@example.com"), + author.Author( + last_first="Last, First, Jr.", nick="Last", email="first@example.com" + ), + ), + ], +) +def test_parse_author_email(test_input, expected): + out = author.parse_author_email(test_input, AUTHORS_OVERRIDES) + + assert out == expected + + +def test_parse_author_email_empty_name(): + with pytest.raises(ValueError, match="Name is empty!"): + author.parse_author_email(("", "user@example.com"), AUTHORS_OVERRIDES) diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py new file mode 100644 index 00000000000..379a227d025 --- /dev/null +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py @@ -0,0 +1,84 @@ +from pathlib import Path + +import pytest + +from pep_sphinx_extensions.pep_zero_generator import parser +from pep_sphinx_extensions.pep_zero_generator.author import Author +from pep_sphinx_extensions.pep_zero_generator.errors import PEPError +from pep_sphinx_extensions.tests.utils import AUTHORS_OVERRIDES + + +def test_pep_repr(): + pep8 = parser.PEP(Path("pep-0008.txt"), AUTHORS_OVERRIDES) + + assert (repr(pep8)) == "" + + +def test_pep_less_than(): + pep8 = parser.PEP(Path("pep-0008.txt"), AUTHORS_OVERRIDES) + pep3333 = parser.PEP(Path("pep-3333.txt"), AUTHORS_OVERRIDES) + + assert pep8 < pep3333 + + +def test_pep_equal(): + pep_a = parser.PEP(Path("pep-0008.txt"), AUTHORS_OVERRIDES) + pep_b = parser.PEP(Path("pep-0008.txt"), AUTHORS_OVERRIDES) + + assert pep_a == pep_b + + +def test_pep_details(): + pep8 = parser.PEP(Path("pep-0008.txt"), AUTHORS_OVERRIDES) + + assert pep8.details(title_length=80) == { + "authors": "GvR, Warsaw, Coghlan", + "number": 8, + "status": " ", + "title": "Style Guide for Python Code", + "type": "P", + } + + +def test_pep_details_short_title(): + pep8 = parser.PEP(Path("pep-0008.txt"), AUTHORS_OVERRIDES) + + assert pep8.details(title_length=10) == { + "authors": "GvR, Warsaw, Coghlan", + "number": 8, + "status": " ", + "title": "Style ...", + "type": "P", + } + + +@pytest.mark.parametrize( + "test_input, expected", + [ + ( + "First Last ", + [Author(last_first="Last, First", nick="Last", email="user@example.com")], + ), + ( + "First Last", + [Author(last_first="Last, First", nick="Last", email="")], + ), + ], +) +def test_parse_authors(test_input, expected): + # Arrange + pep = parser.PEP(Path("pep-0160.txt"), AUTHORS_OVERRIDES) + + # Act + out = parser._parse_authors(pep, test_input, AUTHORS_OVERRIDES) + + # Assert + assert out == expected + + +def test_parse_authors_invalid(): + + pep = parser.PEP(Path("pep-0008.txt"), AUTHORS_OVERRIDES) + + with pytest.raises(PEPError, match="no authors found"): + parser._parse_authors(pep, "", AUTHORS_OVERRIDES) diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_pep_index_generator.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_pep_index_generator.py new file mode 100644 index 00000000000..35a6a937c79 --- /dev/null +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_pep_index_generator.py @@ -0,0 +1,12 @@ +from pathlib import Path + +from pep_sphinx_extensions.pep_zero_generator import parser, pep_index_generator +from pep_sphinx_extensions.tests.utils import AUTHORS_OVERRIDES + + +def test_create_pep_json(): + peps = [parser.PEP(Path("pep-0008.txt"), AUTHORS_OVERRIDES)] + + out = pep_index_generator.create_pep_json(peps) + + assert '"url": "https://peps.python.org/pep-0008/"' in out diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_writer.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_writer.py new file mode 100644 index 00000000000..9cae97a0a2e --- /dev/null +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_writer.py @@ -0,0 +1,76 @@ +from pathlib import Path + +import pytest + +from pep_sphinx_extensions.pep_zero_generator import parser, writer +from pep_sphinx_extensions.tests.utils import AUTHORS_OVERRIDES + + +def test_pep_zero_writer_emit_text_newline(): + pep0_writer = writer.PEPZeroWriter() + pep0_writer.emit_text("my text 1") + pep0_writer.emit_newline() + pep0_writer.emit_text("my text 2") + + assert pep0_writer.output == ["my text 1", "", "my text 2"] + + +def test_pep_zero_writer_emit_title(): + pep0_writer = writer.PEPZeroWriter() + pep0_writer.emit_title("My Title") + pep0_writer.emit_subtitle("My Subtitle") + + assert pep0_writer.output == [ + "My Title", + "========", + "", + "My Subtitle", + "-----------", + "", + ] + + +@pytest.mark.parametrize( + "test_input, expected", + [ + ( + "pep-9000.rst", + { + "Fussyreverend, Francis": "one@example.com", + "Soulfulcommodore, Javier": "two@example.com", + }, + ), + ( + "pep-9001.rst", + {"Fussyreverend, Francis": "", "Soulfulcommodore, Javier": ""}, + ), + ], +) +def test_verify_email_addresses(test_input, expected): + # Arrange + peps = [ + parser.PEP( + Path(f"pep_sphinx_extensions/tests/peps/{test_input}"), AUTHORS_OVERRIDES + ) + ] + + # Act + out = writer._verify_email_addresses(peps) + + # Assert + assert out == expected + + +def test_sort_authors(): + # Arrange + authors_dict = { + "Zebra, Zoë": "zoe@example.com", + "lowercase, laurence": "laurence@example.com", + "Aardvark, Alfred": "alfred@example.com", + } + + # Act + out = writer._sort_authors(authors_dict) + + # Assert + assert out == ["Aardvark, Alfred", "lowercase, laurence", "Zebra, Zoë"] diff --git a/pep_sphinx_extensions/tests/peps/pep-9000.rst b/pep_sphinx_extensions/tests/peps/pep-9000.rst new file mode 100644 index 00000000000..84a117c17e5 --- /dev/null +++ b/pep_sphinx_extensions/tests/peps/pep-9000.rst @@ -0,0 +1,7 @@ +PEP: 9000 +Title: Test with authors with email addresses +Author: Francis Fussyreverend , + Javier Soulfulcommodore +Created: 20-Apr-2022 +Status: Draft +Type: Process diff --git a/pep_sphinx_extensions/tests/peps/pep-9001.rst b/pep_sphinx_extensions/tests/peps/pep-9001.rst new file mode 100644 index 00000000000..4a1a9e11532 --- /dev/null +++ b/pep_sphinx_extensions/tests/peps/pep-9001.rst @@ -0,0 +1,7 @@ +PEP: 9001 +Title: Test with authors with no email addresses +Author: Francis Fussyreverend, + Javier Soulfulcommodore +Created: 20-Apr-2022 +Status: Draft +Type: Process diff --git a/pep_sphinx_extensions/tests/utils.py b/pep_sphinx_extensions/tests/utils.py new file mode 100644 index 00000000000..19167d5526d --- /dev/null +++ b/pep_sphinx_extensions/tests/utils.py @@ -0,0 +1,6 @@ +AUTHORS_OVERRIDES = { + "Guido van Rossum": { + "Surname First": "van Rossum, Guido (GvR)", + "Name Reference": "GvR", + }, +} diff --git a/requirements.txt b/requirements.txt index 6f79491b0d2..0f4493675a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,7 @@ docutils >= 0.17.1 # For RSS feedgen >= 0.9.0 # For RSS feed + +# For tests +pytest +pytest-cov diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000000..e3d6f4f5c09 --- /dev/null +++ b/tox.ini @@ -0,0 +1,11 @@ +[tox] +envlist = + py{311, 310, 39} +skipsdist = true + +[testenv] +passenv = + FORCE_COLOR +commands = + make test +allowlist_externals = make From 9071118e9d6f16792e9c5b47c0c47d48e252d3a2 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 21 Apr 2022 11:50:52 +0300 Subject: [PATCH 02/15] Infra: add comment to explain magic number --- .../tests/pep_processor/transform/test_pep_footer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py index 2d19608f72d..0ff4bcc3258 100644 --- a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py +++ b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py @@ -35,4 +35,5 @@ def test_get_last_modified_timestamps(): out = pep_footer._get_last_modified_timestamps() assert len(out) >= 585 + # Should be a Unix timestamp and at least this assert out["pep-0008.txt"] >= 1643124055 From dae13c08768ffc780e8b9890a573b9022458916b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 21 Apr 2022 11:51:10 +0300 Subject: [PATCH 03/15] Infra: remove redundant parentheses --- pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py index 379a227d025..51dc9323d7c 100644 --- a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py @@ -11,7 +11,7 @@ def test_pep_repr(): pep8 = parser.PEP(Path("pep-0008.txt"), AUTHORS_OVERRIDES) - assert (repr(pep8)) == "" + assert repr(pep8) == "" def test_pep_less_than(): From ad0ba485e2d81ef8bb2e0d65f1cbc2fe82eecf1f Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 21 Apr 2022 11:51:41 +0300 Subject: [PATCH 04/15] Infra: remove unused code, handled via author override instead --- pep_sphinx_extensions/pep_zero_generator/author.py | 9 --------- .../tests/pep_zero_generator/test_author.py | 8 -------- 2 files changed, 17 deletions(-) diff --git a/pep_sphinx_extensions/pep_zero_generator/author.py b/pep_sphinx_extensions/pep_zero_generator/author.py index 24b2240255b..4425c6b3cdf 100644 --- a/pep_sphinx_extensions/pep_zero_generator/author.py +++ b/pep_sphinx_extensions/pep_zero_generator/author.py @@ -33,15 +33,6 @@ def parse_author_email(author_email_tuple: tuple[str, str], authors_overrides: d if name_parts.mononym is not None: return Author(name_parts.mononym, name_parts.mononym, email) - if name_parts.surname[1] == ".": - # Add an escape to avoid docutils turning `v.` into `22.`. - name_parts = _Name( - mononym=name_parts.mononym, - forename=name_parts.forename, - surname=f"\\{name_parts.surname}", - suffix=name_parts.suffix, - ) - if name_parts.suffix: last_first = f"{name_parts.surname}, {name_parts.forename}, {name_parts.suffix}" return Author(last_first, name_parts.surname, email) diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_author.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_author.py index 302fde9b1d0..8d5eb5da24c 100644 --- a/pep_sphinx_extensions/tests/pep_zero_generator/test_author.py +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_author.py @@ -37,14 +37,6 @@ email="eric@example.com", ), ), - ( - ("Bob v. Smith", "bob@example.com"), - author.Author( - last_first="\\v. Smith, Bob", - nick="\\v. Smith", - email="bob@example.com", - ), - ), ( ("Mariatta", "mariatta@example.com"), author.Author( From ee01a9c0571b59b5ec91622f775f27596177c1c0 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 21 Apr 2022 15:19:10 +0300 Subject: [PATCH 05/15] Infra: prettify Pep->PEP like Sig->SIG --- pep_sphinx_extensions/pep_processor/transforms/pep_headers.py | 2 +- .../tests/pep_processor/transform/test_pep_headers.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pep_sphinx_extensions/pep_processor/transforms/pep_headers.py b/pep_sphinx_extensions/pep_processor/transforms/pep_headers.py index 497545720a7..90872de0afc 100644 --- a/pep_sphinx_extensions/pep_processor/transforms/pep_headers.py +++ b/pep_sphinx_extensions/pep_processor/transforms/pep_headers.py @@ -205,7 +205,7 @@ def _process_pretty_url(url: str) -> tuple[str, str]: except KeyError as error: raise ValueError( f"{url} not a link to a recognized domain to prettify") from error - item_name = item_name.title().replace("Sig", "SIG") + item_name = item_name.title().replace("Sig", "SIG").replace("Pep", "PEP") return item_name, item_type diff --git a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py index 00d86855d88..21e39808240 100644 --- a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py +++ b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py @@ -47,7 +47,7 @@ def test_generate_list_url(test_input, expected): ), ( "https://discuss.python.org/c/peps/", - ("Peps Discourse", "category"), + ("PEPs Discourse", "category"), ), ], ) @@ -104,7 +104,7 @@ def test_process_pretty_url_invalid(test_input, expected): ), ( "https://discuss.python.org/c/peps/", - "Peps Discourse category", + "PEPs Discourse category", ), ], ) From 4c587dd07a028680d7082a9aef95aa64087f4fb1 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 21 Apr 2022 15:24:16 +0300 Subject: [PATCH 06/15] Infra: add xfailing case with 'first at example.com' --- .../tests/pep_zero_generator/test_author.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_author.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_author.py index 8d5eb5da24c..8334b1c5f85 100644 --- a/pep_sphinx_extensions/tests/pep_zero_generator/test_author.py +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_author.py @@ -49,6 +49,13 @@ last_first="Last, First, Jr.", nick="Last", email="first@example.com" ), ), + pytest.param( + ("First Last", "first at example.com"), + author.Author( + last_first="Last, First", nick="Last", email="first@example.com" + ), + marks=pytest.mark.xfail, + ), ], ) def test_parse_author_email(test_input, expected): From 228b6db71cbe900bce3b46d9389c3cca5b15abb4 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 21 Apr 2022 15:27:03 +0300 Subject: [PATCH 07/15] Infra: deduplicate test with parametrize --- .../tests/pep_zero_generator/test_parser.py | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py index 51dc9323d7c..26a0175a6b0 100644 --- a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py @@ -28,26 +28,21 @@ def test_pep_equal(): assert pep_a == pep_b -def test_pep_details(): - pep8 = parser.PEP(Path("pep-0008.txt"), AUTHORS_OVERRIDES) - - assert pep8.details(title_length=80) == { - "authors": "GvR, Warsaw, Coghlan", - "number": 8, - "status": " ", - "title": "Style Guide for Python Code", - "type": "P", - } - - -def test_pep_details_short_title(): +@pytest.mark.parametrize( + "test_input, expected", + [ + (80, "Style Guide for Python Code"), + (10, "Style ..."), + ], +) +def test_pep_details(test_input, expected): pep8 = parser.PEP(Path("pep-0008.txt"), AUTHORS_OVERRIDES) - assert pep8.details(title_length=10) == { + assert pep8.details(title_length=test_input) == { "authors": "GvR, Warsaw, Coghlan", "number": 8, "status": " ", - "title": "Style ...", + "title": expected, "type": "P", } From 7077eca88bf2689ae8accafb6fac14cd616e2440 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 21 Apr 2022 15:31:22 +0300 Subject: [PATCH 08/15] Infra: test legacy format and pseudo-obfuscated email --- .../tests/pep_zero_generator/test_parser.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py index 26a0175a6b0..c339434e0f0 100644 --- a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py @@ -58,6 +58,15 @@ def test_pep_details(test_input, expected): "First Last", [Author(last_first="Last, First", nick="Last", email="")], ), + ( + "user@example.com (First Last)", + [Author(last_first="Last, First", nick="Last", email="user@example.com")], + ), + pytest.param( + "First Last ", + [Author(last_first="Last, First", nick="Last", email="user@example.com")], + marks=pytest.mark.xfail, + ), ], ) def test_parse_authors(test_input, expected): From 57e1c743d282a8c8b46f9959ca5f552a2816faab Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 21 Apr 2022 15:33:16 +0300 Subject: [PATCH 09/15] Apply suggestions from code review Co-authored-by: CAM Gerlach --- .github/workflows/test.yml | 2 +- .pre-commit-config.yaml | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6cb91b77db2..ffb55406fb6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,7 @@ jobs: python -m pip install -U wheel python -m pip install -U tox - - name: tox tests + - name: Run tests with tox run: | tox -e py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e793feb40f0..46ff5710886 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,20 +46,23 @@ repos: rev: 22.3.0 hooks: - id: black + name: "Format with Black" args: [--target-version=py39] - files: "pep_sphinx_extensions/tests/.*" + files: 'pep_sphinx_extensions/tests/.*' - repo: https://github.com/PyCQA/isort rev: 5.10.1 hooks: - id: isort + name: "Sort imports with isort" args: [--profile=black] - files: "pep_sphinx_extensions/tests/.*" + files: 'pep_sphinx_extensions/tests/.*' - repo: https://github.com/tox-dev/tox-ini-fmt rev: 0.5.2 hooks: - id: tox-ini-fmt + name: "Format tox.ini" # RST checks - repo: https://github.com/pre-commit/pygrep-hooks From 2f7a28350497d8cc579f9c93a630928c269d97c0 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 23 Apr 2022 16:48:09 +0300 Subject: [PATCH 10/15] Infra: apply suggestions from code review Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: CAM Gerlach --- .github/workflows/test.yml | 2 +- .pre-commit-config.yaml | 6 ++++-- Makefile | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ffb55406fb6..927a20b5697 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Test +name: Test Sphinx Extensions on: push: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 46ff5710886..bb2ed78a06b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,7 +47,9 @@ repos: hooks: - id: black name: "Format with Black" - args: [--target-version=py39] + args: + - '--target-version=py39' + - '--target-version=py310' files: 'pep_sphinx_extensions/tests/.*' - repo: https://github.com/PyCQA/isort @@ -55,7 +57,7 @@ repos: hooks: - id: isort name: "Sort imports with isort" - args: [--profile=black] + args: ['--profile=black', '--atomic'] files: 'pep_sphinx_extensions/tests/.*' - repo: https://github.com/tox-dev/tox-ini-fmt diff --git a/Makefile b/Makefile index 5b88177ed6e..616f725cc0b 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ lint: venv $(VENVDIR)/bin/python3 -m pre_commit run --all-files test: venv - $(VENVDIR)/bin/python3 -m pytest --cov pep_sphinx_extensions --cov-report html --cov-report term --cov-report xml + $(VENVDIR)/bin/python3 -bb -X dev -W error -m pytest spellcheck: venv $(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install pre-commit From eb644d949b6ad6ac55937b58c42b9a3c1250b9f0 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 23 Apr 2022 16:46:50 +0300 Subject: [PATCH 11/15] Infra: simplify to assert link is good (plus let docutils do its thing) --- .../tests/pep_processor/transform/test_pep_footer.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py index 0ff4bcc3258..ad8cf278227 100644 --- a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py +++ b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py @@ -6,12 +6,7 @@ def test_add_source_link(): out = pep_footer._add_source_link(Path("pep-0008.txt")) - assert ( - str(out) == "Source: " - '' - "https://github.com/python/peps/blob/main/pep-0008.txt" - "" - ) + assert "https://github.com/python/peps/blob/main/pep-0008.txt" in str(out) def test_add_commit_history_info(): From 721a8621470dfa920dd4de467c2e685a45ee98d5 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 23 Apr 2022 16:49:06 +0300 Subject: [PATCH 12/15] Infra: add pytest config --- pytest.ini | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000000..b872465bfb6 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,8 @@ +[pytest] +addopts = -r a --strict-config --strict-markers --import-mode=importlib --cov pep_sphinx_extensions --cov-report html --cov-report xml +empty_parameter_set_mark = fail_at_collect +filterwarnings = + error +minversion = 6.0 +testpaths = pep_sphinx_extensions +xfail_strict = True From f68459cdc83ef133cc6d8b7042555c81d6f57cb5 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 21 Apr 2022 16:18:08 +0300 Subject: [PATCH 13/15] Infra: test on Windows --- .github/workflows/test.yml | 4 ++-- tox.ini | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 927a20b5697..78833bb568e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: fail-fast: false matrix: python-version: ["3.9", "3.10"] - os: [macos-latest, ubuntu-latest] + os: [windows-latest, macos-latest, ubuntu-latest] steps: - uses: actions/checkout@v3 @@ -42,7 +42,7 @@ jobs: - name: Run tests with tox run: | - tox -e py + tox -e py -- -v --cov-report term - name: Upload coverage uses: codecov/codecov-action@v3 diff --git a/tox.ini b/tox.ini index e3d6f4f5c09..24c48ad73bd 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,7 @@ skipsdist = true [testenv] passenv = FORCE_COLOR +deps = + -rrequirements.txt commands = - make test -allowlist_externals = make + python -m pytest {posargs} From 0fe2394e39cfd0c6ae5acbb7597fb9e5f73f6684 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 23 Apr 2022 17:08:30 +0300 Subject: [PATCH 14/15] Infra: install requirements only once, via make pages --- .github/workflows/render.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/render.yml b/.github/workflows/render.yml index bafa531dac4..264716958ec 100644 --- a/.github/workflows/render.yml +++ b/.github/workflows/render.yml @@ -22,7 +22,6 @@ jobs: - name: 👷‍ Install dependencies run: | python -m pip install --upgrade pip - python -m pip install --upgrade -r requirements.txt - name: 🔧 Render PEPs run: make pages -j$(nproc) From 261cf052134f8a49da862743b82d6c18cb6fc26a Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 25 Apr 2022 11:53:29 +0300 Subject: [PATCH 15/15] Infra: update pytest invocation in tox.ini Co-authored-by: CAM Gerlach --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 24c48ad73bd..396ef49d628 100644 --- a/tox.ini +++ b/tox.ini @@ -9,4 +9,4 @@ passenv = deps = -rrequirements.txt commands = - python -m pytest {posargs} + python -bb -X dev -W error -m pytest {posargs}