Menu

#7 Fixes for 2 issues with Each and 1 issue with Keyword/Literal

Unstable (example)
open
None
5
2016-09-10
2014-11-26
No

The following patch fixes three issues and provides accompanying tests.

The issues are:

  • elements that are not allowed to generate IndexErrors (Keyword, Literal), do generate them when attempting a match against trailing whitespace
  • ParseFatalExceptions raised during tryParse are demoted to ParseExceptions, which means the error stop operator does not work as expected within an Each
  • When Each reported one or more missing required elements, the reported location of the error would not be after the last successfully matched item

I decided to put the new tests in a separate file from the existing tests (unitTests2.py for now), because the existing tests were of mixed levels and generated a lot of output even when successful.
The new set of tests have the following properties:

  • They are implemented in one test class per tested class and one function per test case
  • They each test a single thing
  • What they test is expressed in the method name
  • They don't generate output unless they fail
  • They rely on test method discovery, so no code is needed for creation of a test suite or a test runner.

I hope you like the way these tests are set up, but if you don't, feel free to integrate them into the other suite.

Regards,
Maurice.

1 Attachments

Related

Patches: #7

Discussion

  • Maurice van der Pot

    After the fix of reporting tmpLoc instead of loc, I see that markInputline() incorrectly reports the start of the line if the match fails at the end of a line.

    This is because col() has a special case for when strg[loc] == '\n'.

    I don't see the need for this special case. Also passing the loc of the newline is the only way to report an error after the last regular character of the line.

    The code works properly for me when I remove the special case.

    Thoughts?

     

    Last edit: Maurice van der Pot 2014-12-06
    • Paul McGuire

      Paul McGuire - 2014-12-06

      Maurice -

      Thanks for submitting these, sorry for not looking closely at them yet. I've
      been pretty jammed at work, I'll try to get to them this weekend.

      -- Paul

      From: Maurice van der Pot [mailto:griffon26@users.sf.net]
      Sent: Saturday, December 06, 2014 5:53 AM
      To: [pyparsing:patches]
      Subject: [pyparsing:patches] #7 Fixes for 2 issues with Each and 1 issue
      with Keyword/Literal

      .


      [patches:#7] http://sourceforge.net/p/pyparsing/patches/7 Fixes for 2
      issues with Each and 1 issue with Keyword/Literal

      Status: open
      Group: Unstable (example)
      Created: Wed Nov 26, 2014 05:50 PM UTC by Maurice van der Pot
      Last Updated: Wed Nov 26, 2014 05:50 PM UTC
      Owner: Paul McGuire

      The following patch fixes three issues and provides accompanying tests.

      The issues are:

      • elements that are not allowed to generate IndexErrors (Keyword,
        Literal), do generate them when attempting a match against trailing
        whitespace
      • ParseFatalExceptions raised during tryParse are demoted to
        ParseExceptions, which means the error stop operator does not work as
        expected within an Each
      • When Each reported one or more missing required elements, the
        reported location of the error would not be after the last successfully
        matched item

      I decided to put the new tests in a separate file from the existing tests
      (unitTests2.py for now), because the existing tests were of mixed levels and
      generated a lot of output even when successful.
      The new set of tests have the following properties:

      • They are implemented in one test class per tested class and one
        function per test case
      • They each test a single thing
      • What they test is expressed in the method name
      • They don't generate output unless they fail
      • They rely on test method discovery, so no code is needed for
        creation of a test suite or a test runner.

      I hope you like the way these tests are set up, but if you don't, feel free
      to integrate them into the other suite.

      Regards,
      Maurice.


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/pyparsing/patches/7/
      https://sourceforge.net/p/pyparsing/patches/7

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/
      https://sourceforge.net/auth/subscriptions


      This email is free from viruses and malware because avast! Antivirus protection is active.
      http://www.avast.com

       

      Related

      Patches: #7

  • Paul McGuire

    Paul McGuire - 2016-09-10

    Maurice -
    I've redone the pyparsing unittest.py file to incorporate some of your suggested behavior, although the basic structure is the same.
    1. Test suites are now composed using test discovery, instead of the ugly explicit method used previously. Test discovery is done based on subclassing, and I use inspect to maintain the order of tests in their order of declaration in the file.
    2. Test output is suppressed for successful tests. This is a major benefit, and has already helped me to clean up some of my tests and test structure.

    Thanks again for the suggestions!
    -- Paul McGuire

     

Log in to post a comment.