Example #1
0
 def testMultiLinesElements(self):
     p = pym.PyComment(inifile)
     p._parse()
     self.failUnless('first' in p.get_output_docs()[1])
     self.failUnless('second' in p.get_output_docs()[1])
     self.failUnless('third' in p.get_output_docs()[1])
     self.failUnless('multiline' in p.get_output_docs()[1])
 def testCaseFreeTesting(self):
     # free cases
     p = pym.PyComment(absdir("free_cases.py"))
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     self.assertTrue(result == '')
Example #3
0
 def testIssue51(self):
     # Title:  Raise block convertion
     p = pym.PyComment(absdir('issue51.py'), output_style='google')
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     self.assertTrue(result == '')
Example #4
0
 def testIssue95(self):
     # Title: When there's a parameter without description in reST, Pyment copies the whole next element
     p = pym.PyComment(absdir('issue95.py'))
     p._parse()
     f = open(absdir('issue95.py.patch'))
     patch = f.read()
     f.close()
     self.assertEqual(''.join(p.diff()), patch)
Example #5
0
 def testIssue99(self):
     # Title: Type is removed from parameter if not in type hints when converting reST docstring
     p = pym.PyComment(absdir('issue99.py'))
     p._parse()
     f = open(absdir('issue99.py.patch'))
     patch = f.read()
     f.close()
     self.assertEqual(''.join(p.diff()), patch)
 def testCaseNoGenDocsAlreadyReST(self):
     # The file has functions with already docstrings in reST format,
     # so no docstring should be produced
     p = pym.PyComment(absdir("docs_already_reST.py"))
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     self.assertTrue(result == '')
Example #7
0
 def testIssue47(self):
     # Title:  Extra blank line for docstring with a muli-line description #47
     # If a function has no argument and a multi-line description, Pyment will insert two blank lines
     # between the description and the end of the docstring.
     p = pym.PyComment(absdir('issue47.py'))
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     self.assertTrue(result == '')
Example #8
0
 def testIssue34(self):
     # Title: Problem with regenerating empty param docstring
     # if two consecutive params have empty descriptions, the first will
     # be filled with the full second param line
     p = pym.PyComment(absdir('issue34.py'))
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     self.assertTrue(result == '')
Example #9
0
 def testIssue93(self):
     # Title: Support for type hints
     # Add support for type hints (PEP 484).
     p = pym.PyComment(absdir('issue93.py'))
     p._parse()
     f = open(absdir('issue93.py.patch'))
     patch = f.read()
     f.close()
     self.assertEqual(''.join(p.diff()), patch)
Example #10
0
 def testCaseGenAllParamsReST(self):
     # The file has several functions with no or several parameters,
     # so Pyment should produce docstrings in reST format
     expected = get_expected_patch(self, "params.py.patch.reST.expected")
     p = pym.PyComment(absdir("params.py"))
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     self.assertTrue(result == expected)
 def testCaseNoGenDocsAlreadyJavadoc(self):
     # The file has functions with already docstrings in javadoc format,
     # so no docstring should be produced
     p = pym.PyComment(absdir("docs_already_javadoc.py"),
                       output_style="javadoc")
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     self.assertTrue(result == '')
Example #12
0
 def testIssue69(self):
     # Title: Wrong Formatting for Input params with default values
     # When default value has a list it is split and considers list's elements as parameters
     p = pym.PyComment(absdir('issue69.py'))
     p._parse()
     f = open(absdir('issue69.py.patch'))
     patch = f.read()
     f.close()
     self.assertEqual(''.join(p.diff()), patch)
Example #13
0
 def testCaseGenAllParamsJavadoc(self):
     # The file has several functions with no or several parameters,
     # so Pyment should produce docstrings in javadoc
     expected = get_expected_patch(self, "params.py.patch.javadoc.expected")
     p = pym.PyComment(absdir("params.py"), output_style="javadoc")
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     self.assertTrue(result == expected)
Example #14
0
 def testIssue88(self):
     # Title: Not working on async functions
     # The async functions are not managed
     p = pym.PyComment(absdir('issue88.py'))
     p._parse()
     f = open(absdir('issue88.py.patch'))
     patch = f.read()
     f.close()
     self.assertEqual(''.join(p.diff()), patch)
Example #15
0
 def testIssue9(self):
     issue9 = absdir('issue9.py')
     p = pym.PyComment(issue9)
     p._parse()
     self.assertTrue(p.parsed)
     res = p.diff(issue9, "{0}.patch".format(issue9))
     self.assertTrue(res[8].strip() != "-    :return: smthg")
     self.assertTrue(res[9].strip() != "-    :rtype: ret type")
     self.assertTrue(res[10].strip() != "+:return: smthg")
 def testCaseGenAllParamsGoogle(self):
     # The file has several functions with no or several parameters,
     # so Pyment should produce docstrings in google format
     expected = get_expected_patch(self, "params.py.patch.google.expected")
     p = pym.PyComment(absdir("params.py"), output_style="google")
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     self.assertTrue(
         remove_diff_header(result) == remove_diff_header(expected))
Example #17
0
 def testIssue30(self):
     # if file starting with a function/class definition, patching the file
     # will remove the first line!
     p = pym.PyComment(absdir('issue30.py'), input_style="numpydoc", output_style="numpydoc")
     p._parse()
     self.assertTrue(p.parsed)
     try:
         p.diff()
     except Exception as e:
         self.fail('Raised expection: "{0}"'.format(e))
Example #18
0
 def testIssue49(self):
     # Title: If already numpydoc format, will remove the Raises section
     # If the last section in a numpydoc docstring is a `Raises` section,
     # it will be removed if the output format is also set to numpydoc
     p = pym.PyComment(absdir('issue49.py'), output_style='numpydoc')
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     print(result)
     self.assertTrue(result == '')
Example #19
0
 def testIssue90(self):
     # Title: __doc__ is not well parsed
     # If the line after function signature contains triple [double] quotes but is not a docstring
     # it will be however considered as if it was and will have side effect.
     p = pym.PyComment(absdir('issue90.py'))
     p._parse()
     f = open(absdir('issue90.py.patch'))
     patch = f.read()
     f.close()
     self.assertEqual(''.join(p.diff()), patch)
Example #20
0
 def testMultiLinesShiftElements(self):
     p = pym.PyComment(inifile)
     p._parse()
     #TODO: improve this test
     self.assertEqual((len(p.get_output_docs()[13]) -
                       len(p.get_output_docs()[13].lstrip())), 8)
     self.failUnless('first' in p.get_output_docs()[13])
     self.failUnless('second' in p.get_output_docs()[13])
     self.failUnless('third' in p.get_output_docs()[13])
     self.failUnless('multiline' in p.get_output_docs()[13])
Example #21
0
 def testWindowsRename(self):
     bar = absdir("bar")
     with open(bar, "w") as fbar:
         fbar.write("bar")
     p = pym.PyComment(foo)
     p._windows_rename(bar)
     self.assertFalse(os.path.isfile(bar))
     self.assertTrue(os.path.isfile(foo))
     with open(foo, "r") as fooo:
         foo_txt = fooo.read()
     self.assertTrue(foo_txt == "bar")
Example #22
0
 def testIssue85(self):
     # Title: When converting from reST, parameter types are not handled correctly
     # For reST, Sphinx allows to declare the type inside the parameter statement
     # like this: `:param str name: description`
     # Pyment should support this.
     p = pym.PyComment(absdir('issue85.py'))
     p._parse()
     f = open(absdir('issue85.py.patch'))
     patch = f.read()
     f.close()
     self.assertEqual(''.join(p.diff()), patch)
Example #23
0
 def testIssue9(self):
     # Title: :rtype: is removed from doc comments; :return: loses indentation
     issue9 = absdir('issue9.py')
     p = pym.PyComment(issue9)
     p._parse()
     self.assertTrue(p.parsed)
     res = p.diff(issue9, "{0}.patch".format(issue9))
     self.assertTrue(res[8].strip() == "-    :return: smthg")
     self.assertTrue(res[9].strip() == "+    :returns: smthg")
     self.assertTrue((res[10][1:].rstrip() == "    :rtype: ret type")
                     and (res[10][0] == ' '))
Example #24
0
 def testIssue15(self):
     # Title: Does not convert existing docstrings
     try:
         f = open(absdir("issue15.py.patch.expected"))
         expected = f.read()
         f.close()
     except Exception as e:
         self.fail('Raised exception: "{0}"'.format(e))
     p = pym.PyComment(absdir('issue15.py'))
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     self.assertTrue(result == expected)
Example #25
0
 def testIssue10(self):
     # Title: created patch-file not correct
     try:
         f = open(absdir("issue10.py.patch.expected"))
         expected = f.read()
         f.close()
     except Exception as e:
         self.fail('Raised exception: "{0}"'.format(e))
     p = pym.PyComment(absdir('issue10.py'))
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     self.assertTrue(result == expected)
Example #26
0
 def testIssue46(self):
     # Title: list, tuple, dict default param values are not parsed correctly
     # if a list/tuple/dict is given as default value for a parameter, the
     # commas will be considered as separators for parameters
     try:
         f = open(absdir("issue46.py.patch.expected"))
         expected = f.readlines()
         if expected[0].startswith("# Patch"):
             expected = expected[2:]
         expected = "".join(expected)
         f.close()
     except Exception as e:
         self.fail('Raised exception: "{0}"'.format(e))
     p = pym.PyComment(absdir('issue46.py'))
     p._parse()
     self.assertTrue(p.parsed)
     result = ''.join(p.diff())
     self.assertTrue(result == expected)
Example #27
0
    def testIssue32(self):
        # if file starting with a function/class definition, patching the file
        # will remove the first line!
        expected = """--- a/issue32.py
+++ b/issue32.py
@@ -1,2 +1,8 @@
 def hello_world(a=22, b='hello'):
+    '''
+
+    :param a:  (Default value = 22)
+    :param b:  (Default value = 'hello')
+
+    '''
   return 42"""
        p = pym.PyComment(absdir('issue32.py'))
        p._parse()
        self.assertTrue(p.parsed)
        result = ''.join(p.diff())
        self.assertTrue(result == expected)
Example #28
0
    def testIssue22(self):
        # Title: Class __init__() docstrings are not generated
        expected = '''--- a/issue22.py
+++ b/issue22.py
@@ -2,4 +2,9 @@
     """Test class for issue 22"""
 
     def __init__(self, param1):
+        """
+
+        :param param1: 
+
+        """
         pass
'''
        p = pym.PyComment(absdir('issue22.py'))
        p._parse()
        self.assertTrue(p.parsed)
        result = ''.join(p.diff())
        self.assertTrue(result == expected)
Example #29
0
    def testIssue58(self):
        # Title: Comments after def statement not supported
        # If a function's def statement is followed by a comment it won't be proceeded.
        p = pym.PyComment(absdir('issue58.py'))
        expected = '''--- a/issue58.py
+++ b/issue58.py
@@ -1,5 +1,9 @@
 def func(param): # some comment
-    """some docstring"""
+    """some docstring
+
+    :param param: 
+
+    """
     pass
 
 
'''
        p._parse()
        self.assertTrue(p.parsed)
        result = ''.join(p.diff())
        self.assertTrue(result == expected)
Example #30
0
 def testSameOutJavadocReST(self):
     pj = pym.PyComment(jvdfile)
     pr = pym.PyComment(rstfile)
     pj._parse()
     pr._parse()
     self.assertEqual(pj.get_output_docs(), pr.get_output_docs())