Skip to content

Commit 6196d2e

Browse files
authored
Add conformance testing to string.format implementation (#307)
Fixes #257 This adds conformance testing to our implementation of `string.format`. cel-python does not currently provide a `string.format` function so we implement our own and add it to the protovalidate-python CEL runtime. While formatting is not (yet) a part of the cel-spec, they do provide conformance test data for validating behavior. So, to ensure we are conformant, we use this test data and run it against our implementation. See the test data [here](https://github.com/google/cel-spec/blob/master/tests/simple/testdata/string_ext.textproto). Note that this file contains various sections for testing. However, we are only concerned with the `format` and `format_errors` sections. In addition, since we are only testing for formatting, we do not handle every `oneof` case or variation in the `SimpleTest` definition -- only expected results or evaluation errors. If others are added down the road in future versions of the spec, we can adjust these tests.
1 parent 2559d06 commit 6196d2e

25 files changed

+3438
-102
lines changed

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ ADD_LICENSE_HEADER := $(BIN)/license-header \
1818
--year-range "2023-2025"
1919
# This version should be kept in sync with the version in buf.yaml
2020
PROTOVALIDATE_VERSION ?= v0.11.0
21+
# Version of the cel-spec that this implementation is conformant with
22+
# This should be kept in sync with the version in format_test.py
23+
CEL_SPEC_VERSION ?= v0.24.0
24+
TESTDATA_FILE := tests/testdata/string_ext_$(CEL_SPEC_VERSION).textproto
2125

2226
.PHONY: help
2327
help: ## Describe useful make targets
@@ -36,6 +40,7 @@ generate: $(BIN)/buf $(BIN)/license-header ## Regenerate code and license header
3640
rm -rf gen
3741
$(BIN)/buf generate buf.build/bufbuild/protovalidate:$(PROTOVALIDATE_VERSION)
3842
$(BIN)/buf generate buf.build/bufbuild/protovalidate-testing:$(PROTOVALIDATE_VERSION)
43+
$(BIN)/buf generate buf.build/google/cel-spec:$(CEL_SPEC_VERSION) --exclude-path cel/expr/conformance/proto2 --exclude-path cel/expr/conformance/proto3
3944
$(BIN)/buf generate
4045
$(ADD_LICENSE_HEADER)
4146

@@ -46,7 +51,7 @@ format: install $(BIN)/license-header ## Format code
4651
pipenv run ruff check --fix protovalidate tests
4752

4853
.PHONY: test
49-
test: generate install ## Run unit tests
54+
test: generate install gettestdata ## Run unit tests
5055
pipenv run pytest
5156

5257
.PHONY: conformance
@@ -69,6 +74,13 @@ checkgenerate: generate
6974
@# Used in CI to verify that `make generate` doesn't produce a diff.
7075
test -z "$$(git status --porcelain | tee /dev/stderr)"
7176

77+
.PHONY: gettestdata
78+
gettestdata: $(TESTDATA_FILE)
79+
80+
$(TESTDATA_FILE):
81+
mkdir -p $(dir @)
82+
curl -fsSL -o $@ https://raw.githubusercontent.com/google/cel-spec/refs/tags/$(CEL_SPEC_VERSION)/tests/simple/testdata/string_ext.textproto
83+
7284
$(BIN):
7385
@mkdir -p $(BIN)
7486

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ protobuf = "==6.*"
99

1010
[dev-packages]
1111
pytest = "*"
12+
pytest-subtests = "*"
1213
mypy = "*"
1314
ruff = "*"
1415
types-protobuf = "==6.30.2.20250503"

Pipfile.lock

Lines changed: 39 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buf.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
version: v2
33
deps:
44
- name: buf.build/bufbuild/protovalidate
5-
commit: 0409229c37804d6187ee0806eb4eebce
6-
digest: b5:795db9d3a6e066dc61d99ac651fa7f136171869abe2211ca272dd84aada7bc4583b9508249fa5b61300a5b1fe8b6dbf6edbc088aa0345d1ccb9fff705e3d48e9
5+
commit: 7712fb530c574b95bc1d57c0877543c3
6+
digest: b5:b3e9c9428384357e3b73e4d5a4614328b0a4b1595b10163bbe9483fa16204749274c41797bd49b0d716479c855aa35c1172a94f471fa120ba8369637fd138829
77
- name: buf.build/bufbuild/protovalidate-testing
8-
commit: 5acbe1f3c8f24ced9466b9ccccad4cb0
9-
digest: b5:5e9d54d19ce3d9d368f4b1b5ee4f20094d1c33d0f2dca19536339335c2e70d5ffedbd4fa28e290b59ecae0671c9d2dc20b6b8ebba5a9ac76cbf5f9d2af655ef4
8+
commit: 485aa672244b4befa63053fdc75d4a03
9+
digest: b5:82930441f8c3ad186d825d226536baec007b94d23fa974b9905abea7b891a43bd276969d7e8a27453b632cb8b1557079decdd3044306a81de34316d2707089be

gen/cel/expr/checked_pb2.py

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)