dadadel / pyment

Format and convert Python docstrings and generates patches
GNU General Public License v3.0
905 stars 62 forks source link

Common base class for NumpydocTools and GoogledocTools #64

Closed wagnerpeer closed 6 years ago

wagnerpeer commented 6 years ago

This PR is an implementation of the proposed common base class, described in issue #63.

On my way to extract the common base class, I had to alter a few places of the tests to make them work for my OS (Windows 10) and I am not completely sure if this is the intended way to go here. Next to the direct modifications I had to do, I also reactivated a few commented tests for issues still present and decorated them with the statement @unittest.expectedFailure

If I worked correctly, the tests should now run on Windows and Unix systems. As well there should no longer be the need for modification to the PYTHONPATH environment variable or knowing the path to the Python executable in advance. Disclaimer: I was not able to test those changes!

I would like to get feedback on the proposal and discuss further changes and improvements to the idea. Thanks for all your effort!

dadadel commented 6 years ago

Hi @wagnerpeer,

I tested on linux with Python 2.7 and 3.5 and got the test_app tests in failures. Those tests are related to the stdin feature of issue #53 and the pull request #59. It is strange as the errors are due to a bad virtual python path (missing folder bin/). (FYI I had already a failure concerning only the testNoArgs test in Python3 but for an other reason)

There are the details of test failures:

~/dev/pyment$ python setup.py test
running test
running egg_info
writing top-level names to Pyment.egg-info/top_level.txt
writing dependency_links to Pyment.egg-info/dependency_links.txt
writing Pyment.egg-info/PKG-INFO
writing entry points to Pyment.egg-info/entry_points.txt
reading manifest file 'Pyment.egg-info/SOURCES.txt'
writing manifest file 'Pyment.egg-info/SOURCES.txt'
running build_ext
testNoArgs (test_app.AppTests) ... FAIL
testOverwriteFilesDifferent (test_app.AppTests) ... FAIL
testOverwriteFilesTheSame (test_app.AppTests) ... FAIL
testPatchFilesDifferent (test_app.AppTests) ... FAIL
testPatchFilesTheSame (test_app.AppTests) ... FAIL
testRunOnStdinOverwrite (test_app.AppTests) ... FAIL
testStdinPatchMode (test_app.AppTests) ... FAIL
testAutoInputStyleGoogledoc (test_docs.DocStringTests) ... ok
testAutoInputStyleGroups (test_docs.DocStringTests) ... ok
testAutoInputStyleJavadoc (test_docs.DocStringTests) ... ok
testAutoInputStyleNumpydoc (test_docs.DocStringTests) ... ok
testAutoInputStyleReST (test_docs.DocStringTests) ... ok
testChekListParamsGoogledoc (test_docs.DocStringTests) ... ok
testGeneratingDocsDesc (test_docs.DocStringTests) ... ok
testGeneratingDocsParams (test_docs.DocStringTests) ... ok
testGeneratingDocsRaise (test_docs.DocStringTests) ... ok
testGeneratingDocsReturn (test_docs.DocStringTests) ... ok
testIfParsedDocs (test_docs.DocStringTests) ... ok
testNoParam (test_docs.DocStringTests) ... ok
testOneLineDocs (test_docs.DocStringTests) ... ok
testParsingDocsDesc (test_docs.DocStringTests) ... ok
testParsingDocsParams (test_docs.DocStringTests) ... ok
testParsingDocsRaises (test_docs.DocStringTests) ... ok
testParsingDocsReturn (test_docs.DocStringTests) ... ok
testParsingElement (test_docs.DocStringTests) ... ok
testParsingGoogleDocsDesc (test_docs.DocStringTests) ... ok
testParsingGoogleDocsParams (test_docs.DocStringTests) ... ok
testParsingGoogleDocsRaises (test_docs.DocStringTests) ... ok
testParsingGoogleDocsReturn (test_docs.DocStringTests) ... ok
testParsingGroups2DocsParams (test_docs.DocStringTests) ... ok
testParsingGroups2DocsRaises (test_docs.DocStringTests) ... ok
testParsingGroupsDocsDesc (test_docs.DocStringTests) ... ok
testParsingGroupsDocsParams (test_docs.DocStringTests) ... ok
testParsingGroupsDocsRaises (test_docs.DocStringTests) ... ok
testParsingGroupsDocsReturn (test_docs.DocStringTests) ... ok
testParsingNumpyDocsDesc (test_docs.DocStringTests) ... 49 50
ok
testParsingNumpyDocsParams (test_docs.DocStringTests) ... 49 50
ok
testParsingNumpyDocsRaises (test_docs.DocStringTests) ... 49 50
ok
testParsingNumpyDocsReturn (test_docs.DocStringTests) ... 49 50
ok
testSameOutputJavadocReST (test_docs.DocStringTests) ... ok
testIssue10 (test_issues.IssuesTests) ... ok
testIssue11 (test_issues.IssuesTests) ... 1 2
ok
testIssue15 (test_issues.IssuesTests) ... ok
testIssue19 (test_issues.IssuesTests) ... ok
testIssue30 (test_issues.IssuesTests) ... ok
testIssue32 (test_issues.IssuesTests) ... ok
testIssue34 (test_issues.IssuesTests) ... expected failure
testIssue46 (test_issues.IssuesTests) ... expected failure
testIssue47 (test_issues.IssuesTests) ... expected failure
testIssue49 (test_issues.IssuesTests) ... 
ok
testIssue58 (test_issues.IssuesTests) ... ok
testIssue9 (test_issues.IssuesTests) ... ok
setup
testMultiLinesElements (test_pyment.DocStringTests) ... ok
testMultiLinesShiftElements (test_pyment.DocStringTests) ... ok
testParsedJavadoc (test_pyment.DocStringTests) ... ok
testSameOutJavadocReST (test_pyment.DocStringTests) ... ok
testWindowsRename (test_pyment.DocStringTests) ... ok
end
testCaseFreeTesting (test_pyment_cases.FilesConversionTests) ... ok
testCaseGenAllParamsGoogle (test_pyment_cases.FilesConversionTests) ... expected failure
testCaseGenAllParamsJavadoc (test_pyment_cases.FilesConversionTests) ... ok
testCaseGenAllParamsNumpydoc (test_pyment_cases.FilesConversionTests) ... ok
testCaseGenAllParamsReST (test_pyment_cases.FilesConversionTests) ... ok
testCaseNoGenDocsAlreadyGoogle (test_pyment_cases.FilesConversionTests) ... expected failure
testCaseNoGenDocsAlreadyJavadoc (test_pyment_cases.FilesConversionTests) ... ok
testCaseNoGenDocsAlreadyNumpydoc (test_pyment_cases.FilesConversionTests) ... expected failure
testCaseNoGenDocsAlreadyReST (test_pyment_cases.FilesConversionTests) ... ok

======================================================================
FAIL: testNoArgs (test_app.AppTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 216, in testNoArgs
    expected_returncode=2
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 203, in runPymentAppAndAssertIsExpected
    assert_output(cmd_to_run, 'stderr', stderr, expected_stderr)
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 183, in assert_output
    assert expected.search(got) is not None, msg
AssertionError: Test failed for cmd /home/dadadel/.local/share/virtualenvs/pyment/python -m pyment.pymentapp 
stderr was expected to match the regex:
re.compile('usage: pymentapp.py \\[-h\\] \\[-i style\\] \\[-o style\\] \\[-q quotes\\] \\[-f status\\] \\[-t\\].?.?\\s{20}\\[-c config\\] \\[-d\\] \\[-p status\\] \\[-v\\] \\[-w\\].?.?\\s{20}path.?.?pymentapp\\., re.DOTALL)
But this was the output:
'/bin/sh: 1: /home/dadadel/.local/share/virtualenvs/pyment/python: not found\n'

======================================================================
FAIL: testOverwriteFilesDifferent (test_app.AppTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 335, in testOverwriteFilesDifferent
    overwrite_mode=True,
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 285, in runPymentAppWithAFileAndAssertIsExpected
    output_format=output_format,
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 203, in runPymentAppAndAssertIsExpected
    assert_output(cmd_to_run, 'stderr', stderr, expected_stderr)
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 194, in assert_output
    assert got == expected, msg
AssertionError: Test failed for cmd /home/dadadel/.local/share/virtualenvs/pyment/python -m pyment.pymentapp  /tmp/tmprtvtlngt.input -w  --output google 
stderr was expected to be:
''
But this was the output:
'/bin/sh: 1: /home/dadadel/.local/share/virtualenvs/pyment/python: not found\n'

======================================================================
FAIL: testOverwriteFilesTheSame (test_app.AppTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 326, in testOverwriteFilesTheSame
    overwrite_mode=True,
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 285, in runPymentAppWithAFileAndAssertIsExpected
    output_format=output_format,
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 203, in runPymentAppAndAssertIsExpected
    assert_output(cmd_to_run, 'stderr', stderr, expected_stderr)
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 194, in assert_output
    assert got == expected, msg
AssertionError: Test failed for cmd /home/dadadel/.local/share/virtualenvs/pyment/python -m pyment.pymentapp  /tmp/tmpzt0d3qoi.input -w  --output google 
stderr was expected to be:
''
But this was the output:
'/bin/sh: 1: /home/dadadel/.local/share/virtualenvs/pyment/python: not found\n'

======================================================================
FAIL: testPatchFilesDifferent (test_app.AppTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 351, in testPatchFilesDifferent
    output_format=self.OUTPUT_FORMAT
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 285, in runPymentAppWithAFileAndAssertIsExpected
    output_format=output_format,
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 203, in runPymentAppAndAssertIsExpected
    assert_output(cmd_to_run, 'stderr', stderr, expected_stderr)
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 194, in assert_output
    assert got == expected, msg
AssertionError: Test failed for cmd /home/dadadel/.local/share/virtualenvs/pyment/python -m pyment.pymentapp  /tmp/tmpvvhl8liz.input --output google 
stderr was expected to be:
''
But this was the output:
'/bin/sh: 1: /home/dadadel/.local/share/virtualenvs/pyment/python: not found\n'

======================================================================
FAIL: testPatchFilesTheSame (test_app.AppTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 343, in testPatchFilesTheSame
    output_format=self.OUTPUT_FORMAT
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 285, in runPymentAppWithAFileAndAssertIsExpected
    output_format=output_format,
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 203, in runPymentAppAndAssertIsExpected
    assert_output(cmd_to_run, 'stderr', stderr, expected_stderr)
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 194, in assert_output
    assert got == expected, msg
AssertionError: Test failed for cmd /home/dadadel/.local/share/virtualenvs/pyment/python -m pyment.pymentapp  /tmp/tmpxp8rzycm.input --output google 
stderr was expected to be:
''
But this was the output:
'/bin/sh: 1: /home/dadadel/.local/share/virtualenvs/pyment/python: not found\n'

======================================================================
FAIL: testRunOnStdinOverwrite (test_app.AppTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 235, in testRunOnStdinOverwrite
    output_format=self.OUTPUT_FORMAT,
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 203, in runPymentAppAndAssertIsExpected
    assert_output(cmd_to_run, 'stderr', stderr, expected_stderr)
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 194, in assert_output
    assert got == expected, msg
AssertionError: Test failed for cmd /home/dadadel/.local/share/virtualenvs/pyment/python -m pyment.pymentapp -w - --output google 
stderr was expected to be:
''
But this was the output:
'/bin/sh: 1: /home/dadadel/.local/share/virtualenvs/pyment/python: not found\n'

======================================================================
FAIL: testStdinPatchMode (test_app.AppTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 225, in testStdinPatchMode
    output_format=self.OUTPUT_FORMAT,
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 203, in runPymentAppAndAssertIsExpected
    assert_output(cmd_to_run, 'stderr', stderr, expected_stderr)
  File "/home/dadadel/dev/pyment/tests/test_app.py", line 194, in assert_output
    assert got == expected, msg
AssertionError: Test failed for cmd /home/dadadel/.local/share/virtualenvs/pyment/python -m pyment.pymentapp - --output google 
stderr was expected to be:
''
But this was the output:
'/bin/sh: 1: /home/dadadel/.local/share/virtualenvs/pyment/python: not found\n'

----------------------------------------------------------------------
Ran 66 tests in 0.172s

FAILED (failures=7, expected failures=6)
Test failed: <unittest.runner.TextTestResult run=66 errors=0 failures=7>
error: Test failed: <unittest.runner.TextTestResult run=66 errors=0 failures=7>
wagnerpeer commented 6 years ago

It's all the same error. The interpreter could not be found. At the moment I can't explain, because I thought the sys.exec_prefix should point to the interpreter in any circumstance. I will try to find a solution tomorrow.

wagnerpeer commented 6 years ago

By accident I used the wrong attribute from the sys module. It must be sys.executable not sys.exec_prefix. To prevent other bugs kreeping into the commit I tested on my Windows machine as well as I set up an integration build using TravisCI for which I also created a PR (#68 )

dadadel commented 6 years ago

Thanks!