示例#1
0
    def test_docstring(self):
        def test_func_no_docstring(arg1):
            pass

        def test_func_one_line(*args):
            """This is a one line docstring."""
            return sum(args)

        def test_func_one_line_2():
            """
            This is also a one line docstring.
            """
            pass

        def test_func_multi_line():
            """
            This is a multi-line docstring.

            It has multiple lines.
            """
            pass

        self.assertEqual(registry.docstring(test_func_no_docstring), None)
        self.assertEqual(
            registry.docstring(test_func_one_line), ["This is a one line docstring."]
        )
        self.assertEqual(
            registry.docstring(test_func_one_line_2),
            ["This is also a one line docstring."],
        )
        self.assertEqual(
            registry.docstring(test_func_multi_line),
            ["This is a multi-line docstring.", "", "It has multiple lines."],
        )
示例#2
0
 def print_default(self, events: RegistryType) -> None:
     """Print the first line of the docstring for each mapped function."""
     for label, funcs in events.items():
         self.stdout.write("")
         self.stdout.write(label)
         for func in funcs:
             docs = docstring(func)
             if docs is None:
                 self.missing_docstrings.append(fname(func))
                 self.stderr.write(f"  x {fname(func)} (no docstring)")
             else:
                 self.stdout.write(f"  - {docs[0]}")
示例#3
0
 def print_verbose(self, events: RegistryType) -> None:
     """Print the entire docstring for each mapped function."""
     for label, funcs in events.items():
         self.stdout.write("")
         self.stdout.write(label)
         self.stdout.write("")
         for func in funcs:
             docs = docstring(func)
             if docs is None:
                 self.missing_docstrings.append(fname(func))
                 self.stderr.write(f"  x {fname(func)} (no docstring)")
                 self.stdout.write("")
             else:
                 self.stdout.write(f"  - {fname(func)}:")
                 self.stdout.write(f"    {docs[0]}")
                 for line in docs[1:]:
                     self.stdout.write(f"    {line}")
                 self.stdout.write("")