Skip to content

Commit

Permalink
Adjust bats tests to new CLI and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
fkglr committed Oct 24, 2024
1 parent 4d7564b commit 4a71646
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/gallia/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import argcomplete
from pydantic import Field, create_model

from pydantic_argparse import ArgumentParser
from pydantic_argparse import BaseCommand as PydanticBaseCommand
from pydantic_core import PydanticUndefined
Expand Down Expand Up @@ -110,7 +109,7 @@ def parse_and_run(
auto_complete: bool = True,
setup_log: bool = True,
top_level_options: Mapping[str, Callable[[], None]] | None = None,
show_help_on_zero_args: bool = True
show_help_on_zero_args: bool = True,
) -> Never:
"""
Creates an argument parser out of the given command hierarchy and runs the command with its argument.
Expand Down
2 changes: 2 additions & 0 deletions src/gallia/command/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ def err_int(x: str, base: int) -> int:
Usage: x: HexBytes = ....
"""


def _process_ranges(value: Any) -> Any:
if isinstance(value, str):
return unravel(",".join(value.split()))
elif isinstance(value, list) and all(isinstance(x, str) for x in value):
return unravel(",".join(value))
return value


Ranges = Annotated[list[int], BeforeValidator(_process_ranges)]
"""
Special type for a field, which parses one-dimensional ranges.
Expand Down
4 changes: 3 additions & 1 deletion src/gallia/commands/scan/uds/reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@


class ResetScannerConfig(UDSScannerConfig):
sessions: Ranges | None = Field(description="Set list of sessions to be tested; all if None")
sessions: Ranges | None = Field(
None, description="Set list of sessions to be tested; all if None"
)
skip: Ranges2D = Field(
{},
metavar="SESSION_ID:ID",
Expand Down
2 changes: 1 addition & 1 deletion tests/bats/001-invocation.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ load "helpers"
}

@test "invoke gallia without config" {
run -1 gallia --show-config
run -78 gallia --show-config
}

@test "invoke gallia with config" {
Expand Down
8 changes: 4 additions & 4 deletions tests/bats/002-scans.bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ teardown() {
}

@test "scan identifiers sid 0x22" {
gallia scan uds identifiers --start 0 --end 100 --sid 0x22
gallia scan uds identifiers --start 0 --end 100 --service 0x22
}

@test "scan identifiers sid 0x2e" {
gallia scan uds identifiers --start 0 --end 100 --sid 0x2e
gallia scan uds identifiers --start 0 --end 100 --service 0x2e
}

@test "scan identifiers sid 0x31" {
gallia scan uds identifiers --start 0 --end 100 --sid 0x31
gallia scan uds identifiers --start 0 --end 100 --service 0x31
}

@test "scan reset" {
Expand All @@ -52,6 +52,6 @@ teardown() {

@test "scan memory" {
for sid in 0x23 0x34 0x35 0x3d; do
gallia scan uds memory --sid "$sid"
gallia scan uds memory --service "$sid"
done
}

0 comments on commit 4a71646

Please sign in to comment.