Module pyparsing :: Class pyparsing_test :: Class reset_pyparsing_context
[hide private]
[frames] | no frames]

Class reset_pyparsing_context

source code


Context manager to be used when writing unit tests that modify pyparsing config values:
 - packrat parsing
 - default whitespace characters.
 - default keyword characters
 - literal string auto-conversion class
 - __diag__ settings

Example:
    with reset_pyparsing_context():
        # test that literals used to construct a grammar are automatically suppressed
        ParserElement.inlineLiteralsUsing(Suppress)

        term = Word(alphas) | Word(nums)
        group = Group('(' + term[...] + ')')

        # assert that the '()' characters are not included in the parsed tokens
        self.assertParseAndCheckLisst(group, "(abc 123 def)", ['abc', '123', 'def'])

    # after exiting context manager, literals are converted to Literal expressions again

Instance Methods [hide private]
 
__init__(self) source code
 
save(self) source code
 
restore(self) source code
 
__enter__(self) source code
 
__exit__(self, *args) source code