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: 1 addition & 2 deletions src/assertionengine/assertion_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
from typing import Any, TypeVar, cast

from robot.libraries.BuiltIn import BuiltIn
from robot.utils import is_truthy # type: ignore

from .type_converter import type_converter
from .type_converter import is_truthy, type_converter

__version__ = "4.0.0"

Expand Down
10 changes: 10 additions & 0 deletions src/assertionengine/type_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@

from typing import Any

FALSE_STRINGS = {"FALSE", "NO", "OFF", "0", "UNCHECKED", "NONE", ""}


def type_converter(argument: Any) -> str:
return type(argument).__name__.lower()


def is_truthy(item: Any) -> bool:
if isinstance(item, bool):
return item
if isinstance(item, str):
return item.upper() not in FALSE_STRINGS
return bool(item)
7 changes: 7 additions & 0 deletions utest/test_verify_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ def test_bool_ne_operator_passes_and_returns_value():
assert res is False


def test_bool_operator_with_notchecked():
false_strings = {"FALSE", "NO", "OFF", "0", "UNCHECKED", "NONE", ""}
for false_str in false_strings:
res = bool_verify_assertion(False, AssertionOperator["=="], false_str)
assert res is False


def test_bool_invalid_operator_raises_value_error():
with pytest.raises(ValueError):
bool_verify_assertion(True, AssertionOperator["<"], "yes")
Expand Down