-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Infra: add tests #2545
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
Merged
Merged
Infra: add tests #2545
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6e47986
Infra: add tests
hugovk 9071118
Infra: add comment to explain magic number
hugovk dae13c0
Infra: remove redundant parentheses
hugovk ad0ba48
Infra: remove unused code, handled via author override instead
hugovk ee01a9c
Infra: prettify Pep->PEP like Sig->SIG
hugovk 4c587dd
Infra: add xfailing case with 'first at example.com'
hugovk 228b6db
Infra: deduplicate test with parametrize
hugovk 7077eca
Infra: test legacy format and pseudo-obfuscated email
hugovk 57e1c74
Apply suggestions from code review
hugovk 2f7a283
Infra: apply suggestions from code review
hugovk eb644d9
Infra: simplify to assert link is good (plus let docutils do its thing)
hugovk 721a862
Infra: add pytest config
hugovk f68459c
Infra: test on Windows
hugovk 0fe2394
Infra: install requirements only once, via make pages
hugovk 261cf05
Infra: update pytest invocation in tox.ini
hugovk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Test Sphinx Extensions | ||
|
||
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: [windows-latest, 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: Run tests with tox | ||
run: | | ||
tox -e py -- -v --cov-report term | ||
|
||
- name: Upload coverage | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
flags: ${{ matrix.os }} | ||
name: ${{ matrix.os }} Python ${{ matrix.python-version }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ __pycache__ | |
*.pyo | ||
*~ | ||
*env | ||
.coverage | ||
.tox | ||
.vscode | ||
*.swp | ||
/build | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
34 changes: 34 additions & 0 deletions
34
pep_sphinx_extensions/tests/pep_processor/transform/test_pep_footer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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 "https://github.com/python/peps/blob/main/pep-0008.txt" in str(out) | ||
|
||
|
||
def test_add_commit_history_info(): | ||
out = pep_footer._add_commit_history_info(Path("pep-0008.txt")) | ||
|
||
assert str(out).startswith( | ||
"<paragraph>Last modified: " | ||
'<reference refuri="https://github.com/python/peps/commits/main/pep-0008.txt">' | ||
) | ||
# A variable timestamp comes next, don't test that | ||
assert str(out).endswith("</reference></paragraph>") | ||
|
||
|
||
def test_add_commit_history_info_invalid(): | ||
out = pep_footer._add_commit_history_info(Path("pep-not-found.txt")) | ||
|
||
assert str(out) == "<paragraph/>" | ||
|
||
|
||
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 | ||
hugovk marked this conversation as resolved.
Show resolved
Hide resolved
|
114 changes: 114 additions & 0 deletions
114
pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import pytest | ||
|
||
from pep_sphinx_extensions.pep_processor.transforms import pep_headers | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_input, expected", | ||
[ | ||
("[email protected]", "[email protected]"), | ||
("[email protected]", "https://groups.google.com/g/python-tulip"), | ||
("[email protected]", "https://mail.python.org/mailman/listinfo/db-sig"), | ||
("[email protected]", "https://mail.python.org/pipermail/import-sig/"), | ||
( | ||
"[email protected]", | ||
"https://mail.python.org/archives/list/[email protected]/", | ||
), | ||
], | ||
) | ||
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/[email protected]/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/[email protected]/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 |
25 changes: 25 additions & 0 deletions
25
pep_sphinx_extensions/tests/pep_processor/transform/test_pep_zero.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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="[email protected]", refuri="mailto:[email protected]" | ||
), | ||
'<raw format="html" xml:space="preserve">user at example.com</raw>', | ||
), | ||
( | ||
nodes.reference("", text="Introduction", refid="introduction"), | ||
'<reference refid="introduction">Introduction</reference>', | ||
), | ||
], | ||
) | ||
def test_generate_list_url(test_input, expected): | ||
CAM-Gerlach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
out = pep_zero._mask_email(test_input) | ||
|
||
assert str(out) == expected |
69 changes: 69 additions & 0 deletions
69
pep_sphinx_extensions/tests/pep_zero_generator/test_author.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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", "[email protected]"), | ||
author.Author( | ||
last_first="Last, First", nick="Last", email="[email protected]" | ||
), | ||
), | ||
( | ||
("Guido van Rossum", "[email protected]"), | ||
author.Author( | ||
last_first="van Rossum, Guido (GvR)", | ||
nick="GvR", | ||
email="[email protected]", | ||
), | ||
), | ||
( | ||
("Hugo van Kemenade", "[email protected]"), | ||
author.Author( | ||
last_first="van Kemenade, Hugo", | ||
nick="van Kemenade", | ||
email="[email protected]", | ||
), | ||
), | ||
( | ||
("Eric N. Vander Weele", "[email protected]"), | ||
author.Author( | ||
last_first="Vander Weele, Eric N.", | ||
nick="Vander Weele", | ||
email="[email protected]", | ||
), | ||
), | ||
( | ||
("Mariatta", "[email protected]"), | ||
author.Author( | ||
last_first="Mariatta", nick="Mariatta", email="[email protected]" | ||
), | ||
), | ||
( | ||
("First Last Jr.", "[email protected]"), | ||
author.Author( | ||
last_first="Last, First, Jr.", nick="Last", email="[email protected]" | ||
), | ||
), | ||
pytest.param( | ||
("First Last", "first at example.com"), | ||
author.Author( | ||
last_first="Last, First", nick="Last", email="[email protected]" | ||
), | ||
marks=pytest.mark.xfail, | ||
), | ||
], | ||
) | ||
def test_parse_author_email(test_input, expected): | ||
out = author.parse_author_email(test_input, AUTHORS_OVERRIDES) | ||
|
||
assert out == expected | ||
CAM-Gerlach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_parse_author_email_empty_name(): | ||
with pytest.raises(ValueError, match="Name is empty!"): | ||
author.parse_author_email(("", "[email protected]"), AUTHORS_OVERRIDES) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.