
    \hA_                    
   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rSSKrSSKrSSK	r	SSK
J
r
  SSKJr  SSKrSSKJrJr  SSKrSSK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  SSKJr  SS	KJr  SS
K J!r!  SSK"J#r#  \RH                  S:H  r%\RL                  " SS5      r'/ SQr(/ SQr) " S S\*5      r+ " S S\*5      r, " S S\*5      r-SAS jr.\.\l.        S r/\%(       a  \/\l0        S r1S r2SBS jr3\S 5       r4SS\Rj                  SS4S  jr6   SCS! jr7SSS".S# jr8SS$SSSSSSSSSSSSSSSS%.S& jr9SSS".S' jrS( r:S) r;\Rx                  " S*5      r=SDS+ jr>SS,K?J@r@  \@" S-S.5      rASSSSSSSSS\R                  " 5       S4S/ jrC " S0 S15      rD " S2 S35      rE " S4 S5\5      rF " S6 S7\5      rG/ S8QrH\H H  rIS9\I-   rJS:\I-   rK\L" \G\K\M" \\J5      5        M       " S; S<\R                  5      rO " S= S>5      rP " S? S@\P5      rQg)EaF  
This is our testing framework.

Goals:

* it should be compatible with py.test and operate very similarly
  (or identically)
* does not require any external dependencies
* preferably all the functionality should be in this file only
* no magic, just import the test file and execute the test functions, that's it
* portable

    N)fnmatch)default_timer)DocTestFinderDocTestRunner)contextmanager)unwrap)Path)clear_cache)import_module)GROUND_TYPESntCI)d0*x?g_vOf?g_Q{?/nR?a2U0*C?gw?UN@s?gHPsr?Mbp?gp_Q?g_Q[?_Le?r   -C6j?-C6Z?~jtX?-C6:?r   r   ǺV?g 	??߾?gJY8?g_vO~?g"uq?gS!uq{?g0*?r   g ~:p?gZӼ?ggj+?a2U0*3?r   r   r   _LU?r   -C6J?ǺF?r   gPkw?r   r   爅ZӼt?Mb`?r   Mb@?g䃞ͪϕ?ga2U0*s?r   a2U0*S?r   a2U0*c?r   r   r!   r   gI+?ga+ey?r   gJ4a?nt?r   r   r   r   gŏ1w-!_?~jth?g/nr?g_vOv?+eXw?r$   r   r   gH}M?r   r"   r   g2%䃎?g]K=?gŏ1w-!?g	^)p?r#   gS㥋?gǘ?gׁsF?g9m4?gw-!l?gHP?r   r    r   r   gqo?r#   r!   r   r%   gy&1?r   )(g"u?r   gZӼ?r   r   r!   r   r   r   gǘ?gׁsF?g r?gJ+?r!   g-C6z?r   r   r   r   r   gy):?r#   gF%uk?r&   r!   r   gMbP?g;Onr?g&S?r   r!   g8gDio?r   g}?5^I?gS?gW/'?r   r   r   g_)Ǻ?c                       \ rS rSrSrg)SkippedX    N__name__
__module____qualname____firstlineno____static_attributes__r*       N/var/www/auris/envauris/lib/python3.13/site-packages/sympy/testing/runtests.pyr(   r(   X       r1   r(   c                       \ rS rSrSrg)TimeOutError[   r*   Nr+   r*   r1   r2   r5   r5   [   r3   r1   r5   c                       \ rS rSrSrg)DependencyError^   r*   Nr+   r*   r1   r2   r8   r8   ^   r3   r1   r8   c                 8    [         R                  " SUS-  U 5      $ )z
Add the given number of space characters to the beginning of
every non-blank line in ``s``, and return the result.
If the string ``s`` is Unicode, it is encoded using the stdout
encoding and the ``backslashreplace`` error handler.
z
(?m)^(?!$) )resub)sindents     r2   _indentr@   b   s     66,s
A..r1   c                     U R                   R                  X4U R                  5      nUR                  S5      R	                  SS5      nU" U R                  X#5      U-   5        g)z'
Report that the given example failed.
raw_unicode_escapeutf8ignoreN)_checkeroutput_differenceoptionflagsencodedecode_failure_header)selfouttestexamplegotr>   s         r2   _report_failurerP   r   sT     	''d6F6FGA	%&--fh?AT+a/0r1   c                 b   / nU  H  n[         R                  R                  " UR                  S5      6 n[        R
                  S:X  a5  UR                  S5      nUS:w  a  X#S-      S:w  a  USUS-    S-   X#S-   S -   nUR                  [         R                  R                  U5      5        M     U$ )z
Converts a list of '/' separated paths into a list of
native (os.sep separated) paths and converts to lowercase
if the system is case insensitive.
/win32:   \N)	ospathjoinsplitsysplatformfindappendnormcase)lstnewlstrvposs       r2   convert_to_native_pathsre      s     FWW\\288C=)<<7"''#,CbyAg;$&HS1W,r'(|;Bbgg&&r*+  Mr1   c                  @   [         R                  R                  [        5      n [         R                  R	                  [         R                  R                  U 5      SS5      n[         R                  R                  U5      n[         R                  R                  U5      $ )zs
Returns the root SymPy directory and set the global value
indicating whether the system is case sensitive or not.
z..)rX   rY   abspath__file__rZ   dirnamenormpathr`   )	this_file	sympy_dirs     r2   get_sympy_dirrm      sb    
 )IRWW__Y7tDI  +I77I&&r1   Tc                     SSK Jn  SSKJn  SS K Js  Jn  SSKJn  SUl        U" S5      nUR                  nU (       a  SUl	        U" SS9  XV4$ )Nr   )init_printingpprint_use_unicode
stringpictTF)pretty_print)
sympy.interactive.printingro   sympy.printing.pretty.prettyrq   interactiveprintingsympy.printing.prettyrs   	NO_GLOBAL_GLOBAL_WRAP_LINE)disable_line_wrapro   rq   interactive_printingrs   use_unicode_prevwrap_line_prevs          r2   setup_pprintr      sT    8?==0 &*" *%0  11N',
$ u%++r1   c               #      #    [         R                  " 5          [         R                  " SS[        SS9  Sv   SSS5        g! , (       d  f       g= f7f)a  Context manager to make DeprecationWarning raise an error

This is to catch SymPyDeprecationWarning from library code while running
tests and doctests. It is important to use this context manager around
each individual test/doctest in case some tests modify the warning
filters.
errorz.*zsympy.*)moduleN)warningscatch_warningsfilterwarningsDeprecationWarningr*   r1   r2   raise_on_deprecatedr      s6      
	 	 	"/A)T 
#	"	"s   A A	A
AAr*   zsympy.testing.runtestsFc                 `   [        5       n[        R                  " US/[        R                  [        R                  US9nUR                  5         UR                  S:w  a  g[        R                  " S5      nU(       d1  [        [        R                  " S5      5      [        R                  S'   OU(       d  gU=(       d    0 nSU< SU < S	U < S
[        U5      < S[        U5      < S3n	 [        R                  " USSU	/US9nUR                  5         Uc  [        R                  S	 UR                  $ U[        R                  S'   UR                  $ ! [         a    UR                  5          N[f = f! Uc  [        R                  S	 OU[        R                  S'   UR                  s  s $ = f)aj  
Run a function in a Python subprocess with hash randomization enabled.

If hash randomization is not supported by the version of Python given, it
returns False.  Otherwise, it returns the exit value of the command.  The
function is passed to sys.exit(), so the return value of the function will
be the return value.

The environment variable PYTHONHASHSEED is used to seed Python's hash
randomization.  If it is set, this function will return False, because
starting a new subprocess is unnecessary in that case.  If it is not set,
one is set at random, and the tests are run.  Note that if this
environment variable is set when Python starts, hash randomization is
automatically enabled.  To force a subprocess to be created even if
PYTHONHASHSEED is set, pass ``force=True``.  This flag will not force a
subprocess in Python versions that do not support hash randomization (see
below), because those versions of Python do not support the ``-R`` flag.

``function`` should be a string name of a function that is importable from
the module ``module``, like "_test".  The default for ``module`` is
"sympy.testing.runtests".  ``function_args`` and ``function_kwargs``
should be a repr-able tuple and dict, respectively.  The default Python
command is sys.executable, which is the currently running Python command.

This function is necessary because the seed for hash randomization must be
set by the environment variable before Python starts.  Hence, in order to
use a predetermined seed for tests, we must start Python in a separate
subprocess.

Hash randomization was added in the minor Python versions 2.6.8, 2.7.3,
3.1.5, and 3.2.3, and is enabled by default in all Python versions after
and including 3.3.0.

Examples
========

>>> from sympy.testing.runtests import (
... run_in_subprocess_with_hash_randomization)
>>> # run the core tests in verbose mode
>>> run_in_subprocess_with_hash_randomization("_test",
... function_args=("core",),
... function_kwargs={'verbose': True}) # doctest: +SKIP
# Will return 0 if sys.executable supports hash randomization and tests
# pass, 1 if they fail, and False if it does not support hash
# randomization.

z-RV)stdoutstderrcwdr   FPYTHONHASHSEEDl        zimport sys; from z import z
;sys.exit(z(*z, **z))z-Rz-c)r   )rm   
subprocessPopenPIPESTDOUTcommunicate
returncoderX   getenvstrrandom	randrangeenvironreprKeyboardInterruptwait)
functionfunction_argsfunction_kwargscommandr   forcer   p	hash_seedcommandstrings
             r2   )run_in_subprocess_with_hash_randomizationr      s\   f /C 	'5)*// * 1 1s	<AMMO||q		*+I'*6+;+;E+B'C

#$%+O h$}2E?+-MgtT=AsK	 

+, || ,5BJJ'(||  	
 

+,+4BJJ'(||s$   ,)E E1.E4 0E11E4 47F-c                    SnU=(       d    0 nU=(       d    0 nU=(       d    SS0n [        U 0 UD6(       d  Sn[        5         [        U0 UD6(       d  Sn[        5         [        R                  R                  S5        SSKJn  U" U0 UD6(       d  SnU(       a  g[        R                  " S5        g! [         a.    [        5         [        S	5        [        R                  " S5         gf = f)
aR  
Run all tests.

Right now, this runs the regular tests (bin/test), the doctests
(bin/doctest), and the examples (examples/all.py).

This is what ``setup.py test`` uses.

You can pass arguments and keyword arguments to the test functions that
support them (for now, test,  doctest, and the examples). See the
docstrings of those functions for a description of the available options.

For example, to run the solvers tests with colors turned off:

>>> from sympy.testing.runtests import run_all_tests
>>> run_all_tests(test_args=("solvers",),
... test_kwargs={"colors:False"}) # doctest: +SKIP

TquietFexamplesr   )run_examplesNrV   DO *NOT* COMMIT!)
rM   printdoctestr\   rY   r_   allr   exitr   )	test_argstest_kwargsdoctest_argsdoctest_kwargsexamples_argsexamples_kwargstests_successfulr   s           r2   run_all_testsr     s    , #K#)rN%8'4OY.+.  % 	77$ 	
#$]>o>$ HHQK  !s   A3B2 B2 25C*)C*)r   rerunc                 H  ^ U4S jnU (       aN  [        TSS5       H=  nU" U5        [        SX#S9nUSL a    O%[        U5      (       + nU(       a  US:X  d  M;  Us  $    [        TSS5       H5  nU" U5        [        [        U0 UD65      (       + nU(       a  US:X  d  M3  Us  $    g)aq  
Run tests in the specified test_*.py files.

Tests in a particular test_*.py file are run if any of the given strings
in ``paths`` matches a part of the test file's path. If ``paths=[]``,
tests in all test_*.py files are run.

Notes:

- If sort=False, tests are run in random order (not default).
- Paths can be entered in native system format or in unix,
  forward-slash format.
- Files that are on the blacklist can be tested by providing
  their path; they are only excluded if no paths are given.

**Explanation of test results**

======  ===============================================================
Output  Meaning
======  ===============================================================
.       passed
F       failed
X       XPassed (expected to fail but passed)
f       XFAILed (expected to fail and indeed failed)
s       skipped
w       slow
T       timeout (e.g., when ``--timeout`` is used)
K       KeyboardInterrupt (when running the slow tests with ``--slow``,
        you can interrupt one of them without killing the test runner)
======  ===============================================================


Colors have no additional meaning and are used just to facilitate
interpreting the output.

Examples
========

>>> import sympy

Run all tests:

>>> sympy.test()    # 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 with verbose mode on:

>>> sympy.test(verbose=True)    # doctest: +SKIP

Do not sort the test output:

>>> sympy.test(sort=False)    # doctest: +SKIP

Turn on post-mortem pdb:

>>> sympy.test(pdb=True)    # doctest: +SKIP

Turn off colors:

>>> sympy.test(colors=False)    # doctest: +SKIP

Force colors, even when the output is not to a terminal (this is useful,
e.g., if you are piping to ``less -r`` and you still want colors)

>>> sympy.test(force_colors=False)    # doctest: +SKIP

The traceback verboseness can be set to "short" or "no" (default is
"short")

>>> sympy.test(tb='no')    # doctest: +SKIP

The ``split`` option can be passed to split the test run into parts. The
split currently only splits the test files, though this may change in the
future. ``split`` should be a string of the form 'a/b', which will run
part ``a`` of ``b``. For instance, to run the first half of the test suite:

>>> sympy.test(split='1/2')  # doctest: +SKIP

The ``time_balance`` option can be passed in conjunction with ``split``.
If ``time_balance=True`` (the default for ``sympy.test``), SymPy will attempt
to split the tests such that each split takes equal time.  This heuristic
for balancing is based on pre-recorded test data.

>>> sympy.test(split='1/2', time_balance=True)  # doctest: +SKIP

You can disable running the tests in a separate subprocess using
``subprocess=False``.  This is done to support seeding hash randomization,
which is enabled by default in the Python versions where it is supported.
If subprocess=False, hash randomization is enabled/disabled according to
whether it has been enabled or not in the calling Python process.
However, even if it is enabled, the seed cannot be printed unless it is
called from a new Python process.

Hash randomization was added in the minor Python versions 2.6.8, 2.7.3,
3.1.5, and 3.2.3, and is enabled by default in all Python versions after
and including 3.3.0.

If hash randomization is not supported ``subprocess=False`` is used
automatically.

>>> sympy.test(subprocess=False)     # doctest: +SKIP

To set the hash randomization seed, set the environment variable
``PYTHONHASHSEED`` before running the tests.  This can be done from within
Python using

>>> import os
>>> os.environ['PYTHONHASHSEED'] = '42' # doctest: +SKIP

Or from the command line using

$ PYTHONHASHSEED=42 ./bin/test

If the seed is not set, a random seed will be chosen.

Note that to reproduce the same hash values, you must use both the same seed
as well as the same architecture (32-bit vs. 64-bit).

c                 >   > TU -
  (       a  [        STU -
  -  5      $ S $ Nzrerun %dr   ir   s    r2   <lambda>test.<locals>.<lambda>  *    #(7 !&jE!G&< = !504!5r1   rU   _testr   r   Fr   N)ranger   boolr   r   r   pathskwargsprint_counterr   retvals    `      r2   rM   rM   X  s    ^6M ub"%A!;G&+ECe|3i-C!q&
 & 5"b!aue.v.//a1fJ	 "r1   short)verbosetbkwpdbcolorsforce_colorssortseedtimeoutfail_on_timeoutslowenhance_assertsr[   time_balance	blacklistfast_thresholdslow_thresholdc           
        ^ U=(       d    Sn[        U[        5      (       a  U4nUnUc  [        R                  " S5      n[        (       a	  USL a  SnSn	[        (       a  [        U5      S/-   n[        U5      n[        XUX\S9n/ nU H5  nS	U;   a  UR                  S	S
5      u  nnUU4-  nUR                  U5        M7     Un[        UUUUUUS9nUR                  S5      nU V^s/ s H!  m[        U4S jU 5       5      (       a  M  TPM#     nn[        U5      S:X  a  UnOi[        U5      n/ nU HV  m[        R                  R!                  T5      nU H.  nUT;   d  [#        UU5      (       d  M  UR                  T5          MT     MX     SnU(       a  U
(       a  [$        nO[&        nU(       a  [)        UUUS9nUR*                  R-                  U5        [/        UR1                  XhU
XS9(       + 5      $ s  snf )z
Internal function that actually runs the tests.

All keyword arguments from ``test()`` are passed to this function except for
``subprocess``.

Returns 0 if tests passed and 1 if they failed.  See the docstring of
``test()`` for more information.
r*   Ni FiS  Tzsympy/plotting/pygletplot/tests)r   r   r   r   r[   ::rV   )r   r   sympyc              3   ,   >#    U  H	  oT;   v   M     g 7fNr*   .0bfs     r2   	<genexpr>_test.<locals>.<genexpr>.       !<)Qq&)   r   )density)r   r   r   r   r   )
isinstancer   r   r   ON_CIlistre   PyTestReporterr[   r_   
SymPyTestsget_test_filesanylenrX   rY   basenamer   SPLIT_DENSITY_SLOWSPLIT_DENSITY
split_list
_testfilesextendintrM   )r   r   r   r   r   r   r   r   r   r   r   r   r[   r   r   r   r   r   post_mortemr_pathsrY   _kwt
test_filesr   not_blacklistedmatchedr   r   r   s                            `     r2   r   r     s    
rB"cUK|	*uE!uO'H&II	'	2Iwf!	0A F4<

4+ID#3&LBd	 
 E1b+t"0"0	2A !!'*J", >*Q!!<)!<< *O > 5zQ!'. Aww''*H6WXq11NN1%  ! G(G#GWeW=LL 166t4'  J J K K7>s   'G5	G5c                 H  ^ U4S jnU (       aN  [        TSS5       H=  nU" U5        [        SX#S9nUSL a    O%[        U5      (       + nU(       a  US:X  d  M;  Us  $    [        TSS5       H5  nU" U5        [        [        U0 UD65      (       + nU(       a  US:X  d  M3  Us  $    g)a.  
Runs doctests in all \*.py files in the SymPy directory which match
any of the given strings in ``paths`` or all tests if paths=[].

Notes:

- Paths can be entered in native system format or in unix,
  forward-slash format.
- Files that are on the blacklist can be tested by providing
  their path; they are only excluded if no paths are given.

Examples
========

>>> import sympy

Run all tests:

>>> sympy.doctest() # doctest: +SKIP

Run one file:

>>> sympy.doctest("sympy/core/basic.py") # doctest: +SKIP
>>> sympy.doctest("polynomial.rst") # doctest: +SKIP

Run all tests in sympy/functions/ and some particular file:

>>> sympy.doctest("/functions", "basic.py") # doctest: +SKIP

Run any file having polynomial in its name, doc/src/modules/polynomial.rst,
sympy/functions/special/polynomials.py, and sympy/polys/polynomial.py:

>>> sympy.doctest("polynomial") # doctest: +SKIP

The ``split`` option can be passed to split the test run into parts. The
split currently only splits the test files, though this may change in the
future. ``split`` should be a string of the form 'a/b', which will run
part ``a`` of ``b``. Note that the regular doctests and the Sphinx
doctests are split independently. For instance, to run the first half of
the test suite:

>>> sympy.doctest(split='1/2')  # doctest: +SKIP

The ``subprocess`` and ``verbose`` options are the same as with the function
``test()`` (see the docstring of that function for more information) except
that ``verbose`` may also be set equal to ``2`` in order to print
individual doctest lines, as they are being tested.
c                 >   > TU -
  (       a  [        STU -
  -  5      $ S $ r   r   r   s    r2   r   doctest.<locals>.<lambda>~  r   r1   rU   _doctestr   Fr   N)r   r   r   r  r   s    `      r2   r   r   L  s    d6M ub"%A!;J&+ECe|3i-C!q&
 & 5"b!ax1&122a1fJ	 "r1   c                     / n U R                  / SQ5        Sn[        SUS-   5       H#  nU R                  S[        U5      -   S-   5        M%     U R                  / SQ5        [	        S5      c  U R                  / S	Q5        O5[	        S
5      c  U R                  SS/5        OSSKnUR                  S5        [        (       d  [	        S5      c  U R                  S/5        [	        S5      c  U R                  SS/5        [	        S5      c  U R                  S/5        [	        S5      c  U R                  S/5        [	        S5      c  U R                  SS/5        [	        S5      c  U R                  S/5        [	        S5      c  U R                  SS/5        [	        S5      c  U R                  SS/5        U R                  / SQ5        U R                  S/5        U R                  / S Q5        [        U 5      n U $ )!z*Get the default blacklist for the doctests)zdoc/src/modules/plotting.rstz4doc/src/modules/physics/mechanics/autolev_parser.rstzsympy/codegen/array_utils.pyzsympy/core/compatibility.pyzsympy/core/trace.pyzsympy/galgebra.pyz,sympy/parsing/autolev/_antlr/autolevlexer.pyz/sympy/parsing/autolev/_antlr/autolevlistener.pyz-sympy/parsing/autolev/_antlr/autolevparser.pyz(sympy/parsing/latex/_antlr/latexlexer.pyz)sympy/parsing/latex/_antlr/latexparser.pyz%sympy/plotting/pygletplot/__init__.pyz!sympy/plotting/pygletplot/plot.pyzsympy/printing/ccode.pyzsympy/printing/cxxcode.pyzsympy/printing/fcode.pyzsympy/testing/randtest.pyzsympy/this.py   rV   z,sympy/parsing/autolev/test-examples/ruletestz.py)zKsympy/parsing/autolev/test-examples/pydy-example-repo/mass_spring_damper.pyzGsympy/parsing/autolev/test-examples/pydy-example-repo/chaos_pendulum.pyzHsympy/parsing/autolev/test-examples/pydy-example-repo/double_pendulum.pyzIsympy/parsing/autolev/test-examples/pydy-example-repo/non_min_pendulum.pynumpyN)z'sympy/plotting/experimental_lambdify.pyzsympy/plotting/plot_implicit.py)examples/advanced/autowrap_integrators.py&examples/advanced/autowrap_ufuncify.pyzexamples/intermediate/sample.py examples/intermediate/mplot2d.py examples/intermediate/mplot3d.py'doc/src/modules/numeric-computation.rstz%doc/src/explanation/best-practices.mdzFdoc/src/tutorials/physics/biomechanics/biomechanical-model-example.rstz7doc/src/tutorials/physics/biomechanics/biomechanics.rst
matplotlibr	  r
  r   Aggpygletzsympy/plotting/pygletplotaesarazsympy/printing/aesaracode.pyr  cupyjaxantlr4z!sympy/parsing/autolev/__init__.pyz)sympy/parsing/latex/_parse_latex_antlr.pylfortranzsympy/parsing/sym_expr.pyscipyz+doc/src/guides/solving/solve-numerically.mdz#doc/src/guides/solving/solve-ode.md)zsympy/utilities/autowrap.pyr  r  zsympy/conftest.py)zsympy/utilities/tmpfiles.pyzsympy/utilities/pytest.pyzsympy/utilities/runtests.pyz"sympy/utilities/quality_unicode.pyzsympy/utilities/randtest.py)	r   r   r_   r   r   r  user   re   )r   numr   r  s       r2   _get_doctest_blacklistr    s4   I  * CAs1uG#a&PSXXY  c d
 W% 
 	 &.22  NN5!uh'/567X&*5
 	
 V$5
 	 U#5
 	 X&/7
 	
 Z ('
 	 W%91
 	
 W%5=
 	  
   
    (	2Ir1   c                  
  ^ SSK Jn  SSKJn  UR	                  SS5      nUR	                  SS5      nUR	                  SS5      nUR	                  S	S5      nUR	                  S
/ 5      nUR	                  SS5      n	UR                  [        5       5        [        S5      b  SSKn
U
R                  S5        SSK
nSUR                  R                  l        SUR                  R                  l        SSKJn  U" 5         [#        XYUUS9n[%        X5      nUR'                  S5      nUR                  UR'                  SSS95        U V^s/ s H!  m[)        U4S jU 5       5      (       a  M  TPM#     nn[+        U 5      S:X  a  UnOi[-        U 5      n / nU HV  m[.        R0                  R3                  T5      nU  H.  nUT;   d  [5        UU5      (       d  M  UR7                  T5          MT     MX     UR9                  5         U	(       a  [;        UU	5      nUR<                  R                  U5        UR<                  (       a  UR?                  5       (       + nOSnUR'                  SSSS9nUR'                  SSSS9nUU-   nUR9                  5         U V^s/ s H!  m[)        U4S jU 5       5      (       a  M  TPM#     nn[+        U 5      S:X  a  UnO^/ nU HV  m[.        R0                  R3                  T5      nU  H.  nUT;   d  [5        UU5      (       d  M  UR7                  T5          MT     MX     U	(       a  [;        UU	5      nSnU GH  n[.        R0                  RA                  U5      (       d  M*  [B        RD                  n [G        5       u  nn[I        USS[J        RL                  [J        RN                  -  [J        RP                  -  S9nU[B        l"        SSK)J*s  J+n  SUl,        U" U5        UUl-        Uu  nn U (       d  M  U=(       d    UnU(       a@  SnSn!UR<                  (       d  UR]                  U!S9  OUR_                  U!5        [a        5         UURc                  S5      [+        S5      -   S-   S n"[a        U"SS9  URd                  [+        U"5      -
  S-
  n#S U -  n$S U=(       d    S!-  n%[a        S"Rg                  U$SU#[+        U$5      -
  [+        U%5      -
  -  U%/5      5        GM     U(       d  U(       a  [a        5         [a        S#5        [i        U5      $ s  snf s  snf ! U[B        l"        SSK)J*s  J+n  SUl,        U" W5        WUl-        f = f)$a  
Internal function that actually runs the doctests.

All keyword arguments from ``doctest()`` are passed to this function
except for ``subprocess``.

Returns 0 if tests passed and 1 if they failed.  See the docstrings of
``doctest()`` and ``test()`` for more information.
r   rp   rr   normalFr   r   Tr   r   r[   Nr  r  )
unset_show)r[   r   r   r   r   )	init_onlyc              3   ,   >#    U  H	  oT;   v   M     g 7fr   r*   r   s     r2   r   _doctest.<locals>.<genexpr>A  r   r   zdoc/srcz*.rstz*.mdc              3   ,   >#    U  H	  oT;   v   M     g 7fr   r*   r   s     r2   r   r  k  r   r   utf-8)module_relativeencodingrG   zrst/md doctests start)msgrV   r;   )endz[%s]OK r   )5rv   rq   ry   rs   getr   r  r   r  r  sympy.externalexternalimporttoolsWARN_OLD_VERSIONWARN_NOT_INSTALLEDsympy.plotting.plotr  r   SymPyDocTestsr   r   r   re   rX   rY   r   r   r_   r   r   r   rM   isfiler\   displayhookr   sympytestfilepdoctestELLIPSISNORMALIZE_WHITESPACEIGNORE_EXCEPTION_DETAILru   rw   rx   rz   r{   startwrite_centerr   r^   terminal_widthrZ   r   )&r   r   rq   rs   r  r   r   r   r   r[   r  r   r  r   r   r   r   r   r   r   r   failedtest_files_rsttest_files_mdfirst_reportrst_fileold_displayhookr~   r   rL   r}   	rstfailedtestedr"  file_idwid	test_filereports&                   `                     r2   r  r    s    @0ZZ%(FjjE*GZZ$'F::ne4L

;+IZZ&E+-. \".u 27ENN/49ENN1 /LwF$0	2Aa A!!'*Ja&&zU&CD", >*Q!!<)!<< *O >
5zQ! (. Aww''*H6WXq11NN1%  ! LLNWe,LL  	||VVX %%iE%JN$$Y%$HM-/JOO", >*Q!!<)!<< *O > 5zQ!  Aww''*H6WXq11NN1%  ! We,Lww~~h''//	:/;~,n%'$--0M0MM0012C .CO FE-2 */0+9J(	66(&F$-||GGG$NN3'Gx}}W5GDqHIJG's#""S\1A5C&)Iy0D1F"''Cs9~!5F!CDfMO O \ F !v;e>T>F .CO FE-2 */0+9J(s%   T(TT0T:A	T,U	z([0-9]+)/([1-9][0-9]*)c                   ^ [         R                  U5      nU(       d  [        S5      e[        [        UR                  5       5      u  pET(       d%  XS-
  [        U 5      -  U-  U[        U 5      -  U-   $ [        T5      nT Vs/ s H  owU-  PM	     snmU4S jnU" US-
  U-  5      n	U" XE-  5      n
U [	        U	[        U 5      -  5      [	        U
[        U 5      -  5       $ s  snf )aE  
Splits a list into part a of b

split should be a string of the form 'a/b'. For instance, '1/3' would give
the split one of three.

If the length of the list is not divisible by the number of splits, the
last split will have more items.

`density` may be specified as a list.  If specified,
tests will be balanced so that each split has as equal-as-possible
amount of mass according to `density`.

>>> from sympy.testing.runtests import split_list
>>> a = list(range(10))
>>> split_list(a, '1/3')
[0, 1, 2]
>>> split_list(a, '2/3')
[3, 4, 5]
>>> split_list(a, '3/3')
[6, 7, 8, 9]
z=split must be a string of the form a/b where a and b are intsrV   c                    > U S::  a  gU [        T5      :  a  gSn[        T5       H  u  p#X-  nX:  d  M    O   WX-
  -
  U-  nWU-   [        T5      -  $ )zPInterpolate the inverse to the cumulative
distribution function given by densityr   rV   )sum	enumerater   )xcummr   dfracr   s        r2   density_invsplit_list.<locals>.density_inv  sj     6G g&DAIDy ' TX!#DCL((r1   )spmatch
ValueErrormapr   groupsr   rF  )lr[   r   mr   r   totrH  rL  
lower_frachigher_fracs     `        r2   r   r     s    . 	AXYYsAHHJDAa%Q"Qs1vXq[11 g,C '(13w(G)$ a!eq[)Jae$KSCF"#c+c!f*<&=>>- )s   C")
namedtupleSymPyTestResultszfailed attemptedc                    U(       a  U(       d  [        S5      e[        R                  " XX5      u  pUc  [        R                  R                  U 5      nUc  0 nOUR                  5       nUb  UR                  U5        SU;  a  SUS'   U	(       a  [        R                  " XWS9nO[        XWS9n[        5       Ul        U
R                  XX S5      nUR                  U5        U(       a  UR                  5         [        R                  c  U[        l        O[        R                  R!                  U5        [#        UR$                  UR&                  5      $ )a  
Test examples in the given file.  Return (#failures, #tests).

Optional keyword arg ``module_relative`` specifies how filenames
should be interpreted:

- If ``module_relative`` is True (the default), then ``filename``
  specifies a module-relative path.  By default, this path is
  relative to the calling module's directory; but if the
  ``package`` argument is specified, then it is relative to that
  package.  To ensure os-independence, ``filename`` should use
  "/" characters to separate path segments, and should not
  be an absolute path (i.e., it may not begin with "/").

- If ``module_relative`` is False, then ``filename`` specifies an
  os-specific path.  The path may be absolute or relative (to
  the current working directory).

Optional keyword arg ``name`` gives the name of the test; by default
use the file's basename.

Optional keyword argument ``package`` is a Python package or the
name of a Python package whose directory should be used as the
base directory for a module relative filename.  If no package is
specified, then the calling module's directory is used as the base
directory for module relative filenames.  It is an error to
specify ``package`` if ``module_relative`` is False.

Optional keyword arg ``globs`` gives a dict to be used as the globals
when executing examples; by default, use {}.  A copy of this dict
is actually used for each docstring, so that each docstring's
examples start with a clean slate.

Optional keyword arg ``extraglobs`` gives a dictionary that should be
merged into the globals that are used to execute examples.  By
default, no extra globals are used.

Optional keyword arg ``verbose`` prints lots of stuff if true, prints
only failures if false; by default, it's true iff "-v" is in sys.argv.

Optional keyword arg ``report`` prints a summary at the end when true,
else prints nothing at the end.  In verbose mode, the summary is
detailed, else very brief (in fact, empty if all tests passed).

Optional keyword arg ``optionflags`` or's together module constants,
and defaults to 0.  Possible values (see the docs for details):

- DONT_ACCEPT_TRUE_FOR_1
- DONT_ACCEPT_BLANKLINE
- NORMALIZE_WHITESPACE
- ELLIPSIS
- SKIP
- IGNORE_EXCEPTION_DETAIL
- REPORT_UDIFF
- REPORT_CDIFF
- REPORT_NDIFF
- REPORT_ONLY_FIRST_FAILURE

Optional keyword arg ``raise_on_error`` raises an exception on the
first unexpected exception or failure. This allows failures to be
post-mortem debugged.

Optional keyword arg ``parser`` specifies a DocTestParser (or
subclass) that should be used to extract tests from the files.

Optional keyword arg ``encoding`` specifies an encoding that should
be used to convert the file to unicode.

Advanced tomfoolery:  testmod runs methods of a local instance of
class doctest.Tester, then merges the results into (or creates)
global Tester instance doctest.master.  Methods of doctest.master
can be called directly too, if you want to do something unusual.
Passing report=0 to testmod is especially useful then, to delay
displaying a summary.  Invoke doctest.master.summarize(verbose)
when you're done fiddling.
z8Package may only be specified for module-relative paths.r,   __main__r   rG   r   )rP  r1  _load_testfilerX   rY   r   copyupdateDebugRunnerSymPyDocTestRunnerSymPyOutputCheckerrE   get_doctestrun	summarizemastermergerY  failurestries)filenamer   namepackageglobsr   rC  rG   
extraglobsraise_on_errorparserr!  textrunnerrM   s                  r2   r0  r0    s   b  + , 	, ,,?6ND |ww) }

Z &j%%gO#GM,. d41=D
JJt f%FOOV\\::r1   c                   Z    \ rS rSr  SS jr  SS jrS r  SS jrS rS r	SS	 jr
S
rg)r   in  Nc                 f   X0l         X l        SU l        [        5       U l        Xl        U R
                  R                  U R                  5        / U l        Ub  UO[        R                  " 5       U l	        U(       a  [        U5      U l        OSU l        U(       a  [        U5      U l        g SU l        g )Nr      
   )_post_mortemr   _countrm   	_root_dir	_reporterroot_dirr   r   _seedfloat_fast_threshold_slow_threshold)rK   reporterr   r   r   r   r   s          r2   __init__SymPyTests.__init__p  s    '&!/!-T6==?
 #(#8D #$D #(#8D #%D r1   c           	      
   U(       a  U R                   R                  5         OHU(       a  O@[        R                  " U R                  5        [        R
                  " U R                   5        U R                  R                  U R                  5        U R                    H  n U R                  XaX#XE5        M     U R                  R                  5       $ ! [         a'    [        S5        U R                  R                  5         e f = f)zm
Runs the tests returning True if all tests pass, otherwise False.

If sort=False run tests in random order.
 interrupted by user)r   r   r   r   r|  shufflerz  r5  rB  r   r   finish)rK   r   r   r   r   r   r   s          r2   rM   SymPyTests.test  s     OO  "KK

#NN4??+TZZ(Aq#6 ! ~~$$&&	 % ,-%%'s    C1Dc                    ^^	^
^^^^^^^^ SSK JnJmJmJmJmJmJm	Jm
J	mJ
mJmJnJn  SSSSSSS	S
SSS.
m " UU	U
UUUUUUUU4S jSU5      nU" U5      nU" 5       R                  U5      nU" U5      $ )Nr   )NodeTransformerCompareNameStoreLoadTupleAssignBinOpStrModAssertparsefix_missing_locationsz==z!=<z<=>z>=iszis notinznot in)
EqNotEqLtLtEGtGtEIsIsNotInNotInc                   6   > \ rS rSrU UUUUUUUUU	U
4S jrSrg).SymPyTests._enhance_asserts.<locals>.Transformi  c           	        > [        UR                  T5      (       GaO  UR                  nUR                  /UR                  -   n[	        U5       VVs/ s H
  u  pESU-  PM     nnnU Vs/ s H  nT" UT" 5       5      PM     nnU Vs/ s H  nT" UT" 5       5      PM     n	nT" UT" 5       5      n
T" UT" 5       5      nT" U
/U5      nT" U	S   UR
                  U	SS  5      nSSR                  UR
                   Vs/ s H  nTUR                  R                     PM     sn5      -   S-   nT" T" U5      T" 5       T" U	T" 5       5      5      nT" UUUR                  UR                  S9nUU/$ U$ s  snnf s  snf s  snf s  snf )Nz_%sr   rV   z
%s z
%s)lineno
col_offset)r   rM   leftcomparatorsrG  opsrZ   	__class__r,   r  r  )rK   stmtcomparevaluesr   _namesnnames_store
names_loadtargetvalueassignnew_compareop
msg_formatr"  rM   r  r  r  r  r  r  r  r  r  r  r  s                     r2   visit_Assert;SymPyTests._enhance_asserts.<locals>.Transform.visit_Assert  so   dii11"iiG%ll^g.A.AAF4=f4EG4EDAeai4EEG>C"EeDEG$4eK"E<A!CEq446?EJ!C";8F!&$&1E#VHe4F")*Q-jQRQSn"UK!(7<<_f_j_j8l_jY[#bll>S>S:T_j8l+m!mpv!vJJj$&8QRC!+s4;;SWSbSbcD"D>)K H"E!C
 9ms   E/*E5E:<#E?
r*   N)r,   r-   r.   r/   r  r0   )r  r  r  r  r  r  r  r  r  r  r  s   r2   	Transformr    s         r1   r  )astr  r  r  r  r  r  r  r  r  r  r  r  r  visit)rK   sourcer  r  r  r  treenew_treer  r  r  r  r  r  r  r  r  r  r  s           @@@@@@@@@@@r2   _enhance_assertsSymPyTests._enhance_asserts  sz    	K 	K 	K 	K DD$dXX/	  	  	  	 & V};$$T*$X..r1   c                   ^^^^ U R                   n/ n ST0n	 U4S jn
U
" 5        nUR                  5       nU R                  (       am  UR                  5        HO  mTR	                  5       R                  S5      (       d  M)  [        U4S jU R                   5       5      (       d  MO    O    S S S 5        g S S S 5        U(       a   U R                  W5      n[        WTSSSS9n[        X5        [%        5         U =R&                  S	-  sl        [(        R*                  " U R,                  5        U	R/                  S
S5      nU(       Gd  / nU	 H  nUR                  S5      (       d  M  [0        R2                  " X   5      (       d  [0        R4                  " X   5      (       d  MW  X   m[7        TS5      (       a  TR8                  m[7        TS5      (       a  M  [0        R:                  " T5      T:X  d  M  UR=                  X   5        M     U(       a&  U Vs/ s H  n[?        USS5      (       d  M  UPM     nnURA                  S S9  SnU[C        U5      :  a{  [0        RD                  " X   5      (       aH  URG                  U5      nU" 5        H+  nUS   mUS	S  mUU4S jnURI                  UU5        US	-  nM-     OUS	-  nU[C        U5      :  a  M{  U Vs/ s H  nU RK                  U5      (       d  M  UPM     nnU(       d  g  URM                  T[C        U5      5        U(       d  [(        RN                  " U5        U GH  n[P        RP                  " 5       nURS                  U5         [?        USS5      (       a  U(       d  [U        S5      e[W        5          U(       a  U RY                  XU5        O'[(        R*                  " U R,                  5        U" 5         S S S 5        UR[                  5         [P        RP                  " 5       U-
  nUU Rr                  :  aW  [t        Rv                  Ry                  TURz                  5      mUR|                  R=                  TS-   URl                  -   U45        [?        USS5      (       d  GMG  U(       d  GMQ  UU R~                  :  d  GMd  [t        Rv                  Ry                  TURz                  5      mUR                  R=                  TS-   URl                  -   U45        GM     UR                  5         g ! , (       d  f       GNb= f! [         a     GNYf = f! [        [        4 a    e [         a(    UR                  T[        R                  " 5       5         g [          a(    UR#                  [        R                  " 5       5         GNf = fs  snf s  snf ! [          a    URM                  T[C        U5      5        e f = f! , (       d  f       GN	= f! [         a(    [?        USS5      (       a  UR]                  S5         GN,e [          Ga'    U(       a  [^        R`                  " S5        [        R                  " 5       u  nnnU[b        L a>  URe                  UUU45        U Rf                  (       a  [h        Rj                  " U5         GNURl                  S:X  a  UR]                  U5         GNURl                  S:X  a  URo                  5          GNURl                  S:X  a  URq                  U5         GNUR#                  UUU45        U Rf                  (       a  [h        Rj                  " U5         GN]f = f)Nrh   c                     > [        T SS9$ )NrC   )r!  )open)rj  s   r2   r   &SymPyTests.test_file.<locals>.<lambda>  s    DF$Cr1   zdef c              3      >#    U  H5  nTR                  5       R                  UR                  5       5      S :g  v   M7     g7f)rU   N)lowerr^   )r   krS  s     r2   r   'SymPyTests.test_file.<locals>.<genexpr>  s-     &YPX1qwwy~~aggi'@B'FPXs   =A execr   T)flagsdont_inheritrV   disabledFtest___wrapped___slowc                 4    [         R                  " U 5      S   $ NrV   )inspectgetsourcelinesrH  s    r2   r   r    s    )?)?)B1)Er1   keyc                     > T" T 6 $ r   r*   )argsfuncs   r2   r   r    s	    $+r1   Slowr   r(   XFailXPassr   )Brz  readr   
splitlineslstrip
startswithr   r  ImportErrorcompiler  
SystemExitr   import_errorr\   exc_info	Exceptiontest_exceptionr
   rx  r   r   r|  r&  r  
isfunctionismethodhasattrr  getsourcefiler_   getattrr   r   isgeneratorfunctionpopinsertmatchesentering_filenamer  timeentering_testr(   r   _timeout	test_pass	test_skipsignalalarmAssertionError	test_failrw  r   r   r,   
test_xfail
test_xpassr  rX   rY   relpathry  slow_test_functionsr~  fast_test_functionsleaving_filename)rK   rj  r   r   r   r   r   r  funcsgl	open_filer   r  coder  r   fgfgwrH  r5  r   vtrtakenr  r  rS  s    `                      @@@r2   rB  SymPyTests.test_file  s   >>K	h'B8C	[AVVXFxx!'!2!2!4A xxz44V<<#&&YPTPXPX&Y#Y#Y$) "5
 # ![[ #!%!6!6v!> vxqtTT MKK1KKK

#vvj%0H AW--73E3Ebe3L3L"++BE22!u%dM::#'#3#3D &dM:: #006(B!LL/  (-L1GU1KQEL

E
F#e*n2258<< "IIaL"##B#%a5D#%ab6D"5C!LLC0FA #& Q #e*n %*=EqT\\!_E=  	""8SZ8NN5!AIIKE""1%!%1gu--d!&/)(*a/BDJJ/ +< ""$IIK%'Et+++77??8X5G5GH,,33_qzz159;q'5))dd4///!wwx9K9KLH0077!D1::5u=?[ ^ 	!!#w ![ ' 
  12  %%h? 8''78. M$ >  	&&xU<	 +* % 1gu--&&':; ,LLO<<>1b&&&1bz2((+ZZ9,&&q)ZZ7*'')ZZ7*''*++Q2J7((+#,s  V2 T3 AT"T'T,T3 5T3 T" T3 .A4V2 &8V2 "2V2 V2 2"V2 V(.V(4BV2 V2 V-4V-:	V2 *.W.AWW.
TT3 "
T0,T3 /T00T3 3?V%2V2 4-V%!V2 $V%%V2 2'W
W+	&W..-]B]&!]
 ]-!];]]c                    ^^ UU4S jn[         R                   " [         R                  U5        [         R                  " T5        U" 5         [         R                  " S5        g )Nc                 p   > [         R                  " S5        T(       a  [        ST-  5      e[        S5      e)Nr   zTimed out after %d secondsTimeout)r  r  r5   r(   )rH  yr   r   s     r2   callback%SymPyTests._timeout.<locals>.callbackH  s-    LLO"#?'#IJJi((r1   r   )r  SIGALRMr  )rK   r   r   r   r  s     `` r2   r  SymPyTests._timeoutG  s8    	) 	fnnh/W
Qr1   c                     U R                   (       d  gU R                    H@  nUR                  R                  5       R                  UR                  5       5      S:w  d  M@    g   g)zm
Does the keyword expression self._kw match "x"? Returns True/False.

Always returns True if self._kw is "".
TrU   F)r   r,   r  r^   )rK   rH  r   s      r2   r  SymPyTests.matchesS  sJ     xx((Bzz!&&rxxz2b8  r1   c           
         [         R                  R                  U R                  [	        U/5      S   5      n/ n[         R
                  " U5       HW  u  pEnUR                  U Vs/ s H4  n[        Xr5      (       d  M  [         R                  R                  XG5      PM6     sn5        MY     [        U Vs/ s H"  n[         R                  R                  U5      PM$     sn5      $ s  snf s  snf )zs
Returns the list of test_*.py (default) files at or below directory
``dir`` relative to the SymPy home directory.
r   )
rX   rY   rZ   ry  re   walkr   r   sortedr`   )	rK   dirpatgrY   foldersfilesr   gis	            r2   r   SymPyTests.get_test_files`  s    
 ggll4>>+BC5+I!+LM$&GGCL D5HHUNUgao+bggll4+UNO %1 a8arww''+a899 O8s   %C$
=#C$
4)C))	rx  r~  r   rw  rz  ry  r|  r  r   )r%  FNNN)FFFFF)TFFFF)z	test_*.py)r,   r-   r.   r/   r  rM   r  rB  r  r  r   r0   r*   r1   r2   r   r   n  s?    49@D&2 4938'2/> BG38D$L
:r1   r   c                   D    \ rS rSrS rS rS rS	S jr     S
S jrSr	g)r-  in  c                     SU l         [        5       U l        Xl        U R                  R	                  U R                  5        X l        / U l        g )Nr   )rx  rm   ry  rz  r{  _normalr   )rK   r  r  s      r2   r  SymPyDocTests.__init__p  s9    &!/r1   c                    U R                   R                  5         U R                   H  n U R                  U5        M     U R                   R                  5       $ ! [         a'    [        S5        U R                   R                  5         e f = f)zE
Runs the tests and returns True if all tests pass, otherwise False.
r  )rz  r5  r   rB  r   r   r  rK   r   s     r2   rM   SymPyDocTests.testy  su     	Aq! ! ~~$$&&	 % ,-%%'s   A1Bc                 v	   [        5         SSKJn  SS KJs  Jn  SSKJn  SSKJ	n  U[        U R                  5      S-   S  n[        R                  R                  U5      u  pxUR                  [        R                   S5      S S n	UR#                  S5      (       a%  [$        R                  R'                  SU5        US S n	 [(        R*                  " U	5      n	[-        5       R/                  U	5      n
 UR#                  S5      (       a  [$        R                  S	 U
 Vs/ s H   n[        UR<                  5      S:  d  M  UPM"     n
nU
R?                  S	 S
9  U
(       d  g U R6                  RA                  U[        U
5      5        U
 GH  n[        UR<                  5      S:w  d   eU R6                  RB                  (       a4  U R6                  RE                  SRG                  URH                  5      5        SURJ                  ;   a    U RL                  " S0 URJ                  S   D6  [U        U R6                  RB                  S:H  [(        RV                  [(        RX                  -  [(        RZ                  -  S9n[]        5       Ul/        [$        R`                  nU R6                  RB                  S:X  a  UOU" 5       nU[$        l0        U Rb                  (       d  0 Ul%        [$        Rd                  n[g        5       u  nn URi                  UURD                  SS9u  nn U[$        l0        US:  a7  U R6                  Rk                  URH                  URm                  5       5        GM  U R6                  Ro                  5         U[$        l2        SUl8        U" U5        UUl9        GM     U R6                  Ru                  5         g ! [0        [2        4 a    e [4         aZ    U R6                  R9                  U[$        R:                  " 5       5         UR#                  S5      (       a  [$        R                  S	 g g f = f! UR#                  S5      (       a  [$        R                  S	 f f = fs  snf ! [N         a.  nU R6                  RQ                  [S        U5      S9   S nAGM  S nAff = f! [2         a    e f = f! U[$        l0        f = f)Nr   )StringIOrp   rr   rV   .r   c                     U R                   * $ r   )r  r  s    r2   r   )SymPyDocTests.test_file.<locals>.<lambda>  s
    !((r1   r  z
{} _doctest_depends_on)r     r\  F)rL   clear_globsr*   );r
   ior+  ru   rw   rx   rv   rq   ry   rs   r   ry  rX   rY   r[   replacesepr  r\   r  r1  _normalize_moduleSymPyDocTestFinderr^   r  r   r  rz  r  r  r   r   r  _verbosewriteformatrk  rm  _check_dependenciesr8   r  r   ra  r2  r3  r4  rb  rE   r   r%  r/  r   rd  doctest_failgetvaluer  rz   r{   r  )rK   rj  r+  r}   rq   rs   rel_nameri   filer   testsrM   err  oldnewr=  r~   r   r   r   s                        r2   rB  SymPyDocTests.test_file  s   AAC4C/!345h/!!"&&#.s3z** HHOOAw'#2YF
	 //7F&(--f5E "":..HHQK"'B%$3t}}+=+A%B 	

*
+((3u:>Dt}}%***~~&&$$W^^DII%>? %

2,,Qtzz:O/PQ
 (0G0G0J ( 1 111!244!56F 12FO**C00!3#CCJ <<
 "ooO/;~,n!zz$&)iiU " D1
 !
1u++DIIs||~F((*"116$."#34/=
,e h 	'')Q -. 	 	NN''#,,.A"":..HHQK /		 "":..HHQK / C* ' NN,,s1v,6: %  !
sa   /N8 Q=QQ!6R8A	P,P/ +P,,P/ /*Q!
R+"RRR((R++R8c           
      X   S n[         R                  R                  U R                  [	        U/5      S   5      n/ n[         R
                  " U5       Ho  u  pgnUR                  U V	s/ s HL  n	U	R                  S5      (       a  M  [        X5      (       d  M-  [         R                  R                  Xi5      PMN     sn	5        Mq     U(       a   U V
s/ s H  o" U
5      (       d  M  U
PM     nn
U Vs/ s H"  n[         R                  R                  U5      PM$     sn$ s  sn	f s  sn
f s  snf )z
Returns the list of \*.py files (default) from which docstrings
will be tested which are at or below directory ``dir``. By default,
only those that have an __init__.py in their parent directory
and do not start with ``test_`` will be included.
c                     [         R                  R                  [         R                  R                  U 5      S5      n[         R                  R	                  U5      $ )z
Checks if given pathname x is an importable module by checking for
__init__.py file.

Returns True/False.

Currently we only test if the __init__.py file exists in the
directory with the file "x" (in theory we should also test all the
parent dirs).
z__init__.py)rX   rY   rZ   ri   exists)rH  init_pys     r2   
importable0SymPyDocTests.get_test_files.<locals>.importable  s8     ggll277??1#5}EG77>>'**r1   r   r  )
rX   rY   rZ   ry  re   r  r   r  r   r`   )rK   r  r  r  rI  r  rY   r  r   r   rH  r!  s               r2   r   SymPyDocTests.get_test_files  s    	+ ggll4>>+BC5+I!+LM$&GGCL D5HHU HU\\'2 ,7>q ,bggll4+U H I %1 /AqAAA//01q  $q11H 01s$   (D
D
#D
D"%D"1)D'Nc           	         U H,  n[         R                  " U5      (       a  M   [        SU-  5      e   U HL  nUS:X  a%  [        SS/ SQ0S[        4S9nUc  [        S5      eM.  [        U5      (       a  M@  [        S	U-  5      e   U(       a  [
        R                  " 5       n	U	< S
[        R                  S   < 3[        R                  S'   Sn
U H  n[        [        R                  R                  X5      5      R                  U
5        [        R                  " [        R                  R                  X5      [        R                  [        R                   -  [        R"                  -  5        M     U(       a?  [$        R&                  U:  a+  [        SSR                  [)        [*        U5      5      -   5      eUb!  [,        U;  a  [        S[+        U5      -   5      eSU;   a  SSKn " S S5      nXR0                  l        gg)z
Checks if the dependencies for the test are installed.

Raises ``DependencyError`` it at least one dependency is not installed.
zCould not find %sr  fromlist)pyplotcmcollectionsz1.0.0)import_kwargsmin_module_versioncatchNzCould not import matplotlibzCould not import %srT   PATHzZ#!/usr/bin/env python3
import sys
if len(sys.argv) <= 1:
    exit("wrong number of args")
zRequires Python >= r,  zRequires ground_types in r  r   c                   2    \ rS rSrS rS rS rS rS rSr	g)	6SymPyDocTests._check_dependencies.<locals>.DummyWindowi?  c                 .    SU l         SU l        SU l        g )NTiX  i  )has_exitwidthheight)rK   r  r   s      r2   r  ?SymPyDocTests._check_dependencies.<locals>.DummyWindow.__init__@  s    $(DM!$DJ"%DKr1   c                     g r   r*   rK   rH  s     r2   	set_vsync@SymPyDocTests._check_dependencies.<locals>.DummyWindow.set_vsyncE      r1   c                     g r   r*   rK   s    r2   	switch_to@SymPyDocTests._check_dependencies.<locals>.DummyWindow.switch_toH  r`  r1   c                     g r   r*   r]  s     r2   push_handlersDSymPyDocTests._check_dependencies.<locals>.DummyWindow.push_handlersK  r`  r1   c                     g r   r*   rb  s    r2   close<SymPyDocTests._check_dependencies.<locals>.DummyWindow.closeN  r`  r1   )rX  rZ  rY  N)
r,   r-   r.   r/   r  r^  rc  rf  ri  r0   r*   r1   r2   DummyWindowrV  ?  s    &
r1   rk  )shutilwhichr8   r   RuntimeErrortempfilemkdtemprX   r   r	   rY   rZ   
write_textchmodstatS_IREADS_IWRITES_IXUSRr\   version_inforQ  r   r   r  windowWindow)rK   executablesmodulesdisable_viewerspython_versionground_types
executabler   r  tempdirvwviewerr  rk  s                 r2   r;  !SymPyDocTests._check_dependencies  s    &J<<
++%&9J&FGG & F%* #-&E#G'.|o	G

 %)*GHH & %V,,)*?&*HII  &&(G,3RZZ5G!HBJJv7B
 *RWW\\'23>>rB g65DF	 * .0%&;chhs3P^G_>`&`aa#</%&ACDU&UVVw  $ $/MM - r1   )rx  r%  rz  ry  r   )z*.pyT)r*   r*   r*   )      N)
r,   r-   r.   r/   r  rM   rB  r   r;  r0   r*   r1   r2   r-  r-  n  s0    '\*|2D )+$&,.+1)-K/r1   r-  c                   $    \ rS rSrSrS rS rSrg)r7  iT  a  
A class used to extract the DocTests that are relevant to a given
object, from its docstring and the docstrings of its contained
objects.  Doctests can currently be extracted from the following
object types: modules, functions, classes, methods, staticmethods,
classmethods, and properties.

Modified from doctest's version to look harder for code that
appears comes from a different module. For example, the @vectorize
decorator makes it look like functions come from multidimensional.py
even though their code exists elsewhere.
c           
         U R                   (       a  [        SU-  5        [        U5      U;   a  gSU[        U5      '   [        R                  " U5      (       a#  UR
                  R                  S5      S   S:w  a  gU R                  X#XFU5      nUb  UR                  U5        U R                  (       d  g[        R                  " U5      (       Ga  UR                  R                  5        H  u  p[        R                  " U
5      (       d  [        R                  " U
5      (       d  M=  U
R
                  UR                  :w  a  MY  U R                  XJ5      (       d   U
< SU< SU	< S	35       e U< SU	< 3nU R!                  XXXVU5        M     [%        US
0 5      R                  5        H  u  p['        U[(        5      (       d  [+        S[-        U5      < 35      e[        R                  " U
5      (       d~  [        R                  " U
5      (       dc  [        R.                  " U
5      (       dH  [        R                  " U
5      (       d-  ['        U
[(        5      (       d  [+        S[-        U
5      < 35      eU< SU< 3nU R!                  XXUXg5        M     [        R                  " U5      (       Ga  UR                  R                  5        GHy  u  p['        U
[0        5      (       a  [%        X+5      n
['        U
[2        5      (       a  [%        X+5      R4                  n
[        R                  " [7        U
5      5      (       d2  [        R                  " U
5      (       d  ['        U
[8        5      (       d  M  U R                  XJ5      (       d  M  ['        U
[8        5      (       aC  [;        U
R<                  S5      (       a'  U
R<                  R
                  UR                  :w  a  GM  OU
R
                  UR                  :w  a  GM3  U R                  XJ5      (       d   U
< SU< SU< S	35       eU< SU< 3nU R!                  XXUXg5        GM|     gg! ["         a    e f = f)zW
Find tests for the given object and any contained objects, and
add them to ``tests``.
zFinding tests in %sNrV   r,  r   r   z is not in module z
 (rawname )__test__z8SymPyDocTestFinder.find: __test__ keys must be strings: zcSymPyDocTestFinder.find: __test__ values must be strings, functions, methods, classes, or modules: z
.__test__.r-   z
 (valname )r8  r   idr  isclassr-   r[   	_get_testr_   _recurseismodule__dict__itemsr  r,   _from_module_findr   r  r   r   rP  typer  staticmethodclassmethod__func__r   propertyr  fget)rK   r@  objrk  r   source_linesrm  seenrM   rawnamer   valnames               r2   r  SymPyDocTestFinder._findb  si   
 =='$./ c7d?RW ??3~~##C(+w6 ~~cELL}} C   # 2 2 4%%c**gooc.B.B ~~8 ,,V99 WADfgVW9-17";

5w#/> !5& !(Z < B B D!'3//$&*7m&6 7 7  **3//7??33G3G((--1A1A#1F1F"3,,$ '+3i&2 3 3 /3G<

5w ( !E$ ??3 # 2 2 4c<00!#/Cc;//!#/88C ''s44,,"311%%f22 "#x00"388\::"xx22fooE (>>V__<$,,V99 2229 *.w7GJJu7L$,9 !5  - - s   .QQc                 V   Sn[        U[        5      (       aD  Un[        R                  " SU5      n[	        U5      S:X  d
   SU-  5       e[        US   SS 5      nO2[        USS5      nUc  Sn[        U[        5      (       d  [        U5      nU R                  (       a  U(       d  g[        U[        5      (       a  UR                  R                  c  gUcx  [        U5      n[        US	5      (       a'  UR                  b  UR                  S   R                  n	O$[        U[        5      (       a  UR                  n	OUn	U R                  X5      nUc  gUc  Sn
O%[        US
UR                   5      n
U
SS S;   a  U
SS n
[        US0 5      US'   U R"                  R%                  XtUX5      $ )z[
Return a DocTest for the given object, if it defines a docstring;
otherwise, return None.
Nzline \d+rV   z$string '%s' does not contain lineno r   r  __doc__r%  func_closurerh   )z.pycz.pyorU   r0  )r   r   r<   findallr   r   r  _exclude_emptyr  r  r  r   r  r  cell_contents_find_linenor,   _parserrc  )rK   r  rk  r   rm  r  r  	docstringr  tobjrj  s              r2   r  SymPyDocTestFinder._get_test  s     c3 Ijjd3Gw<1$ >6=>$
 AB(F  Y3I 	i--	N	 y c8$$xx' >+C sN++0@0@0L''*88C**xx&&t:F> >Hvz6??CH} 00#CR='.s4I2'N#$||''	$(0: 	:r1   r*   N)r,   r-   r.   r/   r  r  r  r0   r*   r1   r2   r7  r7  T  s    `,DF:r1   r7  c                   "    \ rS rSrSrSS jrSrg)ra  i  a  
A class used to run DocTest test cases, and accumulate statistics.
The ``run`` method is used to process a single DocTest case.  It
returns a tuple ``(f, t)``, where ``t`` is the number of test cases
tried, and ``f`` is the number of test cases that failed.

Modified from the doctest version to not reset the sys.displayhook (see
issue 5140).

See the docstring of the original DocTestRunner for more information.
Nc                 h   Xl         UR                   HX  nUR                  R                  SS5      Ul        UR                  =(       a    UR                  R                  SS5      Ul        MZ     Uc   [
        R                  " UR                  5      n[        R                  nUc  UR                  nU R                  [        l	        [        R                  n[
        R                  " U5      U l        U R                  R!                  5         U R                  R                  [        l        [
        R"                  R$                  U l        U R(                  ["        l        [+        5           U R-                  XU5      U[        l	        U[        l        U R&                  ["        l        U(       a  UR                  R/                  5         sSSS5        $ ! U[        l	        U[        l        U R&                  ["        l        U(       a  UR                  R/                  5         f f = f! , (       d  f       g= f)a  
Run the examples in ``test``, and display the results using the
writer function ``out``.

The examples are run in the namespace ``test.globs``.  If
``clear_globs`` is true (the default), then this namespace will
be cleared after the test runs, to help with garbage
collection.  If you would like to examine the namespace after
the test completes, then use ``clear_globs=False``.

``compileflags`` gives the set of flags that should be used by
the Python compiler when running the examples.  If not
specified, then it will default to the set of future-import
flags that apply to ``globs``.

The output of each example is checked using
``SymPyDocTestRunner.check_output``, and the results are
formatted by the ``SymPyDocTestRunner.report_*`` methods.
z```
r%  N)rM   r   wantr4  exc_msgr1  _extract_future_flagsrm  r\   r   r9  _fakeoutr   	set_trace_OutputRedirectingPdbdebuggerreset	linecachegetlinessave_linecache_getlines/_SymPyDocTestRunner__patched_linecache_getlinesr   _SymPyDocTestRunner__runclear)rK   rM   compileflagsrL   r2  rN   save_stdoutsave_set_traces           r2   rd  SymPyDocTestRunner.run  s   ( 	 }}G"<<//<GL%ooV'//2I2I'SU2VGO %
 #99$**ELjj;##C]]
  66{C// (0'9'9'B'B$!>>	 !"'zz$c:(
 .%)%A%A	"JJ$$& #" )
 .%)%A%A	"JJ$$&  #"s&   (H#*G;AH#AH  H##
H1)r  r  rM   )NNT)r,   r-   r.   r/   r  rd  r0   r*   r1   r2   ra  ra    s    
='r1   ra  )patched_linecache_getlinesrd  record_outcome_DocTestRunner___SymPyDocTestRunner__c                   $    \ rS rSrSrS rS rSrg)rb  if  z
Compared to the OutputChecker from the stdlib our OutputChecker class
supports numerical comparison of floats occurring in the output of the
doctest examples
c                    SnUS-   nSnUS-   nSU< SU< S3nSU< S	U< SU< S3n[         R                  " S
U< SU< S	35      U l        SU< SU< S3nSU< S	U< SU< S3n[         R                  " S
U< SU< S	35      U l        g )Nz(\d+\.\d*|\.\d+)z(\.{3})?z\s|\+|\-|\*|,z|j|e^z(?=z|$)z(?<=r  (|)r<   r  num_got_rgxnum_want_rgx)rK   
got_floatswant_floats	front_sepback_sepfbegfmidends          r2   r  SymPyOutputChecker.__init__m  s|     )
 !;.$	w&!+X6*3ZJ::4&AB!,h7*3[(KJJD''BCr1   c                    X!:X  a  gU R                   R                  U5      nU Vs/ s H  oUR                  S5      PM     nnU R                  R                  U5      nU Vs/ s H  oUR                  S5      PM     nn[	        U5      [	        U5      :w  a  g[	        U5      S:  a  / n[        Xg5       HU  u  pSU
;   a  UR                  U	5        M  UR                  U
5        [        [        U	5      [        U
5      -
  5      S:  d  MU    g   U R                   R                  SU5      nU[        U5      -  nU[        R                  -  (       d[  [        R                  " S[        R                  " [        R                  5      -  S	U5      n[        R                  " S
S	U5      nX!:X  a  gU[        R                   -  (       aD  SR#                  UR%                  5       5      nSR#                  UR%                  5       5      nX!:X  a  gU[        R&                  -  (       a  [        R(                  " X5      (       a  ggs  snf s  snf )ae  
Return True iff the actual output from an example (`got`)
matches the expected output (`want`).  These strings are
always considered to match if they are identical; but
depending on what option flags the test runner is using,
several non-exact match types are also possible.  See the
documentation for `TestRunner` for more information about
option flags.
TrV   Fr   z...gh㈵>%sz(?m)^%s\s*?$r%  z
(?m)^\s*?$r;   )r  finditergroupr  r   zipr_   absr}  r=   tupler1  DONT_ACCEPT_BLANKLINEr<   escapeBLANKLINE_MARKERr3  rZ   r[   r2  _ellipsis_match)rK   r  rO   rG   r  rO  numbers_gotnumbers_wantnw_ngnws              r2   check_outputSymPyOutputChecker.check_output  s    ;
 ""++C03:;7%{{1~7;##,,T24;<G5AG<{s<00{aCk8B;JJrNJJrNuRyr*+d2  9 ""&&uc2Cc
"C h<<<66/BIIh6O6O,PPd$D &&C0C{
 666((399;'C88DJJL)D{ ***''22 c <<s   H9!H>)r  r  N)r,   r-   r.   r/   r  r  r  r0   r*   r1   r2   rb  rb  f  s    D(Dr1   rb  c                       \ rS rSrSrSrg)Reporteri  z!
Parent class for all reporters.
r*   N)r,   r-   r.   r/   r  r0   r*   r1   r2   r  r    s     	r1   r  c                       \ rS rSrSr  SS jrS r\S 5       r  SS jr	SS jr
S	 rSS
 jrS rS rS rS rS rS rS rS rSS jrSS jrS rS rSrg)r   i  zD
Py.test like reporter. Should produce output identical to py.test.
Nc                    Xl         X l        X0l        X@l        SU l        / U l        / U l        / U l        SU l        SU l	        / U l
        S U l        SU l        XPl        SU l        S U l        / U l        / U l        SU l        SU l        g )Nr   P   r%  F)r8  	_tb_style_colors_force_colors_xfailed_xpassed_failed_failed_doctest_passed_skipped_exceptions_terminal_width_default_width_split_active_file	_active_fr  r  
_write_pos
_line_wrap)rK   r   r   r   r   r[   s         r2   r  PyTestReporter.__init__  s    )!#  $& #%  r1   c                     Xl         g r   )ry  )rK   r  s     r2   r{  PyTestReporter.root_dir  s    r1   c                 b   ^  T R                   b  T R                   $ U 4S jnU" 5       nUT l         U$ )Nc                    > [         R                  S:X  a  SSKJn Jn  U R
                  R                  S5      nU" S5      nU R
                  R                  X#5      nU(       a.  SS KnUR                  SUR                  5      u          pgph    nX-
  $ TR                  $ [        [         R                  S5      (       a/  [         R                  R                  5       (       d  TR                  $  [        R                   " SS	/[        R"                  [        R"                  S
9n	U	R%                  5       u  pU
R'                  S5      n
SnSnSnXU4 HE  n[(        R*                  " X5      nUc  M  UR-                  S5      n [/        U5      nWS:w  d  MC  Us  $    TR                  $ ! [0         a     N&f = f! [2         a     TR                  $ f = f)NrS   r   )windllcreate_string_bufferi   hhhhHhhhhhhisattysttyz-a)r   r   r  zcolumns\s+(?P<columns>\d+);z(?P<columns>\d+)\s*columns;zcolumns\s+=\s+(?P<columns>\d+);columns)r\   r]   ctypesr  r  kernel32GetStdHandleGetConsoleScreenBufferInfostructunpackrawr  r  r   r  r   r   r   r   rI   r<   searchr  r   rP  OSError)r  r  hcsbiresr	  r  r  rightprocessr   r   re_linuxre_osx
re_solarisregexrO  r  rY  rK   s                      r2   findout_terminal_width=PyTestReporter.terminal_width.<locals>.findout_terminal_width  s   ||w& @OO005+B/oo@@I!mTXX> =Q1a!Aq! <'...szz8,,SZZ5F5F5H5H***)$**FD>%??%??, ")!4!4!6w/ :7?
&
;EIIe4E("'++i"8!$'LE !A:#(L < &&&  * ! !+  2 &&&5s%   ,AF2 =F""
F/.F/2
G
	G
)r  )rK   r  rY  s   `  r2   r7  PyTestReporter.terminal_width  s8    +'''8	't '($r1   c                    Sn0 nU H	  u  pXU'   M     Sn
SnUc  U R                   nUS:X  aY  U R                  [        U5      -   U:  a  U R                  S5        U R                  SX@R                  -
  [        U5      -
  -  5        U R                  (       dE  [        [        R                  S5      (       a&  [        R                  R                  5       (       d  S	nO*[        R                  S
:X  a  S	nOU R                  (       d  S	nU R                  (       a(  US   S:w  a  [        R                  R                  S5        [        (       a"  UR                  S5      R                  SS5      nO[        R                  R                  R!                  5       R#                  S5      (       dQ  UR                  [        R                  R                  S5      R                  [        R                  R                  5      nUS	:X  a   [        R                  R                  U5        O-[        R                  R                  XU   -  < U< U
< 35        [        R                  R%                  5         UR'                  S5      nUS:X  a  U =R                  [        U5      -  sl        O[        U5      U-
  S-
  U l        U R                  U:  U l        U =R                  U-  sl        g)aj  
Prints a text on the screen.

It uses sys.stdout.write(), so no readline library is necessary.

Parameters
==========

color : choose from the colors below, "" means default color
align : "left"/"right", "left" is a normal print, "right" is aligned on
        the right-hand side of the screen, filled with spaces if
        necessary
width : the screen width

))Blackz0;30)Redz0;31)Greenz0;32)Brownz0;33)Bluez0;34)Purplez0;35)Cyanz0;36)	LightGrayz0;37)DarkGrayz1;30)LightRedz1;31)
LightGreenz1;32)Yellowz1;33)	LightBluez1;34)LightPurplez1;35)	LightCyanz1;36)Whitez1;37z[0mz[%smNr  
r;   r  r%  rS   r   rB   rC   rD   utfbackslashreplacerU   rV   )r7  r  r   r9  r  r  r\   r   r  r]   r  r  
IS_WINDOWSrH   rI   r!  r  r  flushrfind)rK   rq  coloralignrY  r   color_templatesr   rk  r  c_normalc_colorrS  s                r2   r9  PyTestReporter.write7  s   "
& *KD 4L +=''EGT*U2

4 JJsEOO3c$i?@A!!gcjj(&C&C

!!##
 E\\W$EE??Aw$

  & :;;34;;FHMD$$**,77>>;;szz224F   &szz':': ;  B;JJT"JJ%=($: ;

JJt7OOs4y(O!$i!ma/DO//U25 r1   c                     U R                   nUS:w  a  SU-  nU[        U5      -
  S-  nX$-  U-   X#U-
  [        U5      -
  -  -   nU R                  US-   5        g )Nr%  z %s r1  r+  )r7  r   r9  )rK   rq  delimrY  idxr   s         r2   r6  PyTestReporter.write_center  sa    ##2:D=Ds4y Q&IuckCI&=>>

1t8r1   c                     UR                   n[        R                  " XU5      nU R                  SR	                  U5      5        g )Nr%  )tb_next	tracebackformat_exceptionr9  rZ   )rK   rA  r   r   r   s        r2   write_exceptionPyTestReporter.write_exception  s1    ZZ&&qr2

2771:r1   c           	      &   U R                  U5        [        R                  n[        [        R                  5      nSU-  n[
        R                  " 5       nUS:X  a  US[        R                  -  -  nU R                  SU< SU< SU< S35        SS	K	J
n  U R                  S
U-  5        SSKJn  U R                  SU-  5        Sn	[        S:X  a  SS Kn
U
R                  5       n	U R                  S[        < SU	< S35        [!        S5      nU R                  SU(       d  S OUR"                  -  5        Ub  U R                  SU-  5        SSK	Jn  U R                  S5        [&        R(                  " S5      =(       d    SnU(       a+  US:X  d  [+        U5      (       a  U R                  SU-  5        OU R                  S5        U R,                  (       a  U R                  SU R,                  -  5        U R                  S5        [/        5       U l        g )Nz%s.%s.%s-%s-%sPyPyz %s.%s.%s-%s-%szexecutable:         z  (z) [z]
r   )ARCHzarchitecture:       %s
)	USE_CACHEzcache:              %s
r%  gmpyzground types:       r;   r+  r  znumpy:              %s
zrandom seed:        %d
)HASH_RANDOMIZATIONzhash randomization: r   0r   zon (PYTHONHASHSEED=%s)
zoff
zsplit:              %s
)r6  r\   r  r  rw  r]   python_implementationpypy_version_infor9  sympy.utilities.miscrC  sympy.core.cacherD  r   gmpy2versionr   __version__rF  rX   r   r   r  clock_t_start)rK   r   r"  r  r  r}  implementationrC  rD  rM  rE  r  rF  r   s                 r2   r5  PyTestReporter.start  s   #^^
#""#)A-!779V#/#2G2GGGN

9 	:-

-45.

-	9:&  llnG

L'JKg&

-UHYHYZ[JJ1D89;

)*II./63	9#8C	NNJJ1I=>JJw;;JJ1DKK?@

4r1   c                 	  ^  [        5       T l        T R                  S5        ST R                  -  q[        [        5      qU 4S jn[        T R                  5      S:  a  U" S[        T R                  5      -  5        [        T R                  5      S:  a  U" S[        T R                  5      -  5        T R                  S:  a  U" ST R                  -  5        T R                  S:  a  U" ST R                  -  5        [        T R                  5      S:  a  U" S[        T R                  5      -  5        [        T R                  5      S:  a  U" S	[        T R                  5      -  5        U" S
T R                  T R                  -
  -  5        T R                  (       aA  T R                  SS5        [!        T R                  S S9nU H  u  p4[#        SX44-  5        M     T R$                  (       aA  T R                  SS5        [!        T R$                  S S9nU H  u  pd[#        SXd4-  5        M     [        T R                  5      S:  aU  T R                  SS5        T R                   H"  nT R                  US   < SUS   < S35        M$     T R                  S5        T R&                  S:w  a  [        T R                  5      S:  a~  T R                   H]  nUu  pu  pnT R                  SS5        U	c  SU-  nOU< SU	R(                  < 3nT R                  US5        T R+                  XU5        M_     T R                  S5        T R&                  S:w  a  [        T R                  5      S:  as  T R                   HR  nUu  pu  pnT R                  SS5        T R                  U< SU	R(                  < 3S5        T R+                  XU5        MT     T R                  S5        T R&                  S:w  ay  [        T R                  5      S:  a`  T R                   H?  nUu  pT R                  SS5        T R                  SU-  S5        T R                  U5        MA     T R                  S5        T R                  [        5        [        T R                  5      S:H  =(       a7    [        T R                  5      S:H  =(       a    [        T R                  5      S:H  nU(       d  T R                  S5        U$ )Nr+  ztests finished: %d passed, c                    >  [         [        U 5      -   TR                  :  a  [        S-  qSq [        U -  q[         [        U 5      -  q g )Nr+  r   )linelenr   r7  rq  )mytextrK   s    r2   add_text'PyTestReporter.finish.<locals>.add_text  sB    -V$t':'::FNDs6{"Gr1   r   z%d failed, z%d skipped, z%d expected to fail, z %d expected to fail but passed, z%d exceptions, zin %.2f secondszslowest testsr  c                     U S   $ r  r*   r   s    r2   r   'PyTestReporter.finish.<locals>.<lambda>  s    1r1   r  z%s - Took %.3f secondszunexpectedly fast testsc                     U S   $ r  r*   rZ  s    r2   r   r[    s    qtr1   zxpassed testsz: rV   nor%  r  rT   r   zDO *NOT* COMMIT!
)rO  _t_endr9  r  rq  r   rU  r  r  r  r  r  r  rP  r  r6  r  r   r  r  r,   r?  )rK   rW  sorted_slowslow_func_namer  sorted_fastfast_func_namerA  rj  r   r   r   r   r>   r"  oks   `               r2   r  PyTestReporter.finish  s   g

4,t||;d)	# t||q ]S%667t##$q(]S)=)=%>>?==1^dmm34==1,t}}<=t}}!7#dmm:LLMt 1$&T-=-=)>>?"dkkDMM&ABC##os3 !9!9~NK)4%..1HHI *5 ##7= !9!9%35K)4%..1HHI *5 t}}!os3]]

1qt45 #JJt>>T!c$*:*:&;a&?%%,-)\ab!!"c*9xA#+QZZ8A!!!S)$$QR0 & JJt>>T!c$,,&7!&;\\,-)\ab!!"c*!!h

"CSI$$QR0	 "
 JJt>>T!c$*>*>&?!&C)) !!!"c*!!$/37

3	 *
 JJt$!# +D,<,<(=(B +$$%* 	JJ+,	r1   c                     U[        U R                  5      S-   S  nX0l        SU l        U R	                  U5        U R	                  SU-  5        g )NrV   Fz[%d] )r   ry  r  _active_file_errorr9  )rK   rj  r  r>  s       r2   r   PyTestReporter.entering_filename	  sG    C/!345$"'

8

7Q;r1   c                     U R                  S5        U R                  (       a  U R                  SSSS9  OU R                  SSSS9  U R                  S5        U R                  (       a  U R                  S5        g g )	Nr;   [FAIL]r  r  r2  z[OK]r  r+  )r9  rf  r8  rb  s    r2   r  PyTestReporter.leaving_filename	  s^    

3""JJxgJ6JJvwgJ6

4==JJt r1   c                 v    Xl         U R                  (       a"  U R                  SUR                  -   S-   5        g g )Nr+  r;   )r  r8  r9  r,   r(  s     r2   r  PyTestReporter.entering_test'	  s-    ==JJtajj(3./ r1   c                 R    U =R                   S-  sl         U R                  SS5        g )NrV   r   r  )r  r9  rb  s    r2   r  PyTestReporter.test_xfail,	  s    

3 r1   c                     [        U5      nU R                  R                  U R                  U45        U R	                  SS5        g )NXr  )r   r  r_   r  r9  )rK   r  messages      r2   r   PyTestReporter.test_xpass0	  s6    a&d//9:

3 r1   c                     U R                   R                  U R                  U R                  U45        U R	                  SS5        SU l        g )NFr  T)r  r_   r  r  r9  rf  rK   r  s     r2   r  PyTestReporter.test_fail5	  s;    T..IJ

3"&r1   c                     SR                  UR                  S5      SS  5      nU R                  R                  X45        U R	                  SS5        SU l        g )Nr+  rV   ru  r  T)rZ   r[   r  r_   r9  rf  )rK   rk  	error_msgs      r2   r<  PyTestReporter.doctest_fail:	  sM    IIiood3AB78	##T$56

3"&r1   c                     U =R                   S-  sl         U R                  (       a  U R                  SS5        g U R                  US5        g )NrV   rc  r  )r  r8  r9  )rK   chars     r2   r  PyTestReporter.test_passA	  s3    ==JJtW%JJtW%r1   c                    SnU =R                   S-  sl         Ub%  [        U5      nUS:X  a  SnOUS:X  a  SnOUS:X  a  SnU R                  (       a+  Ub  U R                  WS	-   S
5        OU R                  SS
5        U R                  US
5        g )Nr>   rV   r   Kr  Tr  wr;   r  z - )r  r   r8  r9  )rK   r  r|  rr  s       r2   r  PyTestReporter.test_skipH	  s    =!fG--I%F"==}

7S=&1

5&)

4 r1   c                     U R                   R                  U R                  U R                  U45        US   [        L a  U R                  SS5        OU R                  SS5        SU l        g )Nr   r  r  ET)r  r_   r  r  r5   r9  rf  rv  s     r2   r  PyTestReporter.test_exceptionZ	  sW    !2!2DNNH MNA;,&JJsE"JJsE""&r1   c                 "   U R                   R                  US U45        U[        U R                  5      S-   S  nU R	                  U5        U R	                  SS5        U R	                  S5        U R	                  SSSS9  U R	                  S5        g )	NrV   z[?]   Failed to importr  r;   ri  r  rj  r+  )r  r_   r   ry  r9  )rK   rj  r  r>  s       r2   r  PyTestReporter.import_errorb	  s|    4 :;C/!345

8

+U3

3

8U'
2

4r1   )r  r  rf  r  r  r  r  r  r  r  r  ry  r  r  r^  rP  r  r  r8  r  r  r  r  r  )Fr   TFN)r%  r  NF)=)Nztest process starts)r,  r   )r,   r-   r.   r/   r  r  r{  r  r7  r9  r6  r?  r5  r  r  r  r  r  r   r  r<  r  r  r  r  r0   r*   r1   r2   r   r     s     :>+/ 8 A AF 9= X!t! FRh 0
!!
'
'&!$'r1   r   )   )T)r*   Nr*   Nr*   Nr   )Rr  rX   r\   r]   r  r=  r   r<   r  r  r   timeitr   rO  r   r1  r   r   r   r   rl  r  rs  ro  r   
contextlibr   r   pathlibr	   rK  r
   r'  r   sympy.external.gmpyr   rk  r.  r   r   r   r   r  r(   r5   r8   r@   rP   report_failurere   rm   r   r   r  r   r   rM   r   r  r  r  rN  r   rP  rX  rY  DocTestParserr0  r   r-  r7  ra  monkeypatched_methodsmethodoldnamenewnamesetattrr  OutputCheckerrb  r  r   r*   r1   r2   <module>r     sk   
 
    
 	    )  0        %   ( ( ,ggo

		$*** S 	i 		9 		i 	/  
1 #2M &',. 
 
 !#cnn'uYx -126487t ! dP 'ddD%E5RDJKZ  $1 GT|~]~ ZZ)*7?r #02DE ,0tTdU**,ty;x}: }:@c/ c/Lv: v:rJ' J'\ 
 $F 6)G%.G)HI $_// _D	 	ZX Zr1   