New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test file 'test_keyword.py' submission for use with keyword.py #53816
Comments
'keyword.py' didn't have any tests, so I wrote some. Most of the tests are are for the main() method, which self-populates the keywords section of keyword.py with keywords taken from a grammar file, 'Python/graminit.c'. The main() method allows you to choose the grammar file and the target file, so I've written the tests such that the actual keyword.py does not have to modify itself. Most of the tests generate dummy keyword.py and graminit.c files for parsing. They are all deleted in the tearUp() stages of each test. I've timed the tests. In total they take approximately 3 seconds so you may want to tag some of them as "slow". Also I've only tested on the mac, so someone may want to check it runs ok on Windows. Most of the patch was written at the PyOhio 2010 Sprints. Thanks go to David Murray for advice given while working on it. |
Greg, thanks for working on this. I haven't looked over the whole patch yet, but there's one thing I noticed right away that needs to be fixed. 'python.exe' is the name of the python executable only on OS X, and the tests are not always run from the build directory. To make the test OS and location independent you should instead use subprocess.Popen to run the tests, with sys.executable as the program to run. (You can take a look at how other tests in the test suite do this by searching for sys.executable in the test suite.) |
Thanks for the feedback David! I've replaced the old patch with a new version that uses Popen/sys.executable as suggested.
|
New changeset 0ad18bb85371 by R David Murray in branch 'default': |
Wow, it sure took me a long time to get back to this. Greg, the test ideas in your patch were great, and I used them all, but I wound up rewriting the actual code to better match the style of our other unit tests, and also to take advantage of some of our test infrastructure that should (I hope) allow the tests to run correctly on Windows as well as unix. Thanks for your work, and sorry it took me so long to do something with it. |
New changeset d499189e7758 by R David Murray in branch 'default': |
Just wanted to note that addCleanup is smarter than many core devs think: self.addCleanup(lambda: setattr(keyword, 'kwlist', oldlist))
self.addCleanup(setattr, keyword, 'kwlist', oldlist) |
Tests broken under Windows: ====================================================================== Traceback (most recent call last):
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_keyword.py", line 122, in test_keywords_py_without_markers_produces_error
self.assertEqual(stderr, b'target does not contain format markers\n')
AssertionError: b'target does not contain format markers\r\n' != b'target does not contain format markers\n' ====================================================================== Traceback (most recent call last):
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_keyword.py", line 63, in test_real_grammar_and_keyword_file
self.assertTrue(filecmp.cmp(KEYWORD_FILE, TEST_PY_FILE))
AssertionError: False is not true |
See bpo-17830 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: