classification
Title: Test file 'test_keyword.py' submission for use with keyword.py
Type: enhancement Stage: resolved
Components: Tests Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: r.david.murray Nosy List: benjamin.peterson, eric.araujo, gregmalcolm, pitrou, python-dev, r.david.murray
Priority: normal Keywords: patch

Created on 2010-08-15 05:15 by gregmalcolm, last changed 2013-04-24 18:36 by benjamin.peterson. This issue is now closed.

Files
File name Uploaded Description Edit
test_keyword_v2.patch gregmalcolm, 2010-09-06 16:10 keyword.py tests (2nd attempt)
Messages (9)
msg113942 - (view) Author: Greg Malcolm (gregmalcolm) Date: 2010-08-15 05:15
'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.
msg114909 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-25 13:56
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.)
msg115712 - (view) Author: Greg Malcolm (gregmalcolm) Date: 2010-09-06 16:10
Thanks for the feedback David! I've replaced the old patch with a new version that uses Popen/sys.executable as suggested.

- Greg
msg187395 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-04-20 02:16
New changeset 0ad18bb85371 by R David Murray in branch 'default':
#9607: Add tests for the keyword module.
http://hg.python.org/cpython/rev/0ad18bb85371
msg187396 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-04-20 02:19
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.
msg187398 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-04-20 02:40
New changeset d499189e7758 by R David Murray in branch 'default':
#9607: restore keywords.kwlist after testing it.
http://hg.python.org/cpython/rev/d499189e7758
msg187567 - (view) Author: √Čric Araujo (eric.araujo) * (Python committer) Date: 2013-04-22 15:21
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)
msg187719 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-04-24 18:33
Tests broken under Windows:


======================================================================
FAIL: test_keywords_py_without_markers_produces_error (test.test_keyword.TestKeywordGeneration)
----------------------------------------------------------------------
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'

======================================================================
FAIL: test_real_grammar_and_keyword_file (test.test_keyword.TestKeywordGeneration)
----------------------------------------------------------------------
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

http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.x/builds/1850/steps/test/logs/stdio
msg187721 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2013-04-24 18:36
See #17830
History
Date User Action Args
2013-04-24 18:36:05benjamin.petersonsetstatus: open -> closed

messages: + msg187721
2013-04-24 18:33:32pitrousetstatus: closed -> open

nosy: + pitrou
messages: + msg187719

assignee: r.david.murray
2013-04-22 15:21:48eric.araujosetnosy: + eric.araujo
messages: + msg187567
2013-04-20 02:40:25python-devsetmessages: + msg187398
2013-04-20 02:19:19r.david.murraysetstatus: open -> closed
versions: + Python 3.4, - Python 3.2
type: behavior -> enhancement
messages: + msg187396

resolution: fixed
stage: resolved
2013-04-20 02:16:31python-devsetnosy: + python-dev
messages: + msg187395
2010-09-06 16:10:58gregmalcolmsetfiles: + test_keyword_v2.patch

messages: + msg115712
2010-09-06 16:05:55gregmalcolmsetfiles: - test_keyword.patch
2010-08-25 13:56:51r.david.murraysetmessages: + msg114909
2010-08-15 12:26:00pitrousetnosy: + benjamin.peterson
2010-08-15 05:15:45gregmalcolmcreate