1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
from hassil.util import (
is_template,
merge_dict,
normalize_text,
normalize_whitespace,
remove_escapes,
remove_punctuation,
)
def test_merge_dict():
base_dict = {"a": 1, "list": [1], "dict": {"a": 1}}
merge_dict(base_dict, {"a": 2, "list": [2], "dict": {"b": 2}})
assert base_dict == {"a": 2, "list": [1, 2], "dict": {"a": 1, "b": 2}}
def test_remove_escapes():
assert remove_escapes("\\[test\\]") == "[test]"
def test_normalize_whitespace():
assert normalize_whitespace("this is a test") == "this is a test"
def test_normalize_text():
assert normalize_text("tHIS is A Test") == "tHIS is A Test"
def test_is_template():
assert not is_template("just some plain text")
assert is_template("[optional] word")
assert is_template("a {list}")
assert is_template("a <rule>")
assert is_template("(a group)")
assert is_template("an | alternative")
def test_remove_punctuation():
assert remove_punctuation("test") == "test"
assert remove_punctuation("test.") == "test"
assert remove_punctuation("A.C.") == "A.C."
assert remove_punctuation("A.C") == "A.C"
|