Skip to content

Contributing

Paul McGuire edited this page Oct 24, 2019 · 1 revision

Unit Tests

Pyparsing has a fairly good set of unit tests, but coverage reports show that there is still room for improvement! Here is a summary listing of pyparsing classes and methods, and related tests that would improve our code coverage:

Missing unit tests:

  • ParseResutls

    • init with generator
    • insert()
    • append()
    • extend(ParseREsults)
    • extend(sequence)
    • ParseResults with int name
    • reversed(ParseResults)
    • clear()
    • __lookup() (called from getName)
    • dump() include_list=False
    • dir
    • from_dict
  • ParserElement

    • trim_arity raise TypeError in parse action
    • setBreak(False)
    • setParseAction with non-callable raises TypeError
    • setDebug with parse action
    • unbounded packrat cache
    • scanString(overlap=True)
    • transformString with parse action that converts to a list
    • ParserElement + invalid type (non str) -> SyntaxWarning
    • invalid type + ParserElement
    • ParserElement - invalid type (non str) -> SyntaxWarning
    • invalid type - ParserElement
    • ParserElement * ...
    • ParserElement * (None, 1)
    • ParserElement * invalid object -> TypeError
    • ParserElement * (invalid object,) -> TypeError
    • ParserElement * -1
    • ParserElement * (0, -1)
    • ParserElement * 0 or (0,0)
    • ParserElement * (1, 2)
    • ParserElement * (0, 2)
    • ParserElement * (1,)
    • ParserElement | invalid type (non str) -> SyntaxWarning
    • invalid type | ParserElement
    • ParserElement & invalid type (non str) -> SyntaxWarning
    • invalid type & ParserElement
    • ParserElement ^ invalid type (non str) -> SyntaxWarning
    • invalid type ^ ParserElement
    • iter(ParserElement) -> TypeError
    • ParserElement["x"]
    • ParserElement[0,1,2] -> UserWarning
    • ignore("x")
    • setDebug(False)
    • runTests where test raises an exception
  • NoMatch

  • Keyword

    • init with empty string
  • Word

    • init with excludeChars and bodyChars
    • min=0
    • asKeyword=True
  • Char

    • asKeyword=True
  • Regex

    • init with not str or re_compiled
    • asGroupList=True with no match
  • QuotedString

    • endQuoteChar=''
  • CharsNotIn

    • min < 1 -> ValueError
    • max > 0
    • parse at loc < min chars from end of string
  • White

    • max > 0
    • exact > 0
    • parse at loc < min chars from end of string
  • GoToColumn

  • StringStart

    • parse at loc > 0
  • ParseExpression (And, Or, etc.)

    • append()
    • setResultsName() if diag.warn_ungrouped_named_tokens_in_collection
  • And

    • init with sequence ending in ...
    • str + And
  • Or

    • init with empty exprs
    • match with empty exprs
    • str ^ Or
  • MatchFirst

    • init with empty exprs
    • match with empty exprs
    • str | MatchFirst
  • Each

    • str(Each) with setName
    • checkRecursion
  • ParseElementEnhance (like FollowedBy)

    • init with str
    • parse with expr=None
  • PrecededBy

    • init with Literal or Keyword
  • NotAny

    • str with setName
  • MultipleMatch

    • str with setName
  • ZeroOrMore

    • str with setName
  • Optional

    • parse with expr.setResultsName
    • str with setName
  • SkipTo

    • parse with no match in string
  • Combine

    • ignore() with adjacent=False
    • postParse with setResultsName and some contained exprs have names
  • Dict

    • postParse with no matched tokens
    • postParse with int key
  • Suppress

    • self.suppress()
  • traceParseAction

    • trace parse action that raises an exception
  • oneOf

    • invalid args -> SyntaxWarning
    • return NoMatch if args is empty
  • matchOnlyAtCol (parse action)

    • not tested
  • makeXMLTags

    • not tested
  • infixNotation

    • ternary operator with incorrect operator type -> raises ValueError
    • left assoc, arity=2 and operator is None
    • left assoc, arity not in (1, 2, 3) -> raises ValueError
    • right assoc, arity=2 and operator is None
    • right assoc, arity=3
    • right assoc, arity not in (1, 2, 3) -> raises ValueError
  • nestedExpr

    • opener == closer -> ValueError
    • len(opener) != 1 or len(closer) != 1
      •  with and without ignoreExpr
        
    • opener and/or closer is not str type
    • ignoreExpr is None
    • parse with illegal nesting
  • convertToDate

    • convert invalid string
  • convertToDatetime

    • convert invalid string

Examples

The examples directory is fairly chaotic at the moment, and could use some organization. Please submit your ideas on how this might be done, or clone the repo and submit a PR.