示例#1
0
    def test_empty_doc(self):
        def no_docs():
            pass

        brief, descr = describe(no_docs)
        self.assertEqual(brief, '')
        self.assertEqual(descr, '')
示例#2
0
    def test_brief_only(self):
        def brief_only():
            """Brief description"""

        brief, descr = describe(brief_only)
        self.assertEqual(brief, "Brief description")
        self.assertEqual(descr, "")
示例#3
0
    def test_leading_spaces(self):
        def leading_spaces():
            """      Brief description

            Long description
            """

        brief, descr = describe(leading_spaces)
        self.assertEqual(brief, "Brief description")
        self.assertEqual(descr, "Long description")
示例#4
0
    def test_class_doc(self):
        class BriefAndLong:
            """Brief description

            Long description
            """

        brief, descr = describe(BriefAndLong)
        self.assertEqual(brief, "Brief description")
        self.assertEqual(descr, "Long description")
示例#5
0
    def test_func_doc(self):
        def brief_and_long(self):
            """Brief description

            Long description
            """

        brief, descr = describe(brief_and_long)
        self.assertEqual(brief, "Brief description")
        self.assertEqual(descr, "Long description")
示例#6
0
    def test_multiline(self):
        def multiline():
            """Brief description

            First

            Second
            """

        brief, descr = describe(multiline)
        self.assertEqual(brief, "Brief description")
        self.assertEqual(descr, "First\n\nSecond")
示例#7
0
    def test_empty_lines(self):
        def with_empty_lines():
            """Brief description



            Long description
            """

        brief, descr = describe(with_empty_lines)
        self.assertEqual(brief, "Brief description")
        self.assertEqual(descr, "Long description")
示例#8
0
    def test_multiline_brief(self):
        def multiline_brief():
            """Multiline
            brief description

            Multiline

            long
            description
            """

        brief, descr = describe(multiline_brief)
        self.assertEqual(brief, "Multiline\nbrief description")
        self.assertEqual(descr, "Multiline\n\nlong\ndescription")
示例#9
0
    def from_function(func, name, is_method):
        """Create a new command from the given callable object.

        :param func: a callable object to wrap command around
        :param name: override command name
        :param is_method: indicates whether the underlying `func` accepts `self` as a first argument
        :return: a new Command initialized from the given `func`
        """
        name = name or func.__name__
        brief, descr = describe(func)
        return Command(func=func,
                       name=name,
                       signature=Signature.from_function(func, is_method),
                       brief=brief,
                       descr=descr)
示例#10
0
 def _describe(self):
     """Derive description from the docstring."""
     if type(self) is Handler:
         # ignore docstring from the generic handler
         return '', ''
     return describe(self)