Skip to content

Commit

Permalink
test more error types
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-evans committed Dec 6, 2024
1 parent e170d1a commit 807928c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tests/unit_server/arghandler_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test server/arghandler.py."""

# pylint: disable=W0212,W0621

import argparse
import json
import sys
from typing import Any, Dict, List, Tuple, Union, cast
Expand All @@ -16,6 +15,8 @@
from rest_tools.server.arghandler import ArgumentHandler, ArgumentSource
from rest_tools.server.handler import RestHandler

# pylint: disable=W0212,W0621

# these tests are only for 3.9+
if sys.version_info < (3, 9):
pytest.skip("only for 3.9+", allow_module_level=True) # type: ignore[var-annotated]
Expand Down Expand Up @@ -543,7 +544,11 @@ def test_220__argparse_nargs(argument_source: str) -> None:
"argument_source",
[QUERY_ARGUMENTS, JSON_BODY_ARGUMENTS],
)
def test_230__argparse_catch_most__error(argument_source: str) -> None:
@pytest.mark.parametrize(
"exc",
[TypeError, ValueError, argparse.ArgumentTypeError, argparse.ArgumentError],
)
def test_230__argparse_catch_most__error(argument_source: str, exc: Exception) -> None:
"""Test `argument_source` arguments using argparse's advanced options."""
args: Dict[str, Any] = {
"bar": "True",
Expand All @@ -560,7 +565,7 @@ def test_230__argparse_catch_most__error(argument_source: str) -> None:
)

def _error_now():
raise TypeError("it's a bad value")
raise exc("it's a bad value")

for arg, _ in args.items():
print()
Expand Down

0 comments on commit 807928c

Please # to comment.