def test_empty_doc(self): def no_docs(): pass brief, descr = describe(no_docs) self.assertEqual(brief, '') self.assertEqual(descr, '')
def test_brief_only(self): def brief_only(): """Brief description""" brief, descr = describe(brief_only) self.assertEqual(brief, "Brief description") self.assertEqual(descr, "")
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")
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")
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")
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")
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")
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")
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)
def _describe(self): """Derive description from the docstring.""" if type(self) is Handler: # ignore docstring from the generic handler return '', '' return describe(self)