def dupe1(): add_extension(is_foo) assert_that('foo').is_foo() try: assert_that('FOO').is_foo() fail('should have raised error') except AssertionError as ex: assert_that( str(ex)).is_equal_to('Expected <FOO> to be foo, but was not.')
def dupe2(): def is_foo(self): if self.val != 'FOO': self._err('Expected <%s> to be FOO, but was not.' % (self.val)) return self add_extension(is_foo) assert_that('FOO').is_foo() try: assert_that('foo').is_foo() fail('should have raised error') except AssertionError as ex: assert_that( str(ex)).is_equal_to('Expected <foo> to be FOO, but was not.')
def my_extensions(): add_extension(is_same_schema)
def items_isinstance_extension(): add_extension(is_all_items_instance_of)
raise Exception(f'{self.val} is not a string') else: raise Exception(f'{self.val} is not longer') def check_result_contain_single_spaces_beetween_morse(self, previous_val): if " " not in previous_val: if self.val.count(" ") == len(previous_val): return self.val else: raise Exception('spaces does not match') else: raise Exception('Result does not contain spaces') add_extension(check_result_contain_single_spaces_beetween_morse) add_extension(check_result_length_higher_and_string_and_contain_spaces) class Main_morse_coding_Matchers(unittest.TestCase): def setUp(self): self.temp = Main() def test_Morse_coding_check_result_length_higher_and_string_and_contain_spaces( self): argument = 'wiktor 1' assert_that( self.temp.Morse_coding(argument) ).check_result_length_higher_and_string_and_contain_spaces(argument) def test_Morse_coding_check_result_contain_single_spaces_beetween_morse(
def test_is_even_extension_failure_not_callable(): try: add_extension('foo') fail('should have raised error') except TypeError as ex: assert_that(str(ex)).is_equal_to('func must be callable')
raise TypeError('given arg must be a positive integer') # divide and compute remainder using divmod() built-in _, rem = divmod(self.val, other) # test the negative (is remainder non-zero?) if rem > 0: # non-zero remainder, so not multiple -> we fail! self._err('Expected <%s> to be multiple of <%s>, but was not.' % (self.val, other)) # success, and return self to allow chaining return self add_extension(is_even) add_extension(is_multiple_of) def test_is_even_extension(): assert_that(124).is_even() assert_that(124).is_type_of(int).is_even().is_greater_than( 123).is_less_than(125).is_equal_to(124) def test_is_even_extension_failure(): try: assert_that(123).is_even() fail('should have raised error') except AssertionError as ex: assert_that(