Skip to content
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

Closed
gregmalcolm mannequin opened this issue Aug 15, 2010 · 9 comments
Closed

Test file 'test_keyword.py' submission for use with keyword.py #53816

gregmalcolm mannequin opened this issue Aug 15, 2010 · 9 comments
Assignees
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@gregmalcolm
Copy link
Mannequin

gregmalcolm mannequin commented Aug 15, 2010

BPO 9607
Nosy @pitrou, @benjaminp, @merwok, @bitdancer
Files
  • test_keyword_v2.patch: keyword.py tests (2nd attempt)
  • 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:

    assignee = 'https://github.com/bitdancer'
    closed_at = <Date 2013-04-24.18:36:05.375>
    created_at = <Date 2010-08-15.05:15:45.502>
    labels = ['type-feature', 'tests']
    title = "Test file 'test_keyword.py' submission for use with keyword.py"
    updated_at = <Date 2013-04-24.18:36:05.374>
    user = 'https://bugs.python.org/gregmalcolm'

    bugs.python.org fields:

    activity = <Date 2013-04-24.18:36:05.374>
    actor = 'benjamin.peterson'
    assignee = 'r.david.murray'
    closed = True
    closed_date = <Date 2013-04-24.18:36:05.375>
    closer = 'benjamin.peterson'
    components = ['Tests']
    creation = <Date 2010-08-15.05:15:45.502>
    creator = 'gregmalcolm'
    dependencies = []
    files = ['18769']
    hgrepos = []
    issue_num = 9607
    keywords = ['patch']
    message_count = 9.0
    messages = ['113942', '114909', '115712', '187395', '187396', '187398', '187567', '187719', '187721']
    nosy_count = 6.0
    nosy_names = ['pitrou', 'benjamin.peterson', 'eric.araujo', 'r.david.murray', 'gregmalcolm', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue9607'
    versions = ['Python 3.4']

    @gregmalcolm
    Copy link
    Mannequin Author

    gregmalcolm mannequin commented Aug 15, 2010

    '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.

    @gregmalcolm gregmalcolm mannequin added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Aug 15, 2010
    @bitdancer
    Copy link
    Member

    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.)

    @gregmalcolm
    Copy link
    Mannequin Author

    gregmalcolm mannequin commented Sep 6, 2010

    Thanks for the feedback David! I've replaced the old patch with a new version that uses Popen/sys.executable as suggested.

    • Greg

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 20, 2013

    New changeset 0ad18bb85371 by R David Murray in branch 'default':
    bpo-9607: Add tests for the keyword module.
    http://hg.python.org/cpython/rev/0ad18bb85371

    @bitdancer
    Copy link
    Member

    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.

    @bitdancer bitdancer added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Apr 20, 2013
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 20, 2013

    New changeset d499189e7758 by R David Murray in branch 'default':
    bpo-9607: restore keywords.kwlist after testing it.
    http://hg.python.org/cpython/rev/d499189e7758

    @merwok
    Copy link
    Member

    merwok commented Apr 22, 2013

    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)

    @pitrou
    Copy link
    Member

    pitrou commented Apr 24, 2013

    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

    @benjaminp
    Copy link
    Contributor

    See bpo-17830

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    tests Tests in the Lib/test dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants