Skip to content

Commit 3984ef6

Browse files
committed
And now push the smoke test down onto Implementation.
1 parent 3230177 commit 3984ef6

File tree

4 files changed

+94
-34
lines changed

4 files changed

+94
-34
lines changed

bowtie/_cli.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -715,28 +715,6 @@ async def smoke(
715715
for implementation in implementations:
716716
echo(f"Testing {implementation.name!r}...\n", file=sys.stderr)
717717

718-
# FIXME: All dialects / and/or newest dialect with proper sort
719-
dialect = max(implementation.info().dialects, key=str)
720-
runner = await implementation.start_speaking(dialect)
721-
722-
cases = [
723-
TestCase(
724-
description="allow-everything schema",
725-
schema={"$schema": str(dialect)},
726-
tests=[
727-
Test(description="First", instance=1, valid=True),
728-
Test(description="Second", instance="foo", valid=True),
729-
],
730-
),
731-
TestCase(
732-
description="allow-nothing schema",
733-
schema={"$schema": str(dialect), "not": {}},
734-
tests=[
735-
Test(description="First", instance=12, valid=False),
736-
],
737-
),
738-
]
739-
740718
match format:
741719
case "json":
742720
serializable: list[dict[str, Any]] = []
@@ -758,8 +736,7 @@ def see(seq_case: SeqCase, response: SeqResult):
758736
)
759737
echo(f" · {seq_case.case.description}: {signs}")
760738

761-
for seq_case in SeqCase.for_cases(cases):
762-
result = await seq_case.run(runner=runner)
739+
async for seq_case, result in implementation.smoke():
763740
if result.unsuccessful().causes_stop:
764741
exit_code |= _EX_DATAERR
765742
see(seq_case, result)

bowtie/_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class SeqCase:
146146
case: TestCase
147147

148148
@classmethod
149-
def for_cases(cls, cases: Iterable[TestCase]):
149+
def for_cases(cls, cases: Iterable[TestCase]) -> Iterable[SeqCase]:
150150
return (cls(seq=i, case=case) for i, case in enumerate(cases))
151151

152152
def run(self, runner: DialectRunner) -> Awaitable[SeqResult]:

bowtie/_core.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,53 @@ async def _send(self, cmd: _commands.Command[Any], retry: int = 3) -> Any:
436436
)
437437
break
438438
return INVALID
439+
440+
async def smoke(
441+
self,
442+
) -> AsyncIterator[tuple[_commands.SeqCase, _commands.SeqResult],]:
443+
"""
444+
Smoke test this implementation.
445+
"""
446+
# FIXME: All dialects / and/or newest dialect with proper sort
447+
dialect = max(self.info().dialects, key=str)
448+
runner = await self.start_speaking(dialect)
449+
450+
instances = [
451+
("nil", None),
452+
("boolean", True),
453+
("integer", 37),
454+
("number", 37.37),
455+
("string", "37"),
456+
("array", [37]),
457+
("object", {"foo": 37}),
458+
]
459+
cases = [
460+
_commands.TestCase(
461+
description="allow-everything",
462+
schema={"$schema": str(dialect)},
463+
tests=[
464+
_commands.Test(
465+
description=json_type,
466+
instance=instance,
467+
valid=True,
468+
)
469+
for json_type, instance in instances
470+
],
471+
),
472+
_commands.TestCase(
473+
description="allow-nothing",
474+
schema={"$schema": str(dialect), "not": {}},
475+
tests=[
476+
_commands.Test(
477+
description=json_type,
478+
instance=instance,
479+
valid=False,
480+
)
481+
for json_type, instance in instances
482+
],
483+
),
484+
]
485+
486+
for seq_case in _commands.SeqCase.for_cases(cases):
487+
result = await seq_case.run(runner=runner)
488+
yield seq_case, result

tests/test_integration.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ async def test_smoke_pretty(envsonschema):
601601
dedent(stdout)
602602
== dedent(
603603
"""
604-
· allow-everything schema: ✗✗
605-
· allow-nothing schema:
604+
· allow-everything: ✗✗✗✗✗✗✗
605+
· allow-nothing: ✓✓✓✓✓✓
606606
""",
607607
).lstrip("\n")
608608
), stderr
@@ -625,27 +625,60 @@ async def test_smoke_json(envsonschema):
625625
assert jsonout == [
626626
{
627627
"case": {
628-
"description": "allow-everything schema",
628+
"description": "allow-everything",
629629
"schema": {
630630
"$schema": "https://json-schema.org/draft/2020-12/schema",
631631
},
632632
"tests": [
633-
{"description": "First", "instance": 1},
634-
{"description": "Second", "instance": "foo"},
633+
{"description": "nil", "instance": None},
634+
{"description": "boolean", "instance": True},
635+
{"description": "integer", "instance": 37},
636+
{"description": "number", "instance": 37.37},
637+
{"description": "string", "instance": "37"},
638+
{"description": "array", "instance": [37]},
639+
{"description": "object", "instance": {"foo": 37}},
640+
],
641+
},
642+
"result": {
643+
"results": [
644+
{"valid": False},
645+
{"valid": False},
646+
{"valid": False},
647+
{"valid": False},
648+
{"valid": False},
649+
{"valid": False},
650+
{"valid": False},
635651
],
636652
},
637-
"result": {"results": [{"valid": False}, {"valid": False}]},
638653
},
639654
{
640655
"case": {
641-
"description": "allow-nothing schema",
656+
"description": "allow-nothing",
642657
"schema": {
643658
"$schema": "https://json-schema.org/draft/2020-12/schema",
644659
"not": {},
645660
},
646-
"tests": [{"description": "First", "instance": 12}],
661+
"tests": [
662+
{"description": "nil", "instance": None},
663+
{"description": "boolean", "instance": True},
664+
{"description": "integer", "instance": 37},
665+
{"description": "number", "instance": 37.37},
666+
{"description": "string", "instance": "37"},
667+
{"description": "array", "instance": [37]},
668+
{"description": "object", "instance": {"foo": 37}},
669+
],
670+
},
671+
"result": {
672+
"results": [
673+
{"valid": False},
674+
{"valid": False},
675+
{"valid": False},
676+
{"valid": False},
677+
{"valid": False},
678+
{"valid": False},
679+
{"valid": False},
680+
],
647681
},
648-
"result": {"results": [{"valid": False}]},
649682
},
650683
], stderr
651684

0 commit comments

Comments
 (0)