def testSameOutputJavadocReST(self): doc = mydocs dj = docs.DocString(myelem, ' ') dj.parse_docs(doc) doc = torest(mydocs) dr = docs.DocString(myelem, ' ') dr.parse_docs(doc) self.assertEqual(dj.get_raw_docs(), dr.get_raw_docs())
def testIfParsedDocs(self): doc = mydocs # nothing to parse d = docs.DocString(myelem, ' ') d.parse_docs() self.failIf(d.parsed_docs) # parse docstring given at init d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.failUnless(d.parsed_docs) # parse docstring given in parsing method d = docs.DocString(myelem, ' ') d.parse_docs(doc) self.failUnless(d.parsed_docs)
def testIfParsedDocs(self): doc = mydocs # nothing to parse d = docs.DocString(myelem, ' ') d.parse_docs() self.assertFalse(d.parsed_docs) # parse docstring given at init d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(d.parsed_docs) # parse docstring given in parsing method d = docs.DocString(myelem, ' ') d.parse_docs(doc) self.assertTrue(d.parsed_docs)
def testParsingElement(self): d = docs.DocString(myelem, ' ') self.assertTrue(d.element['deftype'] == 'def') self.assertTrue(d.element['name'] == 'my_method') self.assertTrue(len(d.element['params']) == 3) self.assertTrue(type(d.element['params'][0]['param']) is str) self.assertTrue((d.element['params'][2]['param'], d.element['params'][2]['default']) == ('third', '"value"'))
def testGeneratingDocsReturn(self): doc = mydocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() d.generate_docs() self.assertTrue(d.docs['out']['return'].startswith('the result')) self.assertTrue(d.docs['out']['rtype'] == 'int')
def testGeneratingDocsParamsTypeStubs(self): doc = mydocs d = docs.DocString(myelem, ' ', doc, type_stub=True) d.parse_docs() d.generate_docs() self.assertTrue(':type second: ' in d.docs['out']['raw']) self.assertTrue(':type third: ' in d.docs['out']['raw'])
def testParsingNumpyDocsDesc(self): doc = mynumpydocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.failUnless(d.docs['in']['desc'].strip().startswith('My numpydoc')) self.failUnless( d.docs['in']['desc'].strip().endswith('format docstring.'))
def testParsingElement(self): d = docs.DocString(myelem, ' ') self.failUnless(d.element['type'] == 'def') self.failUnless(d.element['name'] == 'my_method') self.failUnless(len(d.element['params']) == 3) self.failUnless(type(d.element['params'][0]) is str) self.failUnless(d.element['params'][2] == ('third', '"value"'))
def testParsingGroups2DocsParams(self): doc = mygrpdocs2 d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(len(d.docs['in']['params']) == 3) self.assertTrue(d.docs['in']['params'][0][0] == 'first') self.assertTrue(d.docs['in']['params'][0][1].startswith('the 1')) self.assertTrue(d.docs['in']['params'][2][1].startswith('the 3rd'))
def testParsingNumpyDocsParams(self): doc = mynumpydocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(len(d.docs['in']['params']) == 3) self.assertTrue(d.docs['in']['params'][0][0] == 'first') self.assertTrue(d.docs['in']['params'][0][1].strip().startswith('the 1')) self.assertTrue(d.docs['in']['params'][2][1].strip().endswith("default 'value'"))
def testParsingGoogleDocsParams(self): doc = googledocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(len(d.docs['in']['params']) == 3) self.assertTrue(d.docs['in']['params'][0][0] == 'first') self.assertTrue(d.docs['in']['params'][0][1].startswith('this is the first')) self.assertTrue(d.docs['in']['params'][2][1].startswith('this is a third'))
def testNoParam(self): elem = " def noparam():" doc = """ '''the no param docstring '''""" d = docs.DocString(elem, ' ', doc, input_style='javadoc') d.parse_docs() d.generate_docs() self.assertFalse(d.docs['out']['params'])
def testOneLineDocs(self): elem = " def oneline(self):" doc = """ '''the one line docstring '''""" d = docs.DocString(elem, ' ', doc, input_style='javadoc') d.parse_docs() d.generate_docs() #print(d.docs['out']['raw']) self.assertFalse(d.docs['out']['raw'].count('\n'))
def testParsingGoogleDocsRaises(self): doc = googledocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(len(d.docs['in']['raises']) == 2) self.assertTrue(d.docs['in']['raises'][0][0] == 'KeyError') self.assertTrue(d.docs['in']['raises'][0][1].startswith('raises an')) self.assertTrue(d.docs['in']['raises'][1][0] == 'OtherError') self.assertTrue(d.docs['in']['raises'][1][1].startswith('when an other'))
def testParsingNumpyDocsRaises(self): doc = mynumpydocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(len(d.docs['in']['raises']) == 2) self.assertTrue(d.docs['in']['raises'][0][0] == 'KeyError') self.assertTrue(d.docs['in']['raises'][0][1].strip().startswith('when a key')) self.assertTrue(d.docs['in']['raises'][1][0] == 'OtherError') self.assertTrue(d.docs['in']['raises'][1][1].strip().startswith('when an other'))
def testParsingGroups2DocsRaises(self): doc = mygrpdocs2 d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.failUnless(len(d.docs['in']['raises']) == 2) self.failUnless(d.docs['in']['raises'][0][0] == 'KeyError') self.failUnless(d.docs['in']['raises'][0][1].startswith('when a key')) self.failUnless(d.docs['in']['raises'][1][0] == 'OtherError') self.failUnless( d.docs['in']['raises'][1][1].startswith('when an other'))
def testGeneratingDocsParams(self): doc = mydocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() d.generate_docs() self.assertTrue(len(d.docs['out']['params']) == 3) self.assertTrue(type(d.docs['out']['params'][2]) is tuple) self.assertTrue(d.docs['out']['params'][2] == ('third', '', None, '"value"')) # param's description self.assertTrue(d.docs['out']['params'][1][1].startswith("the 2"))
def testGeneratingDocsRaise(self): doc = mydocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() d.generate_docs() self.assertTrue(len(d.docs['out']['raises']) == 2) self.assertTrue(d.docs['out']['raises'][0][0].startswith('KeyError')) self.assertTrue(d.docs['out']['raises'][0][1].startswith('raises a key')) self.assertTrue(d.docs['out']['raises'][1][0].startswith('OtherError')) self.assertTrue(d.docs['out']['raises'][1][1].startswith('raises an other'))
def testParsingDocsRaises(self): doc = mydocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() d.generate_docs() self.failUnless(len(d.docs['in']['raises']) == 2) self.failUnless(d.docs['in']['raises'][0][0].startswith('KeyError')) self.failUnless( d.docs['in']['raises'][0][1].startswith('raises a key')) self.failUnless(d.docs['in']['raises'][1][0].startswith('OtherError')) self.failUnless( d.docs['in']['raises'][1][1].startswith('raises an other'))
def testParsingDocsParams(self): doc = torest(mydocs) d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(len(d.docs['in']['params']) == 2) self.assertTrue(type(d.docs['in']['params'][1]) is tuple) # param's name self.assertTrue(d.docs['in']['params'][1][0] == 'second') # param's type self.assertTrue(d.docs['in']['params'][0][2] == 'str') self.assertFalse(d.docs['in']['params'][1][2]) # param's description self.assertTrue(d.docs['in']['params'][0][1].startswith("the 1"))
def testIssue19(self): txt = '''""" :raises ValueError: on incorrect JSON :raises requests.exceptions.HTTPError: on response error from server """''' expected = ''' """ :raises ValueError: on incorrect JSON :raises requests.exceptions.HTTPError: on response error from server """''' docs = ds.DocString('def test():', quotes='"""') docs.parse_docs(txt) self.assertTrue(docs.get_raw_docs() == expected)
def testIssue11(self): deftxt = "def meaning(subject, answer=False):" txt = '''""" >>> meaning('life', answer=True) 42 """''' expected = ''' """ :param subject: :param answer: (Default value = False) >>> meaning('life', answer=True) 42 """''' d = ds.DocString(deftxt, quotes='"""') d.parse_docs(txt) self.assertTrue(d.get_raw_docs() == expected)
def testGeneratingDocsDesc(self): doc = mydocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() d.generate_docs() self.assertTrue(d.docs['out']['desc'] == d.docs['in']['desc'])
def testParsingNumpyDocsReturn(self): doc = mynumpydocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(d.docs['in']['return'][0][1] == 'a value in a string') d.set_output_style('numpydoc')
def testParsingGroupsDocsDesc(self): doc = mygrpdocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(d.docs['in']['desc'].strip().startswith('My ')) self.assertTrue(d.docs['in']['desc'].strip().endswith('lines.'))
def testParsingGroupsDocsReturn(self): doc = mygrpdocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(d.docs['in']['return'] == 'a value in a string')
def testAutoInputStyleGroups(self): doc = mygrpdocs d = docs.DocString(myelem, ' ', doc) self.assertTrue(d.get_input_style() == 'groups')
def testParsingGoogleDocsReturn(self): doc = googledocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(d.docs['in']['return'][0][1] == 'This is a description of what is returned')
def testParsingGoogleDocsDesc(self): doc = googledocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(d.docs['in']['desc'].strip().startswith('This is a Google style docs.'))
def testParsingDocsDesc(self): doc = mydocs d = docs.DocString(myelem, ' ', doc) d.parse_docs() self.assertTrue(d.docs['in']['desc'].strip().startswith('This ')) self.assertTrue(d.docs['in']['desc'].strip().endswith('style.'))