U ʗReZ4@sBddlmZddlZddlmZmZmZmZmZGdddZ dS))contextmanagerN) ParserElementParseExceptionKeyword__diag__ __compat__c @sfeZdZdZGdddZGdddZed eej e ej e e eej eej eed d d Z dS) pyparsing_testzB namespace class for classes useful in writing unit tests c@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)z&pyparsing_test.reset_pyparsing_contexta Context manager to be used when writing unit tests that modify pyparsing config values: - packrat parsing - bounded recursion 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.assertParseAndCheckList(group, "(abc 123 def)", ['abc', '123', 'def']) # after exiting context manager, literals are converted to Literal expressions again cCs i|_dSN) _save_contextselfr/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/pyparsing/testing.py__init__-sz/pyparsing_test.reset_pyparsing_context.__init__cCstj|jd<tj|jd<tj|jd<tj|jd<tj|jd<tjrRtjj |jd<n d|jd<tj |jd<tj |jd<d d t j D|jd <d tji|jd <|S)Ndefault_whitespacedefault_keyword_charsliteral_string_classverbose_stacktracepackrat_enabledpackrat_cache_size packrat_parserecursion_enabledcSsi|]}|tt|qSr)getattrr).0namerrr Fsz?pyparsing_test.reset_pyparsing_context.save..rcollect_all_And_tokensr)rDEFAULT_WHITE_CHARSr rDEFAULT_KEYWORD_CHARS_literalStringClassr_packratEnabled packrat_cachesize_parse_left_recursion_enabledr _all_namesrrr rrrsave0s4        z+pyparsing_test.reset_pyparsing_context.savecCstj|jdkr t|jd|jdt_|jdt_t|jd|jdD]\}}|rht j nt j |qVdt_ |jdrt |jdn |jd t_|jd t_|jd t_|S) NrrrrrFrrrrr)rrr set_default_whitespace_charsrrrinlineLiteralsUsingitemsrenabledisabler!enable_packratr$r%rr)r rvaluerrrrestorePs.     z.pyparsing_test.reset_pyparsing_context.restorecCst|}|j|j|Sr )typer update)r retrrrcopyqs z+pyparsing_test.reset_pyparsing_context.copycCs|Sr )r'r rrr __enter__vsz0pyparsing_test.reset_pyparsing_context.__enter__cGs |dSr )r/)r argsrrr__exit__ysz/pyparsing_test.reset_pyparsing_context.__exit__N) __name__ __module__ __qualname____doc__rr'r/r3r4r6rrrrreset_pyparsing_contexts !r;c@sJeZdZdZdddZdddZddd Zdd d Zee dfd d Z dS)z&pyparsing_test.TestParseResultsAssertszk A mixin class to add parse results assertion methods to normal unittest.TestCase classes. NcCs<|dk r|j|||d|dk r8|j|||ddS)z Unit test assertion to compare a :class:`ParseResults` object with an optional ``expected_list``, and compare any defined results names with an optional ``expected_dict``. Nmsg) assertEqualas_listas_dict)r result expected_list expected_dictr=rrrassertParseResultsEqualssz?pyparsing_test.TestParseResultsAsserts.assertParseResultsEqualsTcCs@|j|dd}|r t|n t||j|||ddS)z Convenience wrapper assert to test a parser element and input string, and assert that the resulting ``ParseResults.asList()`` is equal to the ``expected_list``. T) parse_all)rBr=N parse_stringprintdumpr?rD)r expr test_stringrBr=verboserArrrassertParseAndCheckLists  z>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckListcCs@|j|dd}|r t|n t||j|||ddS)z Convenience wrapper assert to test a parser element and input string, and assert that the resulting ``ParseResults.asDict()`` is equal to the ``expected_dict``. T)parseAll)rCr=NrF)r rJrKrCr=rLrArrrassertParseAndCheckDicts  z>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDictc Cs |\}}|dk rddt||D}|D]\}}} tdd| Dd} tdd| Dd} | dk r|j| | pn|dt|tr|W5QRXq(tdd| Dd} td d| Dd} | | fd kr|j|| | | p|d q(td |q(|j||dk r|nd ddS)ah Unit test assertion to evaluate output of ``ParserElement.runTests()``. If a list of list-dict tuples is given as the ``expected_parse_results`` argument, then these are zipped with the report tuples returned by ``runTests`` and evaluated using ``assertParseResultsEquals``. Finally, asserts that the overall ``runTests()`` success value is ``True``. :param run_tests_report: tuple(bool, [tuple(str, ParseResults or Exception)]) returned from runTests :param expected_parse_results (optional): [tuple(str, list, dict, Exception)] NcSsg|]\}}||fqSrr)rrptexpectedrrr szOpyparsing_test.TestParseResultsAsserts.assertRunTestResults..css|]}t|tr|VqdSr ) isinstancestrrexprrr s zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..css&|]}t|trt|tr|VqdSr )rSr0 issubclass ExceptionrUrrrrWs )expected_exceptionr=css|]}t|tr|VqdSr )rSlistrUrrrrWs css|]}t|tr|VqdSr )rSdictrUrrrrWs )NN)rBrCr=zno validation for {!r}zfailed runTestsr<) zipnext assertRaisesrSrYrDrHformat assertTrue)r run_tests_reportexpected_parse_resultsr=run_test_successrun_test_resultsmergedrKrArQfail_msgrZrBrCrrrassertRunTestResultssV      z;pyparsing_test.TestParseResultsAsserts.assertRunTestResultsc cs$|j||d dVW5QRXdS)Nr<)r_)r exc_typer=rrrassertRaisesParseExceptionszApyparsing_test.TestParseResultsAsserts.assertRaisesParseException)NNN)NT)NT)NN) r7r8r9r:rDrMrOrhrrrjrrrrTestParseResultsAsserts|s    ?rkNT|)s start_lineend_line expand_tabseol_mark mark_spaces mark_controlreturncs|r |}dk rdkrPtddttddtddDd d iB}d n(tfd dttdd d gD}||}|dk r|dkr|dkrtddd}||}n |d|}|dkrd}|dkrt|}t |t|}t t d||}dkr| |d|}n dd| d|d|D}|sFd Stt|t dd|D} dd} | dkr| d ddtt | ddDd} nd } | | d ddt| d Dd} | d| d d} | | d fddt||d DdS)!u  Helpful method for debugging a parser - prints a string with line and column numbers. (Line and column numbers are 1-based.) :param s: tuple(bool, str - string to be printed with line and column numbers :param start_line: int - (optional) starting line number in s to print (default=1) :param end_line: int - (optional) ending line number in s to print (default=len(s)) :param expand_tabs: bool - (optional) expand tabs to spaces, to match the pyparsing default :param eol_mark: str - (optional) string to mark the end of lines, helps visualize trailing spaces (default="|") :param mark_spaces: str - (optional) special character to display in place of spaces :param mark_control: str - (optional) convert non-printing control characters to a placeholding character; valid values: - "unicode" - replaces control chars with Unicode symbols, such as "␍" and "␊" - any single character string - replace control characters with given string - None (default) - string is displayed as-is :return: str - input string with leading line numbers and column number headers NunicodecSsi|]\}}||qSrr)rcurrrrsz4pyparsing_test.with_line_numbers..r!i$i3$i!$csi|] }|qSrr)rrv)rsrrrs  i $i#$) r{rcSsg|] }|dqS)␊rrlinerrrrR'sz4pyparsing_test.with_line_numbers..r~css|]}t|VqdSr )lenrrrrrW,sz3pyparsing_test.with_line_numbers..ccss"|]}dd|ddVqdS)z{}{}zc rdNr`rirrrrW1sr css |]}d|ddVqdS)z {}r NrrrrrrW<sr 1234567890c3s"|]\}}d||VqdS)z {:{}d}:{}{}Nr)rrr)rq lineno_widthrrrWFs)start) expandtabsrT maketransr]ranger[ translatereplacerminmax splitlinessplitjoin enumerate)rmrnrorprqrrrstbls_lines max_line_lenleadheader0header1header2r)rqrrsrwith_line_numberss              z pyparsing_test.with_line_numbers)NNTrlNN) r7r8r9r:r;rk staticmethodrTtypingOptionalintboolrrrrrr s(hqr ) contextlibrrcorerrrrrr rrrrs