Spaces:
Sleeping
Sleeping
Download tests/test_server.py from build-small-hackathon/tiny-trigger: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/build-small-hackathon/tiny-trigger/resolve/498b1c6598afd1f1fbdbf455287c016ad656d8ab/tests/test_server.py
- Command line
-
hf download hf://spaces/build-small-hackathon/tiny-trigger@498b1c6598afd1f1fbdbf455287c016ad656d8ab/tests/test_server.py
-
curl -L -o test_server.py https://huggingface.co/spaces/build-small-hackathon/tiny-trigger/resolve/498b1c6598afd1f1fbdbf455287c016ad656d8ab/tests/test_server.py
1.48 kB
| from __future__ import annotations | |
| import json | |
| from server import _merge_class_names, _merge_documents | |
| from tiny_trigger.automation import AutomationDocument, load_automation_text | |
| def test_merge_documents_replaces_same_named_rule() -> None: | |
| existing = load_automation_text( | |
| json.dumps( | |
| { | |
| "rules": [ | |
| { | |
| "name": "monitor-lights", | |
| "when": {"all": [{"present": {"label": "person"}}]}, | |
| "then": [{"type": "simulate", "name": "old action"}], | |
| } | |
| ] | |
| } | |
| ) | |
| ) | |
| compiled = load_automation_text( | |
| json.dumps( | |
| { | |
| "rules": [ | |
| { | |
| "name": "monitor-lights", | |
| "when": {"all": [{"present": {"label": "monitor"}}]}, | |
| "then": [{"type": "simulate", "name": "new action"}], | |
| } | |
| ] | |
| } | |
| ) | |
| ) | |
| merged = _merge_documents(existing, compiled) | |
| assert isinstance(merged, AutomationDocument) | |
| assert [rule.name for rule in merged.rules] == ["monitor-lights"] | |
| assert merged.rules[0].then[0].name == "new action" | |
| def test_merge_class_names_adds_rule_labels_without_duplicates() -> None: | |
| assert _merge_class_names(["person", "Monitor"], ["monitor", "guitar"]) == [ | |
| "person", | |
| "Monitor", | |
| "guitar", | |
| ] | |