Fix selection bug to require that arguments be consumed by a branch

This commit is contained in:
Tom 2025-03-24 15:28:06 +00:00
parent c31467fb04
commit 06c84fb20e
2 changed files with 28 additions and 0 deletions

View File

@ -261,6 +261,7 @@ class Qube:
selection: dict[str, str | list[str]],
mode: Literal["strict", "relaxed"] = "relaxed",
prune=True,
consume=True,
) -> "Qube":
# make all values lists
selection = {k: v if isinstance(v, list) else [v] for k, v in selection.items()}

27
tests/test_selection.py Normal file
View File

@ -0,0 +1,27 @@
from qubed import Qube
q = Qube.from_dict(
{
"class=od": {
"expver=0001": {"param=1": {}, "param=2": {}},
"expver=0002": {"param=1": {}, "param=2": {}},
},
"class=rd": {"param=1": {}, "param=2": {}, "param=3": {}},
}
)
def test_consumption():
assert q.select({"expver": "0001"}) == Qube.from_dict(
{"class=od": {"expver=0001": {"param=1": {}, "param=2": {}}}}
)
def test_consumption_off():
expected = Qube.from_dict(
{
"class=od": {"expver=0001": {"param=1": {}, "param=2": {}}},
"class=rd": {"param=1": {}, "param=2": {}, "param=3": {}},
}
)
assert q.select({"expver": "0001"}, consume=False) == expected