Skip to content

Commit

Permalink
test(docs): ✅ update test to use httpx instead of grequests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriella Martin committed Apr 29, 2024
1 parent 388334e commit 48dfb8e
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from bs4 import BeautifulSoup
import grequests
import markdown
import asyncio
import os
import unittest

import httpx
import markdown
from bs4 import BeautifulSoup

from . import (
DOC_NAMES,
DOCS_DIR,
SCHEMA_NAMES,
all_properties,
DOCS_DIR,
DOC_NAMES,
property_doc_name,
schema_enum_registry,
)
Expand Down Expand Up @@ -117,14 +120,12 @@ def error_msg(schema_name, value, enum):
schema_name, v, enum
) # noqa

def test_urls_in_docs(s):
def exception(request, exception):
return f"{request} - {exception}"
def test_urls_in_docs(self):
async def async_requests(urls):
async with httpx.AsyncClient(timeout=60) as client:
responses = (client.get(url) for url in urls)
results = await asyncio.gather(*responses, return_exceptions=True)

def async_requests(urls):
results = grequests.map(
(grequests.get(u) for u in urls), exception_handler=exception, size=100
)
return results

urls = []
Expand All @@ -142,18 +143,21 @@ def async_requests(urls):

urls.append(url)

results = async_requests(urls)
results = asyncio.run(async_requests(urls))

warns = []
not_founds = []
for resp in results:
if not resp.ok:
warns.append(f"failed {resp.status_code}: {resp.url}")
if resp.status_code in [404]:
not_founds.append(resp.url)

if not_founds:
raise ValueError(f"URLs not found: \n {not_founds}")
for response in results:
if isinstance(response, httpx.HTTPError):
warns.append(f"failed {response!s}: {response.request.url!s}")
else:
if not response.is_success:
warns.append(f"failed {response.status_code}: {response.url!s}")

if response.status_code in (404,):
not_founds.append(str(response.url))

assert not not_founds, f"URLs not found: \n {not_founds}"

print("\n=== Minor URL link warnings ===\n")
for w in warns:
Expand Down

0 comments on commit 48dfb8e

Please sign in to comment.