Skip to content

Commit bf5f8ab

Browse files
author
Elias Benussi
committed
Parametrise single filter construction tests
1 parent 634e1c3 commit bf5f8ab

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

faculty/clients/experiment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __new__(cls, by, key, operator, value):
127127
):
128128
raise ValueError(
129129
(
130-
"value can not be type {}. It has to be either an int "
130+
"invalid type {}. Value has to be either an int "
131131
+ "or a float"
132132
).format(type(value))
133133
)

tests/clients/test_experiment.py

+23-26
Original file line numberDiff line numberDiff line change
@@ -531,44 +531,41 @@ def test_single_filter_value_field_validation(mocker):
531531
SingleFilterSchema().dump(singleFilterObj)
532532

533533

534-
def test_single_filter_validation(mocker):
535-
with pytest.raises(
536-
ValueError,
537-
match="key must be none for filter type {}".format(
538-
SingleFilterBy.PROJECT_ID
539-
),
540-
):
541-
SingleFilter(
534+
@pytest.mark.parametrize(
535+
"by,key,op,value,err_msg",
536+
[
537+
[
542538
SingleFilterBy.PROJECT_ID,
543539
"invalid_key",
544540
SingleFilterOperator.EQUAL_TO,
545541
PROJECT_ID,
546-
)
547-
with pytest.raises(
548-
ValueError,
549-
match="key must not be none for filter type {}".format(
550-
SingleFilterBy.TAG
551-
),
552-
):
553-
SingleFilter(
542+
"key must be none for filter type {}".format(
543+
SingleFilterBy.PROJECT_ID
544+
),
545+
],
546+
[
554547
SingleFilterBy.TAG,
555548
None,
556549
SingleFilterOperator.EQUAL_TO,
557550
"tag_value",
558-
)
559-
with pytest.raises(
560-
ValueError,
561-
match=(
562-
"value can not be type {}. It has to be either an int "
563-
+ "or a float"
564-
).format(type("param_value")),
565-
):
566-
SingleFilter(
551+
"key must not be none for filter type {}".format(
552+
SingleFilterBy.TAG
553+
),
554+
],
555+
[
567556
SingleFilterBy.PARAM,
568557
"param_key",
569558
SingleFilterOperator.GREATER_THAN,
570559
"param_value",
571-
)
560+
"invalid type {}. Value has to be either an int or a float".format(
561+
type("param_value")
562+
),
563+
],
564+
],
565+
)
566+
def test_single_filter_validation(mocker, by, key, op, value, err_msg):
567+
with pytest.raises(ValueError, match=err_msg):
568+
SingleFilter(by, key, op, value)
572569

573570

574571
def test_compound_filter_validation(mocker):

0 commit comments

Comments
 (0)