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
32 changes: 21 additions & 11 deletions src/tirith/core/evaluators/contained_in.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from .base_evaluator import BaseEvaluator
from tirith.utils import sort_collections
from tirith.utils import sort_collections, json_format_value

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -37,7 +37,9 @@ def evaluate(self, evaluator_input, evaluator_data):
result = evaluator_input in evaluator_data
evaluation_result["passed"] = result
if result:
evaluation_result["message"] = "Found {} inside {}".format(evaluator_input, evaluator_data)
evaluation_result["message"] = "Found {} inside {}".format(
json_format_value(evaluator_input), json_format_value(evaluator_data)
)
# if evaluator_input is a list
elif isinstance(evaluator_data, list):
evaluator_data = sort_collections(evaluator_data)
Expand All @@ -46,47 +48,55 @@ def evaluate(self, evaluator_input, evaluator_data):
result = evaluator_input in evaluator_data
evaluation_result["passed"] = result
if result:
evaluation_result["message"] = "Found {} inside {}".format(evaluator_input, evaluator_data)
evaluation_result["message"] = "Found {} inside {}".format(
json_format_value(evaluator_input), json_format_value(evaluator_data)
)
else:
evaluation_result["message"] = "Failed to find {} inside {}".format(
evaluator_input, evaluator_data
json_format_value(evaluator_input), json_format_value(evaluator_data)
)
else:
result = evaluator_input in evaluator_data
evaluation_result["passed"] = result
if result:
evaluation_result["message"] = "Found {} inside {}".format(evaluator_input, evaluator_data)
evaluation_result["message"] = "Found {} inside {}".format(
json_format_value(evaluator_input), json_format_value(evaluator_data)
)
else:
evaluation_result["message"] = "Failed to find {} inside {}".format(
evaluator_input, evaluator_data
json_format_value(evaluator_input), json_format_value(evaluator_data)
)
elif isinstance(evaluator_data, dict):
if isinstance(evaluator_input, dict):
evaluation_result["passed"] = True
evaluation_result["message"] = "Found {} inside {}".format(evaluator_input, evaluator_data)
evaluation_result["message"] = "Found {} inside {}".format(
json_format_value(evaluator_input), json_format_value(evaluator_data)
)
for key in evaluator_input:
if key in evaluator_data:
if evaluator_data[key] != evaluator_input[key]:
evaluation_result["passed"] = False
evaluation_result["message"] = "Failed to find {} inside {}".format(
evaluator_input, evaluator_data
json_format_value(evaluator_input), json_format_value(evaluator_data)
)
break
else:
evaluation_result["passed"] = False
evaluation_result["message"] = "Failed to find {} inside {}".format(
evaluator_input, evaluator_data
json_format_value(evaluator_input), json_format_value(evaluator_data)
)
break
else:
result = evaluator_input in evaluator_data
evaluation_result["passed"] = result
if result:
evaluation_result["message"] = "Found {} inside {}".format(evaluator_input, evaluator_data)
evaluation_result["message"] = "Found {} inside {}".format(
json_format_value(evaluator_input), json_format_value(evaluator_data)
)
else:
evaluation_result["message"] = (
"{} is an unsupported data type for evaluating against value in 'condition.value'".format(
evaluator_data
json_format_value(evaluator_data)
)
)
return evaluation_result
Expand Down
32 changes: 21 additions & 11 deletions src/tirith/core/evaluators/contains.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from .base_evaluator import BaseEvaluator
from tirith.utils import sort_collections
from tirith.utils import sort_collections, json_format_value


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -38,7 +38,9 @@ def evaluate(self, evaluator_input, evaluator_data):
result = evaluator_data in evaluator_input
evaluation_result["passed"] = result
if result:
evaluation_result["message"] = "Found {} inside {}".format(evaluator_data, evaluator_input)
evaluation_result["message"] = "Found {} inside {}".format(
json_format_value(evaluator_data), json_format_value(evaluator_input)
)
# if evaluator_input is a list
elif isinstance(evaluator_input, list):
evaluator_input = sort_collections(evaluator_input)
Expand All @@ -47,47 +49,55 @@ def evaluate(self, evaluator_input, evaluator_data):
result = evaluator_data in evaluator_input
evaluation_result["passed"] = result
if result:
evaluation_result["message"] = "Found {} inside {}".format(evaluator_data, evaluator_input)
evaluation_result["message"] = "Found {} inside {}".format(
json_format_value(evaluator_data), json_format_value(evaluator_input)
)
else:
evaluation_result["message"] = "Failed to find {} inside {}".format(
evaluator_data, evaluator_input
json_format_value(evaluator_data), json_format_value(evaluator_input)
)
else:
result = evaluator_data in evaluator_input
evaluation_result["passed"] = result
if result:
evaluation_result["message"] = "Found {} inside {}".format(evaluator_data, evaluator_input)
evaluation_result["message"] = "Found {} inside {}".format(
json_format_value(evaluator_data), json_format_value(evaluator_input)
)
else:
evaluation_result["message"] = "Failed to find {} inside {}".format(
evaluator_data, evaluator_input
json_format_value(evaluator_data), json_format_value(evaluator_input)
)
elif isinstance(evaluator_input, dict):
if isinstance(evaluator_data, dict):
evaluation_result["passed"] = True
evaluation_result["message"] = "Found {} inside {}".format(evaluator_data, evaluator_input)
evaluation_result["message"] = "Found {} inside {}".format(
json_format_value(evaluator_data), json_format_value(evaluator_input)
)
for key in evaluator_data:
if key in evaluator_input:
if evaluator_input[key] != evaluator_data[key]:
evaluation_result["passed"] = False
evaluation_result["message"] = "Failed to find {} inside {}".format(
evaluator_data, evaluator_input
json_format_value(evaluator_data), json_format_value(evaluator_input)
)
break
else:
evaluation_result["passed"] = False
evaluation_result["message"] = "Failed to find {} inside {}".format(
evaluator_data, evaluator_input
json_format_value(evaluator_data), json_format_value(evaluator_input)
)
break
else:
result = evaluator_data in evaluator_input
evaluation_result["passed"] = result
if result:
evaluation_result["message"] = "Found {} inside {}".format(evaluator_data, evaluator_input)
evaluation_result["message"] = "Found {} inside {}".format(
json_format_value(evaluator_data), json_format_value(evaluator_input)
)
else:
evaluation_result["message"] = (
"{} is an unsupported data type for evaluating against value in 'condition.value'".format(
evaluator_data
json_format_value(evaluator_data)
)
)
return evaluation_result
Expand Down
11 changes: 8 additions & 3 deletions src/tirith/core/evaluators/equals.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
from typing import Dict, Any

from .base_evaluator import BaseEvaluator
from tirith.utils import sort_collections
from tirith.utils import sort_collections, json_format_value

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -41,9 +42,13 @@ def evaluate(self, evaluator_input, evaluator_data):
result = value1 == value2
evaluation_result["passed"] = result
if result:
evaluation_result["message"] = "{} is equal to {}".format(evaluator_input, evaluator_data)
evaluation_result["message"] = "{} is equal to {}".format(
json_format_value(evaluator_input), json_format_value(evaluator_data)
)
else:
evaluation_result["message"] = "{} is not equal to {}".format(evaluator_input, evaluator_data)
evaluation_result["message"] = "{} is not equal to {}".format(
json_format_value(evaluator_input), json_format_value(evaluator_data)
)
return evaluation_result
except Exception as e:
evaluation_result["message"] = str(e)
Expand Down
15 changes: 13 additions & 2 deletions src/tirith/core/evaluators/greater_than.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import logging
from typing import Dict, Any

from .base_evaluator import BaseEvaluator
from tirith.utils import json_format_value


logger = logging.getLogger(__name__)


# Checks if :attr:`value` is more then :attr:`other`. Automatically casts values to the same type if possible.
Expand Down Expand Up @@ -30,9 +37,13 @@ def evaluate(self, evaluator_input, evaluator_data):
value2 = evaluator_data
evaluation_result["passed"] = value1 > value2
if evaluation_result["passed"]:
evaluation_result["message"] = "{} is greater than {}".format(value1, value2)
evaluation_result["message"] = "{} is greater than {}".format(
json_format_value(value1), json_format_value(value2)
)
else:
evaluation_result["message"] = "{} is not greater than {}".format(value1, value2)
evaluation_result["message"] = "{} is not greater than {}".format(
json_format_value(value1), json_format_value(value2)
)
return evaluation_result
except Exception as e:
evaluation_result["message"] = str(e)
Expand Down
11 changes: 9 additions & 2 deletions src/tirith/core/evaluators/greater_than_equal_to.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import logging
from typing import Dict, Any
from .base_evaluator import BaseEvaluator
from tirith.utils import json_format_value

# Checks if :attr:`value` is more then or equal to :attr:`other`. Automatically casts values to the same type if possible.

Expand Down Expand Up @@ -31,9 +34,13 @@ def evaluate(self, evaluator_input, evaluator_data):
value2 = evaluator_data
evaluation_result["passed"] = value1 >= value2
if evaluation_result["passed"]:
evaluation_result["message"] = "{} is greater than equal to {}".format(value1, value2)
evaluation_result["message"] = "{} is greater than equal to {}".format(
json_format_value(value1), json_format_value(value2)
)
else:
evaluation_result["message"] = "{} is not greater than or equal to {}".format(value1, value2)
evaluation_result["message"] = "{} is not greater than or equal to {}".format(
json_format_value(value1), json_format_value(value2)
)
return evaluation_result
except Exception as e:
evaluation_result["message"] = str(e)
Expand Down
8 changes: 6 additions & 2 deletions src/tirith/core/evaluators/is_empty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import logging
from typing import Dict, Any

from .base_evaluator import BaseEvaluator
from tirith.utils import json_format_value

# Checks if input is empty (null, empty list [], empty dict {}, empty str '')

Expand Down Expand Up @@ -33,9 +37,9 @@ def evaluate(self, evaluator_input, evaluator_data=None):
and not evaluator_input
):
evaluation_result["passed"] = True
evaluation_result["message"] = "{} is empty".format(evaluator_input)
evaluation_result["message"] = "{} is empty".format(json_format_value(evaluator_input))
if not evaluation_result["passed"]:
evaluation_result["message"] = "{} is not empty".format(evaluator_input)
evaluation_result["message"] = "{} is not empty".format(json_format_value(evaluator_input))
return evaluation_result
except Exception as e:
evaluation_result["message"] = str(e)
Expand Down
5 changes: 3 additions & 2 deletions src/tirith/core/evaluators/is_not_empty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .base_evaluator import BaseEvaluator
from tirith.utils import json_format_value

# Checks if input is not empty

Expand Down Expand Up @@ -30,9 +31,9 @@ def evaluate(self, evaluator_input, evaluator_data=None):
or isinstance(evaluator_input, dict)
) and evaluator_input:
evaluation_result["passed"] = True
evaluation_result["message"] = "{} is not empty".format(evaluator_input)
evaluation_result["message"] = "{} is not empty".format(json_format_value(evaluator_input))
if not evaluation_result["passed"]:
evaluation_result["message"] = "{} is empty".format(evaluator_input)
evaluation_result["message"] = "{} is empty".format(json_format_value(evaluator_input))
return evaluation_result
except Exception as e:
evaluation_result["message"] = str(e)
Expand Down
12 changes: 10 additions & 2 deletions src/tirith/core/evaluators/less_than.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import logging
from typing import Dict, Any

from .base_evaluator import BaseEvaluator
from tirith.utils import json_format_value

# Checks if :attr:`value` is less then :attr:`other`. Automatically casts values to the same type if possible.

Expand Down Expand Up @@ -29,9 +33,13 @@ def evaluate(self, evaluator_input, evaluator_data):
value2 = evaluator_data
evaluation_result["passed"] = value1 < value2
if evaluation_result["passed"]:
evaluation_result["message"] = "{} is less than {}".format(value1, value2)
evaluation_result["message"] = "{} is less than {}".format(
json_format_value(value1), json_format_value(value2)
)
else:
evaluation_result["message"] = "{} is not less than {}".format(value1, value2)
evaluation_result["message"] = "{} is not less than {}".format(
json_format_value(value1), json_format_value(value2)
)
return evaluation_result
except Exception as e:
evaluation_result["message"] = str(e)
Expand Down
12 changes: 10 additions & 2 deletions src/tirith/core/evaluators/less_than_equal_to.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import logging
from typing import Dict, Any

from .base_evaluator import BaseEvaluator
from tirith.utils import json_format_value

# Checks if :attr:`value` is less then or equal to :attr:`other`. Automatically casts values to the same type if possible.

Expand Down Expand Up @@ -34,9 +38,13 @@ def evaluate(self, evaluator_input, evaluator_data):
value2 = evaluator_data
evaluation_result["passed"] = value1 <= value2
if evaluation_result["passed"]:
evaluation_result["message"] = "{} is less than equal to {}".format(value1, value2)
evaluation_result["message"] = "{} is less than equal to {}".format(
json_format_value(value1), json_format_value(value2)
)
else:
evaluation_result["message"] = "{} is not less than or equal to {}".format(value1, value2)
evaluation_result["message"] = "{} is not less than or equal to {}".format(
json_format_value(value1), json_format_value(value2)
)
return evaluation_result
except Exception as e:
evaluation_result["message"] = str(e)
Expand Down
Loading