Skip to content

Commit

Permalink
Show error details (code)
Browse files Browse the repository at this point in the history
  • Loading branch information
patnr committed Feb 19, 2024
1 parent 2d756b4 commit 18d9c22
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ def _report_error(msg):
return True


def _link_is_down(link):
try:
request = urllib.request.Request(
link, method="HEAD", headers={'User-Agent': 'Mozilla'})
response = urllib.request.urlopen(request, timeout=2)
assert response.status == 200
except Exception as _:
return True


def _find_anchor(fname, anchor):
lines = fname.read_text().splitlines()
headings = [x for x in lines if x.startswith("# #")] # filter for "### Example heading"
Expand Down Expand Up @@ -72,8 +62,14 @@ def errm(issue):

# Internet links
if "http" in link:
if _link_is_down(link):
failed |= _report_error(errm("**requesting** "))
try:
request = urllib.request.Request(
link, method="HEAD", headers={'User-Agent': 'Mozilla'})
response = urllib.request.urlopen(request, timeout=2)
assert response.status == 200
except Exception as e:
failed |= True
_report_error(errm("**requesting**") + f"\nError:\n {e}")

# Local links
else:
Expand Down

0 comments on commit 18d9c22

Please sign in to comment.