Skip to content

Commit

Permalink
Create versioned miniatures and make changes to the existing summary …
Browse files Browse the repository at this point in the history
…test
  • Loading branch information
adwait-godbole committed Aug 22, 2024
1 parent bf40803 commit b7d2cd0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 36 deletions.
43 changes: 35 additions & 8 deletions bowtie/tests/miniatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,53 @@ def links(dialect: Dialect):
"""
return lambda schema, registry: lambda instance: None


@fake(name="versioned", version="1.0")
def version_1(dialect: Dialect):
def foo_v1(dialect: Dialect):
"""
An implementation which claims to be in version 1.0.
Claims to be in version 1.0 and changes its behaviour based on the dialect.
The validity result of instances should not be relied on.
"""
return lambda schema, registry: lambda instance: None
if dialect == Dialect.by_short_name()["draft2020-12"]:
return lambda schema, registry: lambda instance: ARBITRARILY_INVALID
elif dialect == Dialect.by_short_name()["draft2019-09"]:
return lambda schema, registry: lambda instance: None

return lambda schema, registry: lambda instance: None

@fake(name="versioned", version="2.0")
def version_2(dialect: Dialect):
def foo_v2(dialect: Dialect):
"""
An implementation which claims to be in version 2.0.
Claims to be in version 2.0 and changes its behaviour based on the dialect.
The validity result of instances should not be relied on.
"""
if dialect == Dialect.by_short_name()["draft2020-12"]:
return lambda schema, registry: lambda instance: None
elif dialect == Dialect.by_short_name()["draft2019-09"]:
return lambda schema, registry: lambda instance: ARBITRARILY_INVALID

return lambda schema, registry: lambda instance: None

def by_version_and_dialect(version: str, dialect: str):
"""
An implementation whose behaviour changes based on its version and dialect.
Use this by passing a connectable parameter, e.g. via
``direct:miniatures:by_version_and_dialect,version=1.0,dialect=draft2020-12``.
The validity result of instances should not be relied on.
"""
if version == "1.0":
return fake(
name="foo",
version=version,
dialects=frozenset([Dialect.by_short_name()[dialect]]),
)(foo_v1)()
elif version == "2.0":
return fake(
name="foo",
version=version,
dialects=frozenset([Dialect.by_short_name()[dialect]]),
)(foo_v2)()

def naively_correct(schema, registry):
"""
Expand Down
40 changes: 12 additions & 28 deletions bowtie/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2597,9 +2597,9 @@ async def test_summary_show_failures_markdown_different_versions(tmp_path):
"-i",
"direct:null",
"-i",
miniatures.version_1,
"direct:bowtie.tests.miniatures:by_version_and_dialect,version=1.0,dialect=draft2020-12",
"-i",
miniatures.version_2,
"direct:bowtie.tests.miniatures:by_version_and_dialect,version=2.0,dialect=draft2020-12",
"--expect",
"valid",
tmp_path / "schema.json",
Expand All @@ -2616,34 +2616,18 @@ async def test_summary_show_failures_markdown_different_versions(tmp_path):
stdin=validate_stdout,
)
assert stderr == ""
assert stdout in {
dedent(
"""\
# Bowtie Failures Summary
| Implementation | Skips | Errors | Failures |
|:----------------------:|:-:|:-:|:-:|
| null (python) | 0 | 0 | 0 |
| versioned 2.0 (python) | 0 | 0 | 0 |
| versioned 1.0 (python) | 0 | 0 | 0 |
**2 tests ran**
""",
),
dedent(
"""\
# Bowtie Failures Summary
assert stdout == dedent(
"""\
# Bowtie Failures Summary
| Implementation | Skips | Errors | Failures |
|:----------------------:|:-:|:-:|:-:|
| null (python) | 0 | 0 | 0 |
| versioned 1.0 (python) | 0 | 0 | 0 |
| versioned 2.0 (python) | 0 | 0 | 0 |
| Implementation | Skips | Errors | Failures |
|:----------------:|:-:|:-:|:-:|
| foo 2.0 (python) | 0 | 0 | 0 |
| foo 1.0 (python) | 0 | 0 | 2 |
**2 tests ran**
""",
),
}
**2 tests ran**
""",
)


@pytest.mark.asyncio
Expand Down

0 comments on commit b7d2cd0

Please sign in to comment.