示例#1
0
 def test_validates_a_conversion_that_potentially_returns_failure(self):
     assert_that(
         validate(
             conversion_of(
                 'language', 'en',
                 StringToObjectParser(lambda lang_string: Success(
                     language='en_lang')))).map(lambda p: p.language),
         equal_to('en_lang'))
示例#2
0
 def test_or_fail_with_does_not_affect_success(self):
     result = Success(message='Success').or_fail_with(value=0)
     assert result.message == 'Success'
示例#3
0
 def test_do_on_success_is_executed(self):
     side_effect = SideEffect()
     result = Success(
         message='Success').do(lambda result: side_effect.execute())
     assert side_effect.executed
     assert result.message == 'Success'
示例#4
0
 def test_map_on_success_returns_new_result(self):
     result = Success(message='Success').map(lambda r: Success(value=10))
     assert result.value == 10
示例#5
0
 def test_map_on_failure_returns_same_failure(self):
     result = Failure(message='Fail').map(lambda r: Success(value=10))
     assert result.message == 'Fail'
示例#6
0
 def test_parses_a_date_from_string(self):
     assert_that(date_from_iso.parse_from("2020-10-08"),
                 equal_to(Success(date=date(2020, 10, 8))))
示例#7
0
 def test_accepts_spaces(self):
     assert_that(int_from_string().parse_from("  100  "),
                 equal_to(Success(int_val=100)))
示例#8
0
 def test_can_have_a_custom_attribute(self):
     assert_that(
         int_from_string('count').parse_from("100"),
         equal_to(Success(count=100)))
示例#9
0
 def test_parses_an_int_from_string(self):
     assert_that(int_from_string().parse_from("100"),
                 equal_to(Success(int_val=100)))