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'))
def test_or_fail_with_does_not_affect_success(self): result = Success(message='Success').or_fail_with(value=0) assert result.message == 'Success'
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'
def test_map_on_success_returns_new_result(self): result = Success(message='Success').map(lambda r: Success(value=10)) assert result.value == 10
def test_map_on_failure_returns_same_failure(self): result = Failure(message='Fail').map(lambda r: Success(value=10)) assert result.message == 'Fail'
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))))
def test_accepts_spaces(self): assert_that(int_from_string().parse_from(" 100 "), equal_to(Success(int_val=100)))
def test_can_have_a_custom_attribute(self): assert_that( int_from_string('count').parse_from("100"), equal_to(Success(count=100)))
def test_parses_an_int_from_string(self): assert_that(int_from_string().parse_from("100"), equal_to(Success(int_val=100)))