Example #1
0
    def test_calls_with_template_parameter(self):
        # given
        string = self.given_document()

        # when
        populate(
            string,
            lambda param, _, __: self.assertEqual('input_parameter', param))
Example #2
0
    def test_calls_with_placeholder(self):
        # given
        string = self.given_document()

        # when
        populate(
            string, lambda _, __, placeholder: self.assertEqual(
                '{documentary:input_parameter}', placeholder))
Example #3
0
 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()
Example #4
0
    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')
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
    def test_replaces_minimal(self):
        # given
        string = "/**{documentary:foo}*/"

        # when
        result = populate(string, lambda *_: 'Replaced')

        # then
        self.assertEqual(second=result, first="Replaced")
Example #8
0
    def test_replaces_class(self):
        # given
        string = """/**
         * {documentary::class}
         */"""

        # when
        result = populate(string, lambda *_: "Replaced")

        # then
        self.assertEqual(second=result, first="Replaced")
Example #9
0
    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
        """)
Example #10
0
    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        ")
Example #11
0
    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        ")
Example #12
0
    def test_empty(self):
        # when
        result = populate('', lambda: self.fail())

        # then
        self.assertEqual(second=result, first='')
Example #13
0
    def test_calls_with_indent(self):
        # given
        string = self.given_document()

        # when
        populate(string, lambda _, indent, __: self.assertEqual(8, indent))
Example #14
0
 def assertIgnoresPlaceholder(self, string: str):
     self.assertEqual(
         first=string,
         second=populate(string, lambda *_: ''),
         msg="Failed to assert that malformed placeholder was ignored")