Skip to content

Commit

Permalink
Add timeout option to accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Nov 19, 2022
1 parent 77a80b9 commit 5b1809a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions newshomepages/accessibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
@click.command()
@click.argument("handle")
@click.option("-o", "--output-dir", "output_dir", default="./")
def cli(handle: str, output_dir: str):
@click.option("--timeout", "timeout", default="180")
def cli(handle: str, output_dir: str, timeout: str = "180"):
"""Save the accessiblity JSON of a single site."""
# Get metadata
site = utils.get_site(handle)
Expand All @@ -22,11 +23,11 @@ def cli(handle: str, output_dir: str):
output_path.parent.mkdir(parents=True, exist_ok=True)

# Do the thing
_get_accessibility(site, output_path)
_get_accessibility(site, output_path, int(timeout))


@retry(tries=3, delay=5, backoff=2)
def _get_accessibility(data: typing.Dict, output_path: Path):
def _get_accessibility(data: typing.Dict, output_path: Path, timeout: int = 180):
"""Run a command that fetches the accessibility tree for the provided site."""
print(f":newspaper: Fetching a11y tree from {data['url']}")

Expand All @@ -38,7 +39,7 @@ def _get_accessibility(data: typing.Dict, output_path: Path):
"-o",
str(output_path),
"--timeout",
str(60 * 1000 * 3),
str(timeout * 1000), # Convert from seconds into milliseconds
]
javascript = utils.get_javascript(data["handle"])
if javascript:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_accessibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
def test_accessibility_cli(tmp_path):
"""Test a single accessibility run."""
runner = CliRunner()
result = runner.invoke(accessibility.cli, ["latimes", "-o", tmp_path])
result = runner.invoke(
accessibility.cli, ["latimes", "-o", tmp_path, "--timeout=240"]
)
assert result.exit_code == 0

0 comments on commit 5b1809a

Please sign in to comment.