示例#1
0
 def test_multi_return_type(self):
     lines = [
         'def foo(arg1) -> List[',
         '    int,',
         '    int,',
         ']:',
         '    pass',
     ]
     docstrings = [{
         'docstring': '"""foo.\n\n:param arg1:\n:rtype List[\n    int,\n    int,\n]:\n"""',
         'start_lineno': 1,
         'start_col': 0,
         'end_lineno': 7,
         'end_col': 0,
         'is_doc_exists': False,
     }]
     output = StringOutptter().format(lines=lines, docstrings=docstrings, indent=4)
     expected = '\n'.join([
         'def foo(arg1) -> List[',
         '    int,',
         '    int,',
         ']:',
         '    """foo.',
         '',
         '    :param arg1:',
         '    :rtype List[',
         '        int,',
         '        int,',
         '    ]:',
         '    """',
         '    pass',
     ])
     self.assertEqual(expected, output)
示例#2
0
    def test_multi_lines_with_space(self):
        lines = [
            'def foo(',
            '    arg1,',
            '    arg2,',
            '    arg3,',
            ') :',
            '    pass',
        ]

        docstrings = [{
            'docstring': '"""foo.\n\n:param arg1:\n:param arg2:\n:param arg3:\n"""',
            'start_lineno': 1,
            'start_col': 0,
            'end_lineno': 8,
            'end_col': 0,
            'is_doc_exists': False,
        }]
        output = StringOutptter().format(lines=lines, docstrings=docstrings, indent=4)
        expected = '\n'.join([
            'def foo(',
            '    arg1,',
            '    arg2,',
            '    arg3,',
            ') :',
            '    """foo.',
            '',
            '    :param arg1:',
            '    :param arg2:',
            '    :param arg3:',
            '    """',
            '    pass',
        ])
        self.assertEqual(expected, output)
示例#3
0
    def test_multi_lines_with_return_type(self):
        lines = [
            'def foo(',
            '    arg1,',
            '    arg2=None,',
            "    arg3={'foo': 'spam', 'bar': 'ham'},",
            ') -> List[int]:',
            '    pass',
        ]

        docstrings = [{
            'docstring': '"""foo.\n\n:param arg1:\n:param arg2:\n:param arg3:\n:rtype List[int]:\n"""',
            'start_lineno': 1,
            'start_col': 0,
            'end_lineno': 7,
            'end_col': 0,
            'is_doc_exists': False,
        }]
        output = StringOutptter().format(lines=lines, docstrings=docstrings, indent=4)
        expected = '\n'.join([
            'def foo(',
            '    arg1,',
            '    arg2=None,',
            "    arg3={'foo': 'spam', 'bar': 'ham'},",
            ') -> List[int]:',
            '    """foo.',
            '',
            '    :param arg1:',
            '    :param arg2:',
            '    :param arg3:',
            '    :rtype List[int]:',
            '    """',
            '    pass',
        ])
        self.assertEqual(expected, output)