Skip to content

Commit

Permalink
Merge branch 'topic/bbannier/simplify-baselines'
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Feb 24, 2025
2 parents 1fa5718 + aabb000 commit aede394
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ repos:
- id: check-added-large-files

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
rev: v0.9.7
hooks:
- id: ruff
- id: ruff-format

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.43.0
rev: v0.44.0
hooks:
- id: markdownlint-fix
16 changes: 16 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
1.3.1-5 | 2025-02-24 18:23:48 +0100

* Bump pre-commit hooks (Benjamin Bannier, Corelight)

* Simplify baseline names in snapshot testing (Benjamin Bannier, Corelight)

We previously would include a running number for the specific test
parameterization in the snapshot for each sample test. This meant that
tests could get renamed whenever a new sample was added.

With this patch we now override the default name enumerating each
parameterization and instead set it to the name of the sample a test
runs on. With that snapshots should be much more stable.

* build(deps): bump syrupy from 4.8.1 to 4.8.2 (dependabot[bot])

1.3.1 | 2025-01-24 17:02:57 +0100

1.3.0-18 | 2025-01-24 17:02:50 +0100
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.1
1.3.1-5
19 changes: 7 additions & 12 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,27 @@ def _format(script: zeekscript.Script):
return buf.getvalue()


def _get_samples():
def _get_samples() -> list[Path]:
"""Helper to enumerate samples"""

# We exclude directories since we store snapshots along with the samples.
# This assumes that there are no tests in subdirectories of `SAMPLES_DIR`.
try:
# Make sample order deterministic.
return sorted([sample for sample in SAMPLES_DIR.iterdir() if sample.is_file()])
except FileNotFoundError:
return []
assert SAMPLES_DIR.exists(), "directory with code samples not found"
return sorted([sample for sample in SAMPLES_DIR.iterdir() if sample.is_file()])


# For each file in `SAMPLES_DIR` test formatting of the file.
@pytest.mark.parametrize("sample", _get_samples())
@pytest.mark.parametrize(
"sample", _get_samples(), ids=[str(os.path.basename(s)) for s in _get_samples()]
)
def test_samples(sample: Path, snapshot: SnapshotAssertion):
input_ = zeekscript.Script(sample)

assert input_.parse(), f"failed to parse input {sample}"
assert not input_.has_error(), f"parse result for {sample} has parse errors"

name = str(os.path.basename(sample))

output = _format(input_)
assert output == snapshot(name=name), (
f"formatted {sample} inconsistent with snapshot"
)
assert output == snapshot(), f"formatted {sample} inconsistent with snapshot"

output2 = _format(input_)
assert output2 == output, f"idempotency violation for {sample}"
2 changes: 1 addition & 1 deletion zeekscript/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Wrapper around more low-level tests."""

__version__ = "1.3.1"
__version__ = "1.3.1-5"
__all__ = [
"Formatter",
"Script",
Expand Down

0 comments on commit aede394

Please sign in to comment.