o
    oÇh—G  ã                	   @   sT  d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
mZ zddlZW n eyD   G dd„ deƒZG dd„ dƒZY nw dd	lmZ e d
¡e dd¡fZdZG dd„ dƒZe d¡Zejdejfdd„ƒZde	e de	e fdd„Zde	e de
ee  de	e de	e fdd„Zdedefdd„Zdddœd d!„Zd"d#„ ZdS )$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 maintence 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                   @   s   e Zd ZdZdS )ÚNoPytestErrorzBRaise when an internal test helper function is called with pytest.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úq/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/testing/runtests_pytest.pyr   $   s    r   c                   @   s   e Zd ZdZedd„ ƒZdS )Úpytestz@Shadow to support pytest features when pytest can't be imported.c                  O   s   d}t |ƒ‚)Nz7pytest must be installed to run tests via this function)r   )ÚargsÚkwargsÚmsgr   r   r   Úmain*   s   zpytest.mainN)r   r   r	   r
   Ústaticmethodr   r   r   r   r   r   '   s    r   )ÚtestÚsympyÚdocÚsrc)z%sympy/integrals/rubi/rubi_tests/testsc                   @   s²   e Zd ZU dZdZeed< dZeed< dZeed< dZ	eed	< d
Z
eed< ejdefdd„ƒZejdefdd„ƒZejdefdd„ƒZejdefdd„ƒZejdefdd„ƒZdS )ÚPytestPluginManagerz.Module names for pytest plugins used by SymPy.r   ÚPYTESTÚpytest_randomlyÚRANDOMLYÚpytest_splitÚSPLITÚpytest_timeoutÚTIMEOUTÚxdistÚXDISTÚreturnc                 C   ó   t tj | j¡ƒS ©N)ÚboolÚ	importlibÚutilÚ	find_specr   ©Úselfr   r   r   Ú
has_pytestC   ó   zPytestPluginManager.has_pytestc                 C   r"   r#   )r$   r%   r&   r'   r   r(   r   r   r   Úhas_randomlyG   r+   z PytestPluginManager.has_randomlyc                 C   r"   r#   )r$   r%   r&   r'   r   r(   r   r   r   Ú	has_splitK   r+   zPytestPluginManager.has_splitc                 C   r"   r#   )r$   r%   r&   r'   r   r(   r   r   r   Úhas_timeoutO   r+   zPytestPluginManager.has_timeoutc                 C   r"   r#   )r$   r%   r&   r'   r    r(   r   r   r   Ú	has_xdistS   r+   zPytestPluginManager.has_xdistN)r   r   r	   r
   r   ÚstrÚ__annotations__r   r   r   r    Ú	functoolsÚcached_propertyr$   r*   r,   r-   r.   r/   r   r   r   r   r   ;   s"   
 r   z([1-9][0-9]*)/([1-9][0-9]*)r!   c                   C   s   t  t¡jd S )z!Returns the root SymPy directory.é   )ÚpathlibÚPathÚ__file__Úparentsr   r   r   r   Ú	sympy_dir[   s   r9   r   c                 C   s   |   dttƒ ƒg¡ | S )a!  Adds `--rootdir` and path to the args `list` passed to `pytest.main`.

    This is required to ensure that pytest is able to find the SymPy tests in
    instances where it gets confused determining the root directory, e.g. when
    running with Pyodide (e.g. `bin/test_pyodide.mjs`).

    z	--rootdir)Úextendr0   r9   )r   r   r   r   Úupdate_args_with_rootdira   s   r;   ÚpathsÚkeywordsc                    sp  ‡ fdd„}dt dtfdd„}dd„ }g ‰ tD ]}t tƒ |¡}| ¡ r+ˆ  t |ƒ¡ qg }| rag }	g }
| D ]}t |¡ ¡ rL|	 t t tƒ |¡ƒ¡ q6|
 |¡ q6||
ƒ}| |	¡ | |¡ n| ˆ ¡ |d	ur±|d
kr±g }|D ]7}||ƒrƒ|||ƒ}| |¡ qrt	 
|¡D ] \}}}|D ]}t t ||¡ƒ}||ƒr§|||ƒ}| |¡ qqˆqr| |¡ |S | |¡ |S )a¨  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                    sZ  g }| D ]W}t |ƒdkr|d d… dk}|dd … dk}nt |ƒdkr.d}|dd … dk}nd}d}|r<|r<| |¡ q|rG| |› d¡ q|rR| d|› ¡ q| d|› d¡ qg }ˆ D ]J}tj|d	d
D ]@\}}}	t| |ƒ}
|
D ]3\}}t|d|› dƒr“| tt |¡ƒ¡ g |d d …< qu|	D ]}t||ƒr§| tt ||¡ƒ¡ q•quqiq`|S )Né   r   éýÿÿÿú.pyé   Fz*.pyztest*T)ÚtopdownÚ*)	ÚlenÚappendÚosÚwalkÚzipr   r0   r5   r6   )Ú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_defaultr   r   Úfind_paths_matching_partialƒ   sB   

€þûþ
z;update_args_with_paths.<locals>.find_paths_matching_partialÚfilepathr!   c                 S   s<   t  | ¡}| ¡ sdS |jd  d¡sdS |jdksdS dS )NFéÿÿÿÿÚtest_r@   T)r5   r6   Úis_fileÚpartsÚ
startswithÚsuffix)rY   rP   r   r   r   Úis_tests_file¥   s   

z-update_args_with_paths.<locals>.is_tests_filec           	      S   s¨   g }t |ddB}| ¡ }| ¡ D ]0}| ¡  d¡rA| D ]$}| ¡  | ¡ ¡dkr@| d¡d  d¡d }|d	 | }| |¡ qqW d   ƒ |S 1 sMw   Y  |S )
Nzutf-8)Úencodingzdef rZ   ú é   ú(r   z::)	ÚopenÚreadÚ
splitlinesÚlstripr^   ÚlowerÚfindÚsplitrE   )	r=   rY   rN   Ú
tests_fileÚsourceÚlineÚkwÚ	test_nameÚfull_test_pathr   r   r   Úfind_tests_matching_keywords¯   s    
€ú
þ	÷	z<update_args_with_paths.<locals>.find_tests_matching_keywordsNr   )r0   r$   ÚTESTPATHS_DEFAULTr5   r6   r9   ÚexistsrE   r:   rF   rG   )r<   r=   r   rX   r`   rr   rO   Úabsolute_testpathÚcandidate_pathsÚ
full_pathsrI   rP   Úmatched_pathsrN   Útest_matchesÚrootÚdirnamesÚ	filenamesÚfilenameÚabsolute_filepathr   rV   r   Úupdate_args_with_pathsm   sV   "
€


þ
€ùÿ
	
þr   rK   c                 C   sH   dt dtfdd„}|| ƒsdt| ƒ› d}t|ƒ‚t t tƒ | ¡ƒ}|S )a€  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/...`.

    rK   r!   c                 S   s   t  | ¡jd dkS )z@Assumption that partial paths are defined from the `sympy` root.r   r   )r5   r6   r]   )rK   r   r   r   Úis_valid_partial_pathô   s   z1make_absolute_path.<locals>.is_valid_partial_pathzPartial path z] is invalid, partial paths are expected to be defined with the `sympy` directory as the root.)r0   r$   ÚdirÚ
ValueErrorr5   r6   r9   )rK   r€   r   Úabsolute_pathr   r   r   Úmake_absolute_pathè   s   ÿr„   T©Ú
subprocessÚrerunc                 O   s  |  dd¡r-| dd¡ | dd¡ | dd¡ |  d¡du r#d|d< t|ddd	œ|¤ŽS tƒ }|js7t ¡  g }t|ƒ}|  d
d¡rH| d¡ |  d¡ }rV| 	d|g¡ |  d¡r`| d¡ |  dd¡sm| 	ddg¡ |  d¡ }r†|j
s}d}t|ƒ‚| 	dt|ƒg¡ |  dd¡r•|j
r•| d¡ n|  dd¡s¤|j
s¤d}t|ƒ‚|  dd¡ }	rÀ|jsµd}t|ƒ‚| 	dtt|	ƒƒg¡ |  dd¡rÎ| 	ddg¡ n| 	ddg¡ |  d¡ }
dur|jsèd }t|ƒ‚t |
¡}|sõd!}t|ƒ‚tt| ¡ ƒ\}}| 	d"|d#|g¡ ||krd$|› d%|› d&}t|ƒ‚|  d't¡ }r1|D ]}| 	d(t|ƒg¡ q$|  dd¡rI|jsBd)}t|ƒ‚| 	d*d+g¡ |  dd¡r_|jsZd,}t|ƒ‚| d-¡ |  d.¡ }durstd/d0„ |D ƒƒ}nd1}t|||ƒ}t |¡}|S )2aê  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 sucessfully 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 tooslowrk   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-durationsro   c                 s   s    | ]}t |ƒV  qd S r#   )r0   )Ú.0ro   r   r   r   Ú	<genexpr>Ï  s   € ztest.<locals>.<genexpr>r   )ÚgetÚpopÚ
test_sympyr   r*   r   r   r;   rE   r:   r,   ÚModuleNotFoundErrorr0   r.   Úintr-   Úsplit_patternÚmatchr‚   ÚmapÚgroupsÚBLACKLIST_DEFAULTr„   r/   Útupler   )r†   r‡   r<   r   Úpytest_plugin_managerr   r   r‘   r   r“   rk   rž   ÚgroupÚsplitsr”   rP   r=   Ú	exit_coder   r   r   r     sŒ   x






r   c                   C   s   t ‚)zNInterface to run doctests via pytest compatible with SymPy's test runner.
    )ÚNotImplementedErrorr   r   r   r   ÚdoctestØ  s   r¨   ) r
   r2   Úimportlib.utilr%   rF   r5   Úrer   Útypingr   r   r   r   ÚImportErrorÚ	Exceptionr   Úsympy.testing.runtestsr   rš   r6   rs   r¡   r   Úcompiler   Ú	lru_cacher9   r0   r;   r   r„   r¨   r   r   r   r   Ú<module>   sJ    û
þ
ÿ
þý
ü{ V