Exemplo n.º 1
0
 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())
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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"'))
Exemplo n.º 5
0
 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')
Exemplo n.º 6
0
 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'])
Exemplo n.º 7
0
 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.'))
Exemplo n.º 8
0
 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"'))
Exemplo n.º 9
0
 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'))
Exemplo n.º 10
0
 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'"))
Exemplo n.º 11
0
 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'))
Exemplo n.º 12
0
 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'])
Exemplo n.º 13
0
 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'))
Exemplo n.º 14
0
 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'))
Exemplo n.º 15
0
 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'))
Exemplo n.º 16
0
 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'))
Exemplo n.º 17
0
 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"))
Exemplo n.º 18
0
 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'))
Exemplo n.º 19
0
 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'))
Exemplo n.º 20
0
 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"))
Exemplo n.º 21
0
    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)
Exemplo n.º 22
0
    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)
Exemplo n.º 23
0
 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'])
Exemplo n.º 24
0
 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')
Exemplo n.º 25
0
 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.'))
Exemplo n.º 26
0
 def testParsingGroupsDocsReturn(self):
     doc = mygrpdocs
     d = docs.DocString(myelem, '    ', doc)
     d.parse_docs()
     self.assertTrue(d.docs['in']['return'] == 'a value in a string')
Exemplo n.º 27
0
 def testAutoInputStyleGroups(self):
     doc = mygrpdocs
     d = docs.DocString(myelem, '    ', doc)
     self.assertTrue(d.get_input_style() == 'groups')
Exemplo n.º 28
0
 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')
Exemplo n.º 29
0
 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.'))
Exemplo n.º 30
0
 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.'))