def test_calls_with_template_parameter(self): # given string = self.given_document() # when populate( string, lambda param, _, __: self.assertEqual('input_parameter', param))
def test_calls_with_placeholder(self): # given string = self.given_document() # when populate( string, lambda _, __, placeholder: self.assertEqual( '{documentary:input_parameter}', placeholder))
def parse(self, template: str) -> Union[None, str]: mock = Mock(return_value='') populate(template, mock) if len(mock.call_args_list) == 0: return None if len(mock.call_args_list) == 1: [((name, indent, template), kwargs)] = mock.call_args_list return template raise Exception()
def test_should_raise_for_invalid_replacement(self): # given string = self.given_document() # when with self.assertRaises(TypeError) as error: populate(string, lambda *_: 2) # then self.assertEqual(str(error.exception), 'Invalid replacement type')
def test_replaces_calls_with_class(self): # given string = """/** * {documentary::class} */""" mock = MagicMock(return_value="") # when populate(string, mock) # then mock.assert_called_with(":class", ANY, ANY)
def test_ignore_placeholder_if_replacement_is_none(self): # given string = self.given_document() # when result = populate(string, lambda *_: None) # then self.assertEqual(string, result)
def test_replaces_minimal(self): # given string = "/**{documentary:foo}*/" # when result = populate(string, lambda *_: 'Replaced') # then self.assertEqual(second=result, first="Replaced")
def test_replaces_class(self): # given string = """/** * {documentary::class} */""" # when result = populate(string, lambda *_: "Replaced") # then self.assertEqual(second=result, first="Replaced")
def test_populate(self): # given string = self.given_document() # when result = populate(string, lambda *_: 'Replaced') # then self.assertEqual(second=result, first=""" Some text Replaced Some other text """)
def test_populates_comment_above(self): # given string = """ # /** * {documentary:work} */ """ # when result = populate(string, lambda *_: 'Replaced') # then self.assertEqual(second=result, first="\n #\nReplaced\n ")
def test_replaces_non_greedy(self): # given string = """ /** * {documentary:work} */ */ """ # when result = populate(string, lambda *_: 'Replaced') # then self.assertEqual(second=result, first="\nReplaced\n */\n ")
def test_empty(self): # when result = populate('', lambda: self.fail()) # then self.assertEqual(second=result, first='')
def test_calls_with_indent(self): # given string = self.given_document() # when populate(string, lambda _, indent, __: self.assertEqual(8, indent))
def assertIgnoresPlaceholder(self, string: str): self.assertEqual( first=string, second=populate(string, lambda *_: ''), msg="Failed to assert that malformed placeholder was ignored")