예제 #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())
예제 #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)
예제 #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)
예제 #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"'))
예제 #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')
예제 #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'])
예제 #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.'))
예제 #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"'))
예제 #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'))
예제 #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'"))
예제 #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'))
예제 #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'])
예제 #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'))
예제 #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'))
예제 #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'))
예제 #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'))
예제 #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"))
예제 #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'))
예제 #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'))
예제 #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"))
예제 #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)
예제 #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)
예제 #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'])
예제 #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')
예제 #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.'))
예제 #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')
예제 #27
0
 def testAutoInputStyleGroups(self):
     doc = mygrpdocs
     d = docs.DocString(myelem, '    ', doc)
     self.assertTrue(d.get_input_style() == 'groups')
예제 #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')
예제 #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.'))
예제 #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.'))