Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/source/integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ We'll look at integration of CEL into another application from four perspectives

5. Finally, `External API`_ will review some elements of the API that are part of the integration interface.

The CEL compile and evaluation is designed to work inside a single thread.
In an application where multiple, concurrent threads will be performing CEL evaluations, each thread requires a distinct copy of a stateful :py:class:`celpy.Environment` instance.

Integration Essentials
======================

Expand Down
3 changes: 2 additions & 1 deletion features/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ CEL_SPEC_PATH ?= $(HERE)../../../google/cel-spec
CEL_SIMPLE_TESTDATA ?= $(CEL_SPEC_PATH)/tests/simple/testdata

# This is most -- but not all -- the feature files.
# Some are built manually. These are built from textproto files.
# These are built from textproto files to assure conformance with CEL-SPEC.
# Others in this directory are built manually.
FEATURES = \
basic.feature \
bindings_ext.feature \
Expand Down
37 changes: 34 additions & 3 deletions features/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,51 @@ for the ``TestAllTypes`` protobuf definition that some tests expect to be presen
Running the Conformance Tests
=============================

Run behave.
This can be done using **make** at the top level of the project.

::

make test

To test work-in-progress (WIP)::

make test-wip

As an alternative, this can be done by running **behave** manually, using the ``src`` directory directly (without an install of the package.)

::

PYTHONPATH=src uv run behave features

To run a subset, pick a feature file.
To run a subset of the features, pick a specific file.

::

PYTHONPATH=src uv run behave features/basic.feature

To run the ``@wip`` tests, include ``--tags=wip``.

To skip the ``@wip`` tests, include ``tags=~wip``.

Building the Conformance Test Features
======================================

The ``tools`` directory has a ``gherkinize.py`` application that builds the test suite.
See the ``tools/README.rst`` for more information.
See the ``tools/README.rst`` for more information on running this application.

Here's the bigger picture workflow:

1. Create a ``google/cel-spec`` project parallel to this project's directory.
This should be based on https://github.com/google/cel-spec

(Or, create it anywhere and set ``CEL_SPEC_PATH`` to refer to this directory.)

2. Find the tag for the most recent release (e.g. ``v0.24.0``)

3. Do ``git pull tag v0.24.0`` to get the released version.

4. Update this ``README.rst`` to reflect the version tag actually used.

5. Run ``make`` to copy the ``.textproto`` files to this directory and create ``feature`` files from them.


3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ dev = [
"types-protobuf>=6.32.1",
"types-pyyaml>=6.0.12",
"types-toml>=0.10.8",
"ipykernel>=7.2.0",
]

[tool.tox]
envlist = ["py310", "py311", "py312", "py313", "lint", "tools"]
envlist = ["py310", "py311", "py312", "py313", "py314", "lint", "tools"]
minversion = "4.24.0"

[tool.tox.env_run_base]
Expand Down
4 changes: 4 additions & 0 deletions src/celpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ class Environment:
At this time, external functions are bound to the CEL expression.
The :py:class:`celpy.Runnable` can be evaluated repeatedly with multiple inputs, avoiding the overheads of compiling for each input value.

.. note:: This cannot be shared by multiple threads.

Each thread must have an ``Environment`` instance.

.. todo:: For a better fit with Go language expectations

- A type adapters registry makes other native types available for CEL.
Expand Down
25 changes: 14 additions & 11 deletions tests/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""
C7N Type Adapter Test Cases.
"""

import datetime

import celpy.adapter
Expand All @@ -28,30 +29,32 @@ def test_json_to_cel():
assert str(celpy.adapter.json_to_cel(False)) == str(celpy.celtypes.BoolType(False))
assert celpy.adapter.json_to_cel(2.5) == celpy.celtypes.DoubleType(2.5)
assert celpy.adapter.json_to_cel(42) == celpy.celtypes.IntType(42)
assert celpy.adapter.json_to_cel("Hello, world!") == celpy.celtypes.StringType("Hello, world!")
assert celpy.adapter.json_to_cel("Hello, world!") == celpy.celtypes.StringType(
"Hello, world!"
)
assert celpy.adapter.json_to_cel(None) is None
assert celpy.adapter.json_to_cel(["Hello", "world!"]) == celpy.celtypes.ListType(
[
celpy.celtypes.StringType("Hello"),
celpy.celtypes.StringType("world!"),
]
)
assert celpy.adapter.json_to_cel(tuple(["Hello", "world!"])) == celpy.celtypes.ListType(
assert celpy.adapter.json_to_cel(
tuple(["Hello", "world!"])
) == celpy.celtypes.ListType(
[
celpy.celtypes.StringType("Hello"),
celpy.celtypes.StringType("world!"),
]
)
assert celpy.adapter.json_to_cel({"Hello": "world!"}) == celpy.celtypes.MapType(
{
celpy.celtypes.StringType("Hello"):
celpy.celtypes.StringType("world!"),
celpy.celtypes.StringType("Hello"): celpy.celtypes.StringType("world!"),
}
)
assert (
celpy.adapter.json_to_cel(datetime.datetime(2020, 9, 10, 11, 12, 13, tzinfo=datetime.timezone.utc))
== celpy.celtypes.TimestampType("2020-09-10T11:12:13Z")
)
assert (
celpy.adapter.json_to_cel(datetime.timedelta(days=42)) == celpy.celtypes.DurationType("42d")
)
assert celpy.adapter.json_to_cel(
datetime.datetime(2020, 9, 10, 11, 12, 13, tzinfo=datetime.timezone.utc)
) == celpy.celtypes.TimestampType("2020-09-10T11:12:13Z")
assert celpy.adapter.json_to_cel(
datetime.timedelta(days=42)
) == celpy.celtypes.DurationType("42d")
Loading
Loading