
    \hE              	          S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	J
r
Jr   SSKrSS	KJr  \R&                  " S
5      \R&                  " SS5      4rSr " S S5      r\R.                  " S5      r\R2                  S\R&                  4S j5       rS\	\   S\
\\      S\	\   S\	\   4S jrS\S\4S jrSSS.S jrS rg! \ a     " S S\5      r " S S5      r Nf = f)a  Backwards 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)ListOptionalTuplec                       \ rS rSrSrSrg)NoPytestError$   zBRaise when an internal test helper function is called with pytest. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r
       U/var/www/auris/envauris/lib/python3.13/site-packages/sympy/testing/runtests_pytest.pyr   r   $   s    Pr   r   c                   (    \ rS rSrSr\S 5       rSrg)pytest'   z@Shadow to support pytest features when pytest can't be imported.c                      Sn[        U5      e)Nz7pytest must be installed to run tests via this function)r   )argskwargsmsgs      r   mainpytest.main*   s    KC$$r   r
   N)r   r   r   r   r   staticmethodr   r   r
   r   r   r   r   '   s    N		% 
	%r   r   )testsympydocsrc)z%sympy/integrals/rubi/rubi_tests/testsc                   <   \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\\S'   S	r
\\S
'   Sr\\S'   \R                  S\4S j5       r\R                  S\4S j5       r\R                  S\4S j5       r\R                  S\4S j5       r\R                  S\4S j5       rSrg)PytestPluginManager;   z.Module names for pytest plugins used by SymPy.r   PYTESTpytest_randomlyRANDOMLYpytest_splitSPLITpytest_timeoutTIMEOUTxdistXDISTreturnc                 f    [        [        R                  R                  U R                  5      5      $ N)bool	importlibutil	find_specr$   selfs    r   
has_pytestPytestPluginManager.has_pytestC   s     INN,,T[[9::r   c                 f    [        [        R                  R                  U R                  5      5      $ r/   )r0   r1   r2   r3   r&   r4   s    r   has_randomly PytestPluginManager.has_randomlyG   s     INN,,T]];<<r   c                 f    [        [        R                  R                  U R                  5      5      $ r/   )r0   r1   r2   r3   r(   r4   s    r   	has_splitPytestPluginManager.has_splitK        INN,,TZZ899r   c                 f    [        [        R                  R                  U R                  5      5      $ r/   )r0   r1   r2   r3   r*   r4   s    r   has_timeoutPytestPluginManager.has_timeoutO   s     INN,,T\\:;;r   c                 f    [        [        R                  R                  U R                  5      5      $ r/   )r0   r1   r2   r3   r,   r4   s    r   	has_xdistPytestPluginManager.has_xdistS   r>   r   r
   N)r   r   r   r   r   r$   str__annotations__r&   r(   r*   r,   	functoolscached_propertyr0   r6   r9   r<   r@   rC   r   r
   r   r   r"   r"   ;   s    8FC%Hc%E3#GS#E3;D ; ; =d = = :4 : : <T < < :4 : :r   r"   z([1-9][0-9]*)/([1-9][0-9]*)r-   c                  P    [         R                  " [        5      R                  S   $ )z!Returns the root SymPy directory.   )pathlibPath__file__parentsr
   r   r   	sympy_dirrO   [   s     <<!))!,,r   pathskeywordsr   c           	      *  ^ U4S jnS[         S[        4S jnS n/ m[         HS  n[        R                  " [        5       U5      nUR                  5       (       d  M9  TR                  [        U5      5        MU     / nU (       a  / n	/ n
U  Hv  n[        R                  " U5      R                  5       (       a9  U	R                  [        [        R                  " [        5       U5      5      5        Me  U
R                  U5        Mx     U" U
5      nUR                  U	5        UR                  U5        OUR                  T5        Ub  US:w  a  / nU H  nU" U5      (       a  U" X5      nUR                  U5        M+  [        R                  " U5       HY  u  nnnU HL  n[        [        R                  " UU5      5      nU" U5      (       d  M2  U" UU5      nUR                  U5        MN     M[     M     UR                  U5        U$ UR                  U5        U$ )ax  Appends valid paths and flags to the args `list` passed to `pytest.main`.

The are three different types of "path" that a user may pass to the `paths`
positional arguments, all of which need to be handled slightly differently:

1. Nothing is passed
    The paths to the `testpaths` defined in `pytest.ini` need to be appended
    to the arguments list.
2. Full, valid paths are passed
    These paths need to be validated but can then be directly appended to
    the arguments list.
3. Partial paths are passed.
    The `testpaths` defined in `pytest.ini` need to be recursed and any
    matches be appended to the arguments list.

c                    > / nU  H  n[        U5      S:  a  US S S:H  nUSS  S:H  nO[        U5      S:  a  SnUSS  S:H  nOSnSnU(       a  U(       a  UR                  U5        Mb  U(       a  UR                  U S35        M  U(       a  UR                  SU 35        M  UR                  SU S35        M     / nT H  n[        R                  " US	S
9 H  u  pxn	[	        X5      n
U
 H  u  p+[        USU S35      (       a5  UR                  [        [        R                  " U5      5      5        / US S & MO  U	 HC  n[        X5      (       d  M  UR                  [        [        R                  " X|5      5      5        ME     M     M     M     U$ )N   r   .py   Fz*.pyztest*T)topdown*)	lenappendoswalkzipr   rE   rK   rL   )partial_pathspartial_path_file_patternspartial_pathhas_test_prefixhas_py_suffixmatchestestpathpathdirsfileszippedpartial_path_filefilevalid_testpaths_defaults                r   find_paths_matching_partial;update_args_with_paths.<locals>.find_paths_matching_partialw   s|   %'")L< A%".r"2f"< ,RS 1U :\"a'"' ,RS 1U :"' %=*11,? *11\N$2GH*11E,2HI*11E,t2LM# *$ /H%'WWXt%D!E]G9?5\tqa%899s7<<+='>?"$Q$)D&t?? 's7<<3K/L M %* :@ &E 0 r   filepathr-   c                     [         R                  " U 5      nUR                  5       (       d  gUR                  S   R	                  S5      (       d  gUR
                  S:X  d  gg)NFtest_rV   T)rK   rL   is_fileparts
startswithsuffix)ro   rf   s     r   is_tests_file-update_args_with_paths.<locals>.is_tests_file   sL    ||H%||~~zz"~((11{{e#r   c                    / n[         R                  " U5      R                  SS9nUR                  5        H  nUR	                  5       R                  S5      (       d  M)  U  Hu  nUR                  5       R                  UR                  5       5      S:w  d  M6  UR                  S5      S   R                  S5      S   nUS	-   U-   nUR                  U5        Mw     M     U$ )
Nzutf-8)encodingzdef rq       (r   z::)
rK   rL   	read_text
splitlineslstripru   lowerfindsplitr[   )rQ   ro   rd   sourcelinekw	test_namefull_test_paths           r   find_tests_matching_keywords<update_args_with_paths.<locals>.find_tests_matching_keywords   s    h'1171C%%'D{{}''//"Bzz|((4:$(JJsOA$6$<$<S$A!$D	)1D9)D~6	 # ( r   r
   )rE   r0   TESTPATHS_DEFAULTrK   rL   rO   existsr[   extendr\   r]   )rP   rQ   r   rm   rw   r   re   absolute_testpathcandidate_paths
full_pathsr_   rf   matched_pathsrd   test_matchesrootdirnames	filenamesfilenameabsolute_filepathrl   s                       @r   update_args_with_pathsr   a   s   , D  
 !%#LLh?##%%#**3/@+AB &
 O
D||D!((**!!#gll9;&E"FG$$T*	 
 4MBz*}-67B#DT"";HK|,13-D(I$-,/T80L,M)():;;+G ( 1,L $NN<8 %. 2? $ 	G K 	O$Kr   ra   c                     S[         S[        4S jnU" U 5      (       d  S[        U 5       S3n[        U5      e[        [        R
                  " [        5       U 5      5      nU$ )ah  Convert a partial path to an absolute path.

A path such a `sympy/core` might be needed. However, absolute paths should
be used in the arguments to pytest in all cases as it avoids errors that
arise from nonexistent paths.

This function assumes that partial_paths will be passed in such that they
begin with the explicit `sympy` directory, i.e. `sympy/...`.

ra   r-   c                 N    [         R                  " U 5      R                  S   S:H  $ )z@Assumption that partial paths are defined from the `sympy` root.r   r   )rK   rL   rt   )ra   s    r   is_valid_partial_path1make_absolute_path.<locals>.is_valid_partial_path   s!    ||L)//2g==r   zPartial path z] is invalid, partial paths are expected to be defined with the `sympy` directory as the root.)rE   r0   dir
ValueErrorrK   rL   rO   )ra   r   r   absolute_paths       r   make_absolute_pathr      si    >C >D > !..C-. /M N 	 oY[,?@Mr   T
subprocessrerunc                    UR                  SS5      (       a[  UR                  SS5        UR                  SS5        UR                  SS5        UR                  S5      c  SUS'   [        USSS	.UD6$ [        5       nUR                  (       d  [
        R                  " 5         / nUR                  S
S5      (       a  UR                  S5        UR                  S5      =n(       a  UR                  SU/5        UR                  S5      (       a  UR                  S5        UR                  SS5      (       d  UR                  SS/5        UR                  S5      =n(       a:  UR                  (       d  Sn[        U5      eUR                  S[        U5      /5        UR                  SS5      (       a#  UR                  (       a  UR                  S5        O5UR                  SS5      (       d  UR                  (       d  Sn[        U5      eUR                  SS5      =n	(       aC  UR                  (       d  Sn[        U5      eUR                  S[        [        U	5      5      /5        UR                  SS5      (       a  UR                  SS/5        OUR                  SS/5        UR                  S5      =n
b  UR                  (       d  S n[        U5      e[        R!                  U
5      nU(       d  S!n[#        U5      e[%        [        UR'                  5       5      u  pUR                  S"US#U/5        X:  a  S$U S%U S&3n[#        U5      eUR                  S'[(        5      =n(       a%  U H  nUR                  S([+        U5      /5        M!     UR                  SS5      (       a1  UR,                  (       d  S)n[        U5      eUR                  S*S+/5        UR                  SS5      (       a/  UR                  (       d  S,n[        U5      eUR                  S-5        UR                  S.5      =nb  [/        S/ U 5       5      nOS0n[1        UUU5      n[
        R                  " U5      nU$ )1ac  Interface 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 `<SPLIT>/<GROUPS>` 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_runnerFparallelstore_durationsTslowNr   r   verbosez	--verbosetbz--tbpdbz--pdbcolorsz--colornoseedz9`pytest-randomly` plugin required to control random seed.z--randomly-seedsortz--randomly-dont-reorganizez:`pytest-randomly` plugin required to randomize test order.timeoutz;`pytest-timeout` plugin required to apply timeout to tests.z	--timeoutz-mzslow and not tooslowznot slow and not tooslowr   z6`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--splitszcannot have a group number z with only z splits	blacklistz--ignorez8`pytest-xdist` plugin required to run tests in parallel.z-nautoz7`pytest-split` plugin required to store test durations.z--store-durationsr   c              3   8   #    U  H  n[        U5      v   M     g 7fr/   )rE   ).0r   s     r   	<genexpr>test.<locals>.<genexpr>  s     48RR8s   r
   )getpop
test_sympyr"   r6   r   r   r[   r   r9   ModuleNotFoundErrorrE   r@   intr<   split_patternmatchr   mapgroupsBLACKLIST_DEFAULTr   rC   tupler   )r   r   rP   r   pytest_plugin_managerr   r   r   r   r   r   r   groupsplitsr   rf   rQ   	exit_codes                     r   r   r      s   p zz$e,,

:u%

$e,

%t,::f%"F6N5TEfEE/1 ++Dzz)U##K ZZrVRL!zz%G::h%%Y%&zz&!!t!$11MC%c**&D	23zz&$$9$F$F01ZZ%%.C.P.PJ!#&&**Y--w-$00OC%c**[#c'l"345 zz&%  T123T567G$$1$..JC%c**##E*+CS/!C0Yz6:;>0{6( K CS/!JJ{,=>>y>DKK%7%=>?  zz*e$$$..LC%c**T6N#zz#U++$..KC%c**'(JJt$$14844!%48DD!Ir   c                      [         e)zNInterface to run doctests via pytest compatible with SymPy's test runner.
    )NotImplementedErrorr
   r   r   doctestr     s
     r   )r   rG   importlib.utilr1   r\   rK   rer   typingr   r   r   r   ImportError	Exceptionr   sympy.testing.runtestsr   r   rL   r   r   r"   compiler   	lru_cacherO   rE   r   r   r   r
   r   r   <module>r      s1  .   	  	  ( (% 6 LLLL  
: :: 

9: -7<< - -
w9wuSz"w s)w 
#Y	wtS S 6 ! QhQ  %Q	 Q% %%s   C C$#C$