Example #1
0
 def test_must_raise_validation_exception_when_input_is_less_than_minimum_allowed(
         self, input, min):
     with pytest.raises(ValidationException) as exc_info:
         is_float(min=min)(input)
     assert exc_info.value.args[
         0] == "'{}' is less than minimum allowed ({})".format(
             float(input), min)
Example #2
0
 def test_must_raise_validation_exception_when_input_is_greater_than_maximum_allowed(
         self, input, max):
     print(input, max)
     with pytest.raises(ValidationException) as exc_info:
         is_float(max=max)(input)
     assert exc_info.value.args[
         0] == "'{}' is greater than maximum allowed ({})".format(
             float(input), max)
Example #3
0
 def test_must_return_default_provided_when_input_is_missing(self):
     assert is_float(default=0.5)(None) == 0.5
Example #4
0
 def test_must_return_input_upon_validation(self, input, min, max):
     assert is_float(min=min, max=max)(input) == float(input)
Example #5
0
 def test_must_raise_validation_exception_when_input_is_not_a_valid_int(
         self, input):
     with pytest.raises(ValidationException) as exc_info:
         is_float()(input)
     assert exc_info.value.args[
         0] == "'{}' is not a valid floating number".format(input)
Example #6
0
 def test_must_raise_validation_exception_when_input_is_none_and_required_is_true(
         self):
     with pytest.raises(ValidationException) as exc_info:
         is_float(required=True)(None)
     assert exc_info.value.args[0] == "required but was missing"
Example #7
0
 def test_must_return_none_when_input_is_none_and_required_is_false(self):
     assert is_float(required=False)(None) is None
Example #8
0
 def test_must_round_returned_value_to_provided_decimal_places(
         self, input, expected, round_to):
     assert is_float(round_to=round_to)(input) == expected
Example #9
0
 def test_must_round_returned_value_to_2_decimal_places_by_default(
         self, input, expected):
     assert is_float()(input) == expected