-
-
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
Infra: add tests #2545
Changes from 9 commits
6e47986
9071118
dae13c0
ad0ba48
ee01a9c
4c587dd
228b6db
7077eca
57e1c74
2f7a283
eb644d9
721a862
f68459c
0fe2394
261cf05
File filter
F 8000 ilter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we test on multiple OSes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could probably just do Ubuntu? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes sense to either only test on one platform, or test on Ubuntu, macOS and Windows. I'd prefer the latter, since these checks only run when we make build system changes and we may as well make sure things aren't broken on a specific platform (though it seems relatively unlikely). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, let's add Windows. |
||
|
||
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 | ||
|
||
- name: Upload coverage | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
flags: ${{ matrix.os }} | ||
name: ${{ matrix.os }} Python ${{ matrix.python-version }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ __pycache__ | |
*.pyo | ||
*~ | ||
*env | ||
.coverage | ||
.tox | ||
.vscode | ||
*.swp | ||
/build | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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) == "<paragraph>Source: " | ||
'<reference refuri="https://github.com/python/peps/blob/main/pep-0008.txt">' | ||
"https://github.com/python/peps/blob/main/pep-0008.txt</reference>" | ||
"</paragraph>" | ||
CAM-Gerlach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
|
||
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
|
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", | ||
[ | ||
("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_heade F438 rs._make_link_pretty(test_input) | ||
|
||
assert out == expected |
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="user@example.com", refuri="mailto:user@example.com" | ||
), | ||
'<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 |
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", "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", | ||
), | ||
), | ||
( | ||
("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" | ||
), | ||
), | ||
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): | ||
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(("", "user@example.com"), AUTHORS_OVERRIDES) |
Uh oh!
There was an error while loading. Please reload this page.