def test_explicit_role_actual(self): """Workaround output for issue #1.""" def test(): """start :py:class:`int` end""" doc = defopt._parse_doc(test) self.assertEqual(doc.text, 'start :py:class:`int` end')
def test_no_doc(self): def test(param): pass doc = defopt._parse_doc(test) self.assertEqual(doc.text, '') self.assertEqual(doc.params, {})
def test_numpy(self): # Docstring taken from Napoleon's example (plus a keyword argument). def func(arg1, arg2, arg3=None): """One line summary. Extended description. Parameters ---------- arg1 : int Description of arg1 arg2 : str Description of arg2 Keyword Arguments ----------------- arg3 : float Description of arg3 Returns ------- str Description of return value. """ doc = defopt._parse_doc(func) self._check_doc(doc)
def test_explicit_role_desired(self): """Desired output for issue #1.""" def test(): """start :py:class:`int` end""" doc = defopt._parse_doc(test) self.assertEqual(doc.text, 'start int end')
def test_param_only(self): def test(param): """:param int param: test""" doc = defopt._parse_doc(test) self.assertEqual(doc.text, '') param = doc.params['param'] self.assertEqual(param.text, 'test') self.assertEqual(param.type, 'int')
def test_parse_doubles(self): def test(param): """Test function :param int param: the parameter :type param: int """ with self.assertRaises(ValueError): defopt._parse_doc(test) def test(param): """Test function :type param: int :param int param: the parameter """ with self.assertRaises(ValueError): defopt._parse_doc(test)
def test_literal_block(self): def func(): """ :: Literal block Multiple lines """ doc = defopt._parse_doc(func) self.assertEqual(doc.text, ' Literal block\n Multiple lines')
def test_sphinx(self): def func(arg1, arg2): """One line summary. Extended description. :param int arg1: Description of `arg1` :param str arg2: Description of `arg2` :returns: Description of return value. :rtype: str """ doc = defopt._parse_doc(func) self._check_doc(doc)
def test_sphinx(self): def func(arg1, arg2, arg3=None): """One line summary. Extended description. :param int arg1: Description of arg1 :param str arg2: Description of arg2 :keyword float arg3: Description of arg3 :returns: Description of return value. :rtype: str """ doc = defopt._parse_doc(func) self._check_doc(doc)
def test_google(self): # Docstring taken from Napoleon's example. def func(arg1, arg2): """One line summary. Extended description. Args: arg1(int): Description of `arg1` arg2(str): Description of `arg2` Returns: str: Description of return value. """ doc = defopt._parse_doc(func) self._check_doc(doc)
def test_parse_doc(self): def test(one, two): """Test function :param one: first param :type one: int :param float two: second param :returns: str :junk one two: nothing """ doc = defopt._parse_doc(test) self.assertEqual(doc.text, 'Test function') one = doc.params['one'] self.assertEqual(one.text, 'first param') self.assertEqual(one.type, 'int') two = doc.params['two'] self.assertEqual(two.text, 'second param') self.assertEqual(two.type, 'float')
def test_google(self): # Docstring taken from Napoleon's example (plus a keyword argument). def func(arg1, arg2, arg3=None): """One line summary. Extended description. Args: arg1(int): Description of arg1 arg2(str): Description of arg2 Keyword Arguments: arg3(float): Description of arg3 Returns: str: Description of return value. """ doc = defopt._parse_doc(func) self._check_doc(doc)
def test_parse_params(self): def test(first, second, third, fourth, fifth, sixth): """Test function :param first: first param :parameter int second: second param :arg third: third param :argument float fourth: fourth param :key fifth: fifth param :keyword str sixth: sixth param """ doc = defopt._parse_doc(test) self.assertEqual(doc.params['first'].text, 'first param') self.assertEqual(doc.params['second'].text, 'second param') self.assertEqual(doc.params['third'].text, 'third param') self.assertEqual(doc.params['fourth'].text, 'fourth param') self.assertEqual(doc.params['fifth'].text, 'fifth param') self.assertEqual(doc.params['sixth'].text, 'sixth param')
def test_numpy(self): # Docstring taken from Napoleon's example. def func(arg1, arg2): """One line summary. Extended description. Parameters ---------- arg1 : int Description of `arg1` arg2 : str Description of `arg2` Returns ------- str Description of return value. """ doc = defopt._parse_doc(func) self._check_doc(doc)
def test_implicit_role(self): def test(): """start `int` end""" doc = defopt._parse_doc(test) self.assertEqual(doc.text, 'start int end')