Skip to content

Commit

Permalink
Merge pull request #172 from thom311/th/validate-args
Browse files Browse the repository at this point in the history
[th/validate-args] testConfig: improve validation of {ConfServer,ConfClient}.args
  • Loading branch information
wizhaoredhat authored Dec 13, 2024
2 parents eb46da7 + b371804 commit d07f3bf
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions testConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ def _parse(

def _construct_args(pctx2: StructParseParseContext) -> tuple[str, ...]:
if isinstance(pctx2.arg, str):
return tuple(shlex.split(pctx2.arg))
try:
lst = shlex.split(pctx2.arg)
except Exception:
raise pctx2.value_error(
f"cannot parse command line {repr(pctx2.arg)}"
)
return tuple(lst)
if isinstance(pctx2.arg, list):
if not all(isinstance(x, str) for x in pctx2.arg):
raise pctx2.value_error(
Expand Down Expand Up @@ -145,6 +151,14 @@ def _construct_args(pctx2: StructParseParseContext) -> tuple[str, ...]:

return typing.cast("T2", result)

def _validate(self, test_type: TestType) -> None:
if self.args is not None:
if test_type not in (TestType.SIMPLE,):
raise self.value_error(
f"not supported with test type {repr(test_type.name)}",
key="args",
)


@strict_dataclass
@dataclass(frozen=True, kw_only=True)
Expand Down Expand Up @@ -319,21 +333,11 @@ def parse(
"currently only one client entry is supported", key="client"
)

for idx, s in enumerate(server):
if s.args is not None:
if test_type not in (TestType.SIMPLE,):
raise pctx.value_error(
f"args are not supported for test type {test_type}",
subpath=f".server[{idx}].args",
)

for idx, c in enumerate(client):
if c.args is not None:
if test_type not in (TestType.SIMPLE,):
raise pctx.value_error(
f"args are not supported for test type {test_type}",
subpath=f".client[{idx}].args",
)
for s in server:
s._validate(test_type)

for c in client:
c._validate(test_type)

return ConfConnection(
yamlidx=pctx.yamlidx,
Expand Down

0 comments on commit d07f3bf

Please sign in to comment.