예제 #1
0
 def test_can_fail_a_conversion_that_potentially_returns_failure(self):
     assert_that(
         validate(
             conversion_of(
                 'language', 'xx',
                 StringToObjectParser(lambda lang_string: Failure(
                     message='uh oh')))).map(lambda p: p.language),
         equal_to(Failure(message='uh oh')))
예제 #2
0
 def test_or_fail_with_replaces_failure(self):
     result = Failure(message='Fail').or_fail_with(value=0)
     assert result.value == 0
예제 #3
0
 def test_do_on_failure_is_not_executed(self):
     side_effect = SideEffect()
     result = Failure(
         message='Fail').do(lambda result: side_effect.execute())
     assert not side_effect.executed
     assert result.message == 'Fail'
예제 #4
0
 def test_map_on_failure_returns_same_failure(self):
     result = Failure(message='Fail').map(lambda r: Success(value=10))
     assert result.message == 'Fail'
예제 #5
0
 def test_fails_when_it_has_trailing_word_chars(self):
     assert_that(int_from_string().parse_from("100W"),
                 equal_to(Failure(message="'100W' is not a valid integer")))
예제 #6
0
 def test_returns_failure_is_date_is_not_present(self):
     assert_that(date_from_iso.parse_from(None),
                 equal_to(Failure(message="date is missing")))
예제 #7
0
 def test_returns_failure_is_date_is_not_an_iso_string(self):
     assert_that(
         date_from_iso.parse_from("2020-1008"),
         equal_to(Failure(message="Invalid isoformat string: '2020-1008'")))
예제 #8
0
 def test_returns_failure_when_value_is_not_present(self):
     assert_that(
         validate(presence_of('some_parameter',
                              None)).map(lambda p: p.some_parameter),
         equal_to(Failure(message='some_parameter is missing')))