K iE dZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z  ddl Z dd lmZej&d ej&d d fZd ZGddZej.dZej2dej&fdZde ede e ede ede efdZdedefdZddddZdZy#e $rGddeZGddZ YwxYw)aBackwards compatible functions for running tests from SymPy using pytest. SymPy historically had its own testing framework that aimed to: - be compatible with pytest; - operate similarly (or identically) to pytest; - not require any external dependencies; - have all the functionality in one file only; - have no magic, just import the test file and execute the test functions; and - be portable. To reduce the maintenance burden of developing an independent testing framework and to leverage the benefits of existing Python testing infrastructure, SymPy now uses pytest (and various of its plugins) to run the test suite. To maintain backwards compatibility with the legacy testing interface of SymPy, which implemented functions that allowed users to run the tests on their installed version of SymPy, the functions in this module are implemented to match the existing API while thinly wrapping pytest. These two key functions are `test` and `doctest`. N)fnmatch)ListOptionalTupleceZdZdZy) NoPytestErrorzBRaise when an internal test helper function is called with pytest.N)__name__ __module__ __qualname____doc__c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/testing/runtests_pytest.pyrr$sPrrc eZdZdZedZy)pytestz@Shadow to support pytest features when pytest can't be imported.cd}t|)Nz7pytest must be installed to run tests via this function)r)argskwargsmsgs rmainz pytest.main*sKC$ $rN)r r r r staticmethodrr rrrr'sN  %  %rr)testsympydocsrc)z%sympy/integrals/rubi/rubi_tests/testsc*eZdZUdZdZeed<dZeed<dZeed<dZ eed <d Z eed <e jd e fd Ze jd e fdZe jd e fdZe jd e fdZe jd e fdZy)PytestPluginManagerz.Module names for pytest plugins used by SymPy.rPYTESTpytest_randomlyRANDOMLY pytest_splitSPLITpytest_timeoutTIMEOUTxdistXDISTreturncfttjj|jSN)bool importlibutil find_specrselfs r has_pytestzPytestPluginManager.has_pytestCs INN,,T[[9::rcfttjj|jSr))r*r+r,r-r r.s r has_randomlyz PytestPluginManager.has_randomlyGs INN,,T]];<.find_paths_matching_partialws%'") NL< A%".r"2f"< ,RS 1U : \"a'"' ,RS 1U : "' % =*11,? *11\N$2GH*11E,2HI*11E,t2LM# N$/ NH%'WWXt%D N!dE],FG9?N5\#4tqa%89s7<<+='>?"$Q$)ND&t->? 's7<<d3K/L MN N N Nrfilepathr'ctj|}|jsy|jdj dsy|j dk(syy)NFtest_rKT)r@rAis_fileparts startswithsuffix)rcr[s r is_tests_filez-update_args_with_paths..is_tests_filesG||H%||~zz"~((1{{e#rcg}tj|jd}|jD]}|j j ds#|D]r}|j j|j dk7s4|jddjdd}|d z|z}|j|t|S) Nzutf-8)encodingzdef re (rz::) r@rA read_text splitlineslstriprilowerfindsplitrP)rFrcrYsourcelinekw test_namefull_test_paths rfind_tests_matching_keywordsz.find_tests_matching_keywordssh'1171C%%' 7D{{}''/"7Bzz|((4:$(JJsOA$6$<$.is_valid_partial_paths!||L)//2g==rz Partial path z] is invalid, partial paths are expected to be defined with the `sympy` directory as the root.)r:r*dir ValueErrorr@rArD)rVrr absolute_paths rmake_absolute_pathrsf>C>D> ! .C -./M N o Y[,?@M rT subprocessrerunc|jddrZ|jdd|jdd|jdd|jdd|d<t|ddd |St}|jst j g}|jd dr|jd |jd x}r|jd |g|jdr|jd|jdds|jddg|jdx}r5|js d}t||jdt|g|jddr|jr|jdn+|jdds|js d}t||jddx} r>|js d}t||jdtt| g|jddr|jddgn|jddg|jdx} |js d }t|tj!| } | s d!}t#|t%t| j'\} } |jd"| d#| g| | kDrd$| d%| d&}t#||jd't(x}r#|D]}|jd(t+|g |jddr,|j,s d)}t||jd*d+g|jddr*|js d,}t||jd-|jd.x}t/d/|D}nd0}t1|||}t j |}|S)1aInterface to run tests via pytest compatible with SymPy's test runner. Explanation =========== Note that a `pytest.ExitCode`, which is an `enum`, is returned. This is different to the legacy SymPy test runner which would return a `bool`. If all tests successfully pass the `pytest.ExitCode.OK` with value `0` is returned, whereas the legacy SymPy test runner would return `True`. In any other scenario, a non-zero `enum` value is returned, whereas the legacy SymPy test runner would return `False`. Users need to, therefore, be careful if treating the pytest exit codes as booleans because `bool(pytest.ExitCode.OK)` evaluates to `False`, the opposite of legacy behaviour. Examples ======== >>> import sympy # doctest: +SKIP Run one file: >>> sympy.test('sympy/core/tests/test_basic.py') # doctest: +SKIP >>> sympy.test('_basic') # doctest: +SKIP Run all tests in sympy/functions/ and some particular file: >>> sympy.test("sympy/core/tests/test_basic.py", ... "sympy/functions") # doctest: +SKIP Run all tests in sympy/core and sympy/utilities: >>> sympy.test("/core", "/util") # doctest: +SKIP Run specific test from a file: >>> sympy.test("sympy/core/tests/test_basic.py", ... kw="test_equality") # doctest: +SKIP Run specific test from any file: >>> sympy.test(kw="subs") # doctest: +SKIP Run the tests using the legacy SymPy runner: >>> sympy.test(use_sympy_runner=True) # doctest: +SKIP Note that this option is slated for deprecation in the near future and is only currently provided to ensure users have an alternative option while the pytest-based runner receives real-world testing. Parameters ========== paths : first n positional arguments of strings Paths, both partial and absolute, describing which subset(s) of the test suite are to be run. subprocess : bool, default is True Legacy option, is currently ignored. rerun : int, default is 0 Legacy option, is ignored. use_sympy_runner : bool or None, default is None Temporary option to invoke the legacy SymPy test runner instead of `pytest.main`. Will be removed in the near future. verbose : bool, default is False Sets the verbosity of the pytest output. Using `True` will add the `--verbose` option to the pytest call. tb : str, 'auto', 'long', 'short', 'line', 'native', or 'no' Sets the traceback print mode of pytest using the `--tb` option. kw : str Only run tests which match the given substring expression. An expression is a Python evaluatable expression where all names are substring-matched against test names and their parent classes. Example: -k 'test_method or test_other' matches all test functions and classes whose name contains 'test_method' or 'test_other', while -k 'not test_method' matches those that don't contain 'test_method' in their names. -k 'not test_method and not test_other' will eliminate the matches. Additionally keywords are matched to classes and functions containing extra names in their 'extra_keyword_matches' set, as well as functions which have names assigned directly to them. The matching is case-insensitive. pdb : bool, default is False Start the interactive Python debugger on errors or `KeyboardInterrupt`. colors : bool, default is True Color terminal output. force_colors : bool, default is False Legacy option, is ignored. sort : bool, default is True Run the tests in sorted order. pytest uses a sorted test order by default. Requires pytest-randomly. seed : int Seed to use for random number generation. Requires pytest-randomly. timeout : int, default is 0 Timeout in seconds before dumping the stacks. 0 means no timeout. Requires pytest-timeout. fail_on_timeout : bool, default is False Legacy option, is currently ignored. slow : bool, default is False Run the subset of tests marked as `slow`. enhance_asserts : bool, default is False Legacy option, is currently ignored. split : string in form `/` or None, default is None Used to split the tests up. As an example, if `split='2/3' is used then only the middle third of tests are run. Requires pytest-split. time_balance : bool, default is True Legacy option, is currently ignored. blacklist : iterable of test paths as strings, default is BLACKLIST_DEFAULT Blacklisted test paths are ignored using the `--ignore` option. Paths may be partial or absolute. If partial then they are matched against all paths in the pytest tests path. parallel : bool, default is False Parallelize the test running using pytest-xdist. If `True` then pytest will automatically detect the number of CPU cores available and use them all. Requires pytest-xdist. store_durations : bool, False Store test durations into the file `.test_durations`. The is used by `pytest-split` to help determine more even splits when more than one test group is being used. Requires pytest-split. use_sympy_runnerFparallelstore_durationsTslowNrrverbosez --verbosetbz--tbpdbz--pdbcolorsz--colornoseedz9`pytest-randomly` plugin required to control random seed.z--randomly-seedsortz--randomly-dont-reorganizez:`pytest-randomly` plugin required to randomize test order.timeoutz;`pytest-timeout` plugin required to apply timeout to tests.z --timeoutz-mzslow and not tooslowznot slow and not tooslowrvz6`pytest-split` plugin required to run tests as groups.zNsplit must be a string of the form a/b where a and b are positive nonzero intsz--groupz--splitszcannot have a group number z with only z splits blacklistz--ignorez8`pytest-xdist` plugin required to run tests in parallel.z-nautoz7`pytest-split` plugin required to store test durations.z--store-durationsryc32K|]}t|ywr))r:).0rys r ztest..s4RR4sr )getpop test_sympyrr0rrrPrr2ModuleNotFoundErrorr:r7intr4 split_patternmatchrmapgroupsBLACKLIST_DEFAULTrr9tupler)rrrErpytest_plugin_managerrrrrrrvrgroupsplitsrr[rF exit_codes rrrspzz$e, :u% $e, %t, ::f  %"F6N5TEfEE/1 + + D zz)U# K ZZ r VRL! zz% G ::h % Y%&zz&!!t!$11MC%c* * &D 23 zz&$$9$F$F 01 ZZ %.C.P.PJ!#&&**Y--w-$00OC%c* * [#c'l"345zz&%  T123 T567G$$1$..JC%c* *##E*+CS/ !C0 v Yz6:; 6>0{6(KCS/ !JJ{,=>>y> @D KK%7%=> ? @zz*e$$..LC%c* * T6N# zz#U+$..KC%c* * '(JJt$$14844 !%4 8D D!I rct)zNInterface to run doctests via pytest compatible with SymPy's test runner. )NotImplementedErrorr rrdoctestrs  r)r r<importlib.utilr+rQr@rertypingrrrr ImportError Exceptionrsympy.testing.runtestsrrrAr}rrcompiler lru_cacherDr:rrrr rrrs7.  (( %6GLLGLL ::: 9:  -7<<-- w 9wuSz"w s)w #Y wtSS6!QhQ  %Q Q%% %sCCC