-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ned Batchelder
committed
Oct 19, 2023
1 parent
abab6f7
commit bdcb076
Showing
2 changed files
with
63 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,16 +1,72 @@ | ||
"""Tests of scriv/linkcheck.py""" | ||
|
||
import logging | ||
import textwrap | ||
|
||
import pytest | ||
|
||
from scriv.linkcheck import find_links | ||
from scriv.linkcheck import check_markdown_links, find_links | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"markdown_text, links", | ||
[ | ||
("Hello", []), | ||
( | ||
"""\ | ||
[one](https://two.com/hello) and | ||
[two](https://one.com/xyzzy). | ||
""", | ||
["https://one.com/xyzzy", "https://two.com/hello"], | ||
), | ||
( | ||
"""\ | ||
This is [an example](http://example1.com/ "Title") inline link. | ||
This is [an example] [id] reference-style link. | ||
[id]: http://example2.com/ "Optional Title Here" | ||
""", | ||
["http://example1.com/", "http://example2.com/"], | ||
), | ||
], | ||
) | ||
def test_find_links(markdown_text, links): | ||
found_links = sorted(find_links(markdown_text)) | ||
found_links = sorted(find_links(textwrap.dedent(markdown_text))) | ||
assert links == found_links | ||
|
||
|
||
def test_check_markdown_link(caplog, responses): | ||
caplog.set_level(logging.DEBUG, logger="scriv.linkcheck") | ||
responses.head("https://nedbat.com") | ||
check_markdown_links("""[hey](https://nedbat.com)!""") | ||
assert caplog.record_tuples == [ | ||
( | ||
"scriv.linkcheck", | ||
logging.DEBUG, | ||
"OK link: 'https://nedbat.com'", | ||
) | ||
] | ||
|
||
|
||
def test_check_404_markdown_link(caplog, responses): | ||
responses.head("https://nedbat.com", status=404) | ||
check_markdown_links("""[hey](https://nedbat.com)!""") | ||
assert caplog.record_tuples == [ | ||
( | ||
"scriv.linkcheck", | ||
logging.WARNING, | ||
"Failed check for 'https://nedbat.com': status code 404", | ||
) | ||
] | ||
|
||
|
||
def test_check_failing_markdown_link(caplog, responses): | ||
responses.head("https://nedbat.com", body=Exception("Buh?")) | ||
check_markdown_links("""[hey](https://nedbat.com)!""") | ||
assert caplog.record_tuples == [ | ||
( | ||
"scriv.linkcheck", | ||
logging.WARNING, | ||
"Failed check for 'https://nedbat.com': Buh?", | ||
) | ||
] |