Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +2 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/physics/continuum_mechanics/__pycache__/beam.cpython-310.pyc +3 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/physics/control/__pycache__/lti.cpython-310.pyc +3 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/testing/__init__.py +10 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/testing/matrices.py +8 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/testing/pytest.py +401 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/testing/quality_unicode.py +102 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/testing/randtest.py +19 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/testing/runtests.py +2409 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/testing/runtests_pytest.py +475 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/testing/tests/__init__.py +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/testing/tests/test_pytest.py +211 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/testing/tmpfiles.py +46 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/__init__.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/basisdependent.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/coordsysrect.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/deloperator.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/dyadic.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/implicitregion.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/integrals.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/operators.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/orienters.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/parametricregion.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/point.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/scalar.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/vector.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/__pycache__/test_coordsysrect.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/__pycache__/test_dyadic.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/__pycache__/test_functions.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/__pycache__/test_integrals.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/__pycache__/test_vector.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/test_coordsysrect.py +464 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/test_field_functions.py +321 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/test_implicitregion.py +90 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/test_integrals.py +106 -0
- mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/test_parametricregion.py +97 -0
- pllava/share/terminfo/g/guru-44 +0 -0
- pllava/share/terminfo/t/t16 +0 -0
- pllava/share/terminfo/t/tab +0 -0
- pllava/share/terminfo/t/tab132-15 +0 -0
- pllava/share/terminfo/t/tandem653 +0 -0
- pllava/share/terminfo/t/tek4024 +0 -0
- pllava/share/terminfo/t/tek4105 +0 -0
- pllava/share/terminfo/t/tek4112-nd +0 -0
- pllava/share/terminfo/t/tek4113-34 +0 -0
- pllava/share/terminfo/t/tek4404 +0 -0
- pllava/share/terminfo/t/teraterm2.3 +0 -0
- pllava/share/terminfo/t/terminator +0 -0
- pllava/share/terminfo/t/ti707-w +0 -0
- pllava/share/terminfo/t/ti916-8-132 +0 -0
.gitattributes
CHANGED
|
@@ -700,3 +700,5 @@ mplug_owl2/lib/python3.10/site-packages/idna/__pycache__/uts46data.cpython-310.p
|
|
| 700 |
pllava/lib/python3.10/site-packages/numpy/core/_simd.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 701 |
mplug_owl2/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_spin.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 702 |
mplug_owl2/lib/python3.10/site-packages/sympy/parsing/latex/_antlr/__pycache__/latexparser.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 700 |
pllava/lib/python3.10/site-packages/numpy/core/_simd.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 701 |
mplug_owl2/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_spin.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 702 |
mplug_owl2/lib/python3.10/site-packages/sympy/parsing/latex/_antlr/__pycache__/latexparser.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 703 |
+
mplug_owl2/lib/python3.10/site-packages/sympy/physics/control/__pycache__/lti.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 704 |
+
mplug_owl2/lib/python3.10/site-packages/sympy/physics/continuum_mechanics/__pycache__/beam.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
mplug_owl2/lib/python3.10/site-packages/sympy/physics/continuum_mechanics/__pycache__/beam.cpython-310.pyc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:206cba6f99b5f464ddb6468822a7f6e8776ca55baa449e69f7a548e3e4111fd7
|
| 3 |
+
size 122356
|
mplug_owl2/lib/python3.10/site-packages/sympy/physics/control/__pycache__/lti.cpython-310.pyc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aa61cba5c82f963ec0ee069e62b253a2185004a70b964e4c1ff1e18115b2e51c
|
| 3 |
+
size 154412
|
mplug_owl2/lib/python3.10/site-packages/sympy/testing/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""This module contains code for running the tests in SymPy."""
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
from .runtests import doctest
|
| 5 |
+
from .runtests_pytest import test
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
__all__ = [
|
| 9 |
+
'test', 'doctest',
|
| 10 |
+
]
|
mplug_owl2/lib/python3.10/site-packages/sympy/testing/matrices.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def allclose(A, B, rtol=1e-05, atol=1e-08):
|
| 2 |
+
if len(A) != len(B):
|
| 3 |
+
return False
|
| 4 |
+
|
| 5 |
+
for x, y in zip(A, B):
|
| 6 |
+
if abs(x-y) > atol + rtol * max(abs(x), abs(y)):
|
| 7 |
+
return False
|
| 8 |
+
return True
|
mplug_owl2/lib/python3.10/site-packages/sympy/testing/pytest.py
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""py.test hacks to support XFAIL/XPASS"""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
import re
|
| 5 |
+
import functools
|
| 6 |
+
import os
|
| 7 |
+
import contextlib
|
| 8 |
+
import warnings
|
| 9 |
+
import inspect
|
| 10 |
+
import pathlib
|
| 11 |
+
from typing import Any, Callable
|
| 12 |
+
|
| 13 |
+
from sympy.utilities.exceptions import SymPyDeprecationWarning
|
| 14 |
+
# Imported here for backwards compatibility. Note: do not import this from
|
| 15 |
+
# here in library code (importing sympy.pytest in library code will break the
|
| 16 |
+
# pytest integration).
|
| 17 |
+
from sympy.utilities.exceptions import ignore_warnings # noqa:F401
|
| 18 |
+
|
| 19 |
+
ON_CI = os.getenv('CI', None) == "true"
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
import pytest
|
| 23 |
+
USE_PYTEST = getattr(sys, '_running_pytest', False)
|
| 24 |
+
except ImportError:
|
| 25 |
+
USE_PYTEST = False
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
raises: Callable[[Any, Any], Any]
|
| 29 |
+
XFAIL: Callable[[Any], Any]
|
| 30 |
+
skip: Callable[[Any], Any]
|
| 31 |
+
SKIP: Callable[[Any], Any]
|
| 32 |
+
slow: Callable[[Any], Any]
|
| 33 |
+
tooslow: Callable[[Any], Any]
|
| 34 |
+
nocache_fail: Callable[[Any], Any]
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
if USE_PYTEST:
|
| 38 |
+
raises = pytest.raises
|
| 39 |
+
skip = pytest.skip
|
| 40 |
+
XFAIL = pytest.mark.xfail
|
| 41 |
+
SKIP = pytest.mark.skip
|
| 42 |
+
slow = pytest.mark.slow
|
| 43 |
+
tooslow = pytest.mark.tooslow
|
| 44 |
+
nocache_fail = pytest.mark.nocache_fail
|
| 45 |
+
from _pytest.outcomes import Failed
|
| 46 |
+
|
| 47 |
+
else:
|
| 48 |
+
# Not using pytest so define the things that would have been imported from
|
| 49 |
+
# there.
|
| 50 |
+
|
| 51 |
+
# _pytest._code.code.ExceptionInfo
|
| 52 |
+
class ExceptionInfo:
|
| 53 |
+
def __init__(self, value):
|
| 54 |
+
self.value = value
|
| 55 |
+
|
| 56 |
+
def __repr__(self):
|
| 57 |
+
return "<ExceptionInfo {!r}>".format(self.value)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def raises(expectedException, code=None):
|
| 61 |
+
"""
|
| 62 |
+
Tests that ``code`` raises the exception ``expectedException``.
|
| 63 |
+
|
| 64 |
+
``code`` may be a callable, such as a lambda expression or function
|
| 65 |
+
name.
|
| 66 |
+
|
| 67 |
+
If ``code`` is not given or None, ``raises`` will return a context
|
| 68 |
+
manager for use in ``with`` statements; the code to execute then
|
| 69 |
+
comes from the scope of the ``with``.
|
| 70 |
+
|
| 71 |
+
``raises()`` does nothing if the callable raises the expected exception,
|
| 72 |
+
otherwise it raises an AssertionError.
|
| 73 |
+
|
| 74 |
+
Examples
|
| 75 |
+
========
|
| 76 |
+
|
| 77 |
+
>>> from sympy.testing.pytest import raises
|
| 78 |
+
|
| 79 |
+
>>> raises(ZeroDivisionError, lambda: 1/0)
|
| 80 |
+
<ExceptionInfo ZeroDivisionError(...)>
|
| 81 |
+
>>> raises(ZeroDivisionError, lambda: 1/2)
|
| 82 |
+
Traceback (most recent call last):
|
| 83 |
+
...
|
| 84 |
+
Failed: DID NOT RAISE
|
| 85 |
+
|
| 86 |
+
>>> with raises(ZeroDivisionError):
|
| 87 |
+
... n = 1/0
|
| 88 |
+
>>> with raises(ZeroDivisionError):
|
| 89 |
+
... n = 1/2
|
| 90 |
+
Traceback (most recent call last):
|
| 91 |
+
...
|
| 92 |
+
Failed: DID NOT RAISE
|
| 93 |
+
|
| 94 |
+
Note that you cannot test multiple statements via
|
| 95 |
+
``with raises``:
|
| 96 |
+
|
| 97 |
+
>>> with raises(ZeroDivisionError):
|
| 98 |
+
... n = 1/0 # will execute and raise, aborting the ``with``
|
| 99 |
+
... n = 9999/0 # never executed
|
| 100 |
+
|
| 101 |
+
This is just what ``with`` is supposed to do: abort the
|
| 102 |
+
contained statement sequence at the first exception and let
|
| 103 |
+
the context manager deal with the exception.
|
| 104 |
+
|
| 105 |
+
To test multiple statements, you'll need a separate ``with``
|
| 106 |
+
for each:
|
| 107 |
+
|
| 108 |
+
>>> with raises(ZeroDivisionError):
|
| 109 |
+
... n = 1/0 # will execute and raise
|
| 110 |
+
>>> with raises(ZeroDivisionError):
|
| 111 |
+
... n = 9999/0 # will also execute and raise
|
| 112 |
+
|
| 113 |
+
"""
|
| 114 |
+
if code is None:
|
| 115 |
+
return RaisesContext(expectedException)
|
| 116 |
+
elif callable(code):
|
| 117 |
+
try:
|
| 118 |
+
code()
|
| 119 |
+
except expectedException as e:
|
| 120 |
+
return ExceptionInfo(e)
|
| 121 |
+
raise Failed("DID NOT RAISE")
|
| 122 |
+
elif isinstance(code, str):
|
| 123 |
+
raise TypeError(
|
| 124 |
+
'\'raises(xxx, "code")\' has been phased out; '
|
| 125 |
+
'change \'raises(xxx, "expression")\' '
|
| 126 |
+
'to \'raises(xxx, lambda: expression)\', '
|
| 127 |
+
'\'raises(xxx, "statement")\' '
|
| 128 |
+
'to \'with raises(xxx): statement\'')
|
| 129 |
+
else:
|
| 130 |
+
raise TypeError(
|
| 131 |
+
'raises() expects a callable for the 2nd argument.')
|
| 132 |
+
|
| 133 |
+
class RaisesContext:
|
| 134 |
+
def __init__(self, expectedException):
|
| 135 |
+
self.expectedException = expectedException
|
| 136 |
+
|
| 137 |
+
def __enter__(self):
|
| 138 |
+
return None
|
| 139 |
+
|
| 140 |
+
def __exit__(self, exc_type, exc_value, traceback):
|
| 141 |
+
if exc_type is None:
|
| 142 |
+
raise Failed("DID NOT RAISE")
|
| 143 |
+
return issubclass(exc_type, self.expectedException)
|
| 144 |
+
|
| 145 |
+
class XFail(Exception):
|
| 146 |
+
pass
|
| 147 |
+
|
| 148 |
+
class XPass(Exception):
|
| 149 |
+
pass
|
| 150 |
+
|
| 151 |
+
class Skipped(Exception):
|
| 152 |
+
pass
|
| 153 |
+
|
| 154 |
+
class Failed(Exception): # type: ignore
|
| 155 |
+
pass
|
| 156 |
+
|
| 157 |
+
def XFAIL(func):
|
| 158 |
+
def wrapper():
|
| 159 |
+
try:
|
| 160 |
+
func()
|
| 161 |
+
except Exception as e:
|
| 162 |
+
message = str(e)
|
| 163 |
+
if message != "Timeout":
|
| 164 |
+
raise XFail(func.__name__)
|
| 165 |
+
else:
|
| 166 |
+
raise Skipped("Timeout")
|
| 167 |
+
raise XPass(func.__name__)
|
| 168 |
+
|
| 169 |
+
wrapper = functools.update_wrapper(wrapper, func)
|
| 170 |
+
return wrapper
|
| 171 |
+
|
| 172 |
+
def skip(str):
|
| 173 |
+
raise Skipped(str)
|
| 174 |
+
|
| 175 |
+
def SKIP(reason):
|
| 176 |
+
"""Similar to ``skip()``, but this is a decorator. """
|
| 177 |
+
def wrapper(func):
|
| 178 |
+
def func_wrapper():
|
| 179 |
+
raise Skipped(reason)
|
| 180 |
+
|
| 181 |
+
func_wrapper = functools.update_wrapper(func_wrapper, func)
|
| 182 |
+
return func_wrapper
|
| 183 |
+
|
| 184 |
+
return wrapper
|
| 185 |
+
|
| 186 |
+
def slow(func):
|
| 187 |
+
func._slow = True
|
| 188 |
+
|
| 189 |
+
def func_wrapper():
|
| 190 |
+
func()
|
| 191 |
+
|
| 192 |
+
func_wrapper = functools.update_wrapper(func_wrapper, func)
|
| 193 |
+
func_wrapper.__wrapped__ = func
|
| 194 |
+
return func_wrapper
|
| 195 |
+
|
| 196 |
+
def tooslow(func):
|
| 197 |
+
func._slow = True
|
| 198 |
+
func._tooslow = True
|
| 199 |
+
|
| 200 |
+
def func_wrapper():
|
| 201 |
+
skip("Too slow")
|
| 202 |
+
|
| 203 |
+
func_wrapper = functools.update_wrapper(func_wrapper, func)
|
| 204 |
+
func_wrapper.__wrapped__ = func
|
| 205 |
+
return func_wrapper
|
| 206 |
+
|
| 207 |
+
def nocache_fail(func):
|
| 208 |
+
"Dummy decorator for marking tests that fail when cache is disabled"
|
| 209 |
+
return func
|
| 210 |
+
|
| 211 |
+
@contextlib.contextmanager
|
| 212 |
+
def warns(warningcls, *, match='', test_stacklevel=True):
|
| 213 |
+
'''
|
| 214 |
+
Like raises but tests that warnings are emitted.
|
| 215 |
+
|
| 216 |
+
>>> from sympy.testing.pytest import warns
|
| 217 |
+
>>> import warnings
|
| 218 |
+
|
| 219 |
+
>>> with warns(UserWarning):
|
| 220 |
+
... warnings.warn('deprecated', UserWarning, stacklevel=2)
|
| 221 |
+
|
| 222 |
+
>>> with warns(UserWarning):
|
| 223 |
+
... pass
|
| 224 |
+
Traceback (most recent call last):
|
| 225 |
+
...
|
| 226 |
+
Failed: DID NOT WARN. No warnings of type UserWarning\
|
| 227 |
+
was emitted. The list of emitted warnings is: [].
|
| 228 |
+
|
| 229 |
+
``test_stacklevel`` makes it check that the ``stacklevel`` parameter to
|
| 230 |
+
``warn()`` is set so that the warning shows the user line of code (the
|
| 231 |
+
code under the warns() context manager). Set this to False if this is
|
| 232 |
+
ambiguous or if the context manager does not test the direct user code
|
| 233 |
+
that emits the warning.
|
| 234 |
+
|
| 235 |
+
If the warning is a ``SymPyDeprecationWarning``, this additionally tests
|
| 236 |
+
that the ``active_deprecations_target`` is a real target in the
|
| 237 |
+
``active-deprecations.md`` file.
|
| 238 |
+
|
| 239 |
+
'''
|
| 240 |
+
# Absorbs all warnings in warnrec
|
| 241 |
+
with warnings.catch_warnings(record=True) as warnrec:
|
| 242 |
+
# Any warning other than the one we are looking for is an error
|
| 243 |
+
warnings.simplefilter("error")
|
| 244 |
+
warnings.filterwarnings("always", category=warningcls)
|
| 245 |
+
# Now run the test
|
| 246 |
+
yield warnrec
|
| 247 |
+
|
| 248 |
+
# Raise if expected warning not found
|
| 249 |
+
if not any(issubclass(w.category, warningcls) for w in warnrec):
|
| 250 |
+
msg = ('Failed: DID NOT WARN.'
|
| 251 |
+
' No warnings of type %s was emitted.'
|
| 252 |
+
' The list of emitted warnings is: %s.'
|
| 253 |
+
) % (warningcls, [w.message for w in warnrec])
|
| 254 |
+
raise Failed(msg)
|
| 255 |
+
|
| 256 |
+
# We don't include the match in the filter above because it would then
|
| 257 |
+
# fall to the error filter, so we instead manually check that it matches
|
| 258 |
+
# here
|
| 259 |
+
for w in warnrec:
|
| 260 |
+
# Should always be true due to the filters above
|
| 261 |
+
assert issubclass(w.category, warningcls)
|
| 262 |
+
if not re.compile(match, re.I).match(str(w.message)):
|
| 263 |
+
raise Failed(f"Failed: WRONG MESSAGE. A warning with of the correct category ({warningcls.__name__}) was issued, but it did not match the given match regex ({match!r})")
|
| 264 |
+
|
| 265 |
+
if test_stacklevel:
|
| 266 |
+
for f in inspect.stack():
|
| 267 |
+
thisfile = f.filename
|
| 268 |
+
file = os.path.split(thisfile)[1]
|
| 269 |
+
if file.startswith('test_'):
|
| 270 |
+
break
|
| 271 |
+
elif file == 'doctest.py':
|
| 272 |
+
# skip the stacklevel testing in the doctests of this
|
| 273 |
+
# function
|
| 274 |
+
return
|
| 275 |
+
else:
|
| 276 |
+
raise RuntimeError("Could not find the file for the given warning to test the stacklevel")
|
| 277 |
+
for w in warnrec:
|
| 278 |
+
if w.filename != thisfile:
|
| 279 |
+
msg = f'''\
|
| 280 |
+
Failed: Warning has the wrong stacklevel. The warning stacklevel needs to be
|
| 281 |
+
set so that the line of code shown in the warning message is user code that
|
| 282 |
+
calls the deprecated code (the current stacklevel is showing code from
|
| 283 |
+
{w.filename} (line {w.lineno}), expected {thisfile})'''.replace('\n', ' ')
|
| 284 |
+
raise Failed(msg)
|
| 285 |
+
|
| 286 |
+
if warningcls == SymPyDeprecationWarning:
|
| 287 |
+
this_file = pathlib.Path(__file__)
|
| 288 |
+
active_deprecations_file = (this_file.parent.parent.parent / 'doc' /
|
| 289 |
+
'src' / 'explanation' /
|
| 290 |
+
'active-deprecations.md')
|
| 291 |
+
if not active_deprecations_file.exists():
|
| 292 |
+
# We can only test that the active_deprecations_target works if we are
|
| 293 |
+
# in the git repo.
|
| 294 |
+
return
|
| 295 |
+
targets = []
|
| 296 |
+
for w in warnrec:
|
| 297 |
+
targets.append(w.message.active_deprecations_target)
|
| 298 |
+
with open(active_deprecations_file, encoding="utf-8") as f:
|
| 299 |
+
text = f.read()
|
| 300 |
+
for target in targets:
|
| 301 |
+
if f'({target})=' not in text:
|
| 302 |
+
raise Failed(f"The active deprecations target {target!r} does not appear to be a valid target in the active-deprecations.md file ({active_deprecations_file}).")
|
| 303 |
+
|
| 304 |
+
def _both_exp_pow(func):
|
| 305 |
+
"""
|
| 306 |
+
Decorator used to run the test twice: the first time `e^x` is represented
|
| 307 |
+
as ``Pow(E, x)``, the second time as ``exp(x)`` (exponential object is not
|
| 308 |
+
a power).
|
| 309 |
+
|
| 310 |
+
This is a temporary trick helping to manage the elimination of the class
|
| 311 |
+
``exp`` in favor of a replacement by ``Pow(E, ...)``.
|
| 312 |
+
"""
|
| 313 |
+
from sympy.core.parameters import _exp_is_pow
|
| 314 |
+
|
| 315 |
+
def func_wrap():
|
| 316 |
+
with _exp_is_pow(True):
|
| 317 |
+
func()
|
| 318 |
+
with _exp_is_pow(False):
|
| 319 |
+
func()
|
| 320 |
+
|
| 321 |
+
wrapper = functools.update_wrapper(func_wrap, func)
|
| 322 |
+
return wrapper
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
@contextlib.contextmanager
|
| 326 |
+
def warns_deprecated_sympy():
|
| 327 |
+
'''
|
| 328 |
+
Shorthand for ``warns(SymPyDeprecationWarning)``
|
| 329 |
+
|
| 330 |
+
This is the recommended way to test that ``SymPyDeprecationWarning`` is
|
| 331 |
+
emitted for deprecated features in SymPy. To test for other warnings use
|
| 332 |
+
``warns``. To suppress warnings without asserting that they are emitted
|
| 333 |
+
use ``ignore_warnings``.
|
| 334 |
+
|
| 335 |
+
.. note::
|
| 336 |
+
|
| 337 |
+
``warns_deprecated_sympy()`` is only intended for internal use in the
|
| 338 |
+
SymPy test suite to test that a deprecation warning triggers properly.
|
| 339 |
+
All other code in the SymPy codebase, including documentation examples,
|
| 340 |
+
should not use deprecated behavior.
|
| 341 |
+
|
| 342 |
+
If you are a user of SymPy and you want to disable
|
| 343 |
+
SymPyDeprecationWarnings, use ``warnings`` filters (see
|
| 344 |
+
:ref:`silencing-sympy-deprecation-warnings`).
|
| 345 |
+
|
| 346 |
+
>>> from sympy.testing.pytest import warns_deprecated_sympy
|
| 347 |
+
>>> from sympy.utilities.exceptions import sympy_deprecation_warning
|
| 348 |
+
>>> with warns_deprecated_sympy():
|
| 349 |
+
... sympy_deprecation_warning("Don't use",
|
| 350 |
+
... deprecated_since_version="1.0",
|
| 351 |
+
... active_deprecations_target="active-deprecations")
|
| 352 |
+
|
| 353 |
+
>>> with warns_deprecated_sympy():
|
| 354 |
+
... pass
|
| 355 |
+
Traceback (most recent call last):
|
| 356 |
+
...
|
| 357 |
+
Failed: DID NOT WARN. No warnings of type \
|
| 358 |
+
SymPyDeprecationWarning was emitted. The list of emitted warnings is: [].
|
| 359 |
+
|
| 360 |
+
.. note::
|
| 361 |
+
|
| 362 |
+
Sometimes the stacklevel test will fail because the same warning is
|
| 363 |
+
emitted multiple times. In this case, you can use
|
| 364 |
+
:func:`sympy.utilities.exceptions.ignore_warnings` in the code to
|
| 365 |
+
prevent the ``SymPyDeprecationWarning`` from being emitted again
|
| 366 |
+
recursively. In rare cases it is impossible to have a consistent
|
| 367 |
+
``stacklevel`` for deprecation warnings because different ways of
|
| 368 |
+
calling a function will produce different call stacks.. In those cases,
|
| 369 |
+
use ``warns(SymPyDeprecationWarning)`` instead.
|
| 370 |
+
|
| 371 |
+
See Also
|
| 372 |
+
========
|
| 373 |
+
sympy.utilities.exceptions.SymPyDeprecationWarning
|
| 374 |
+
sympy.utilities.exceptions.sympy_deprecation_warning
|
| 375 |
+
sympy.utilities.decorator.deprecated
|
| 376 |
+
|
| 377 |
+
'''
|
| 378 |
+
with warns(SymPyDeprecationWarning):
|
| 379 |
+
yield
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
def _running_under_pyodide():
|
| 383 |
+
"""Test if running under pyodide."""
|
| 384 |
+
try:
|
| 385 |
+
import pyodide_js # type: ignore # noqa
|
| 386 |
+
except ImportError:
|
| 387 |
+
return False
|
| 388 |
+
else:
|
| 389 |
+
return True
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
def skip_under_pyodide(message):
|
| 393 |
+
"""Decorator to skip a test if running under pyodide."""
|
| 394 |
+
def decorator(test_func):
|
| 395 |
+
@functools.wraps(test_func)
|
| 396 |
+
def test_wrapper():
|
| 397 |
+
if _running_under_pyodide():
|
| 398 |
+
skip(message)
|
| 399 |
+
return test_func()
|
| 400 |
+
return test_wrapper
|
| 401 |
+
return decorator
|
mplug_owl2/lib/python3.10/site-packages/sympy/testing/quality_unicode.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
import fnmatch
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
message_unicode_B = \
|
| 6 |
+
"File contains a unicode character : %s, line %s. " \
|
| 7 |
+
"But not in the whitelist. " \
|
| 8 |
+
"Add the file to the whitelist in " + __file__
|
| 9 |
+
message_unicode_D = \
|
| 10 |
+
"File does not contain a unicode character : %s." \
|
| 11 |
+
"but is in the whitelist. " \
|
| 12 |
+
"Remove the file from the whitelist in " + __file__
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
encoding_header_re = re.compile(
|
| 16 |
+
r'^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)')
|
| 17 |
+
|
| 18 |
+
# Whitelist pattern for files which can have unicode.
|
| 19 |
+
unicode_whitelist = [
|
| 20 |
+
# Author names can include non-ASCII characters
|
| 21 |
+
r'*/bin/authors_update.py',
|
| 22 |
+
r'*/bin/mailmap_check.py',
|
| 23 |
+
|
| 24 |
+
# These files have functions and test functions for unicode input and
|
| 25 |
+
# output.
|
| 26 |
+
r'*/sympy/testing/tests/test_code_quality.py',
|
| 27 |
+
r'*/sympy/physics/vector/tests/test_printing.py',
|
| 28 |
+
r'*/physics/quantum/tests/test_printing.py',
|
| 29 |
+
r'*/sympy/vector/tests/test_printing.py',
|
| 30 |
+
r'*/sympy/parsing/tests/test_sympy_parser.py',
|
| 31 |
+
r'*/sympy/printing/pretty/stringpict.py',
|
| 32 |
+
r'*/sympy/printing/pretty/tests/test_pretty.py',
|
| 33 |
+
r'*/sympy/printing/tests/test_conventions.py',
|
| 34 |
+
r'*/sympy/printing/tests/test_preview.py',
|
| 35 |
+
r'*/liealgebras/type_g.py',
|
| 36 |
+
r'*/liealgebras/weyl_group.py',
|
| 37 |
+
r'*/liealgebras/tests/test_type_G.py',
|
| 38 |
+
|
| 39 |
+
# wigner.py and polarization.py have unicode doctests. These probably
|
| 40 |
+
# don't need to be there but some of the examples that are there are
|
| 41 |
+
# pretty ugly without use_unicode (matrices need to be wrapped across
|
| 42 |
+
# multiple lines etc)
|
| 43 |
+
r'*/sympy/physics/wigner.py',
|
| 44 |
+
r'*/sympy/physics/optics/polarization.py',
|
| 45 |
+
|
| 46 |
+
# joint.py uses some unicode for variable names in the docstrings
|
| 47 |
+
r'*/sympy/physics/mechanics/joint.py',
|
| 48 |
+
|
| 49 |
+
# lll method has unicode in docstring references and author name
|
| 50 |
+
r'*/sympy/polys/matrices/domainmatrix.py',
|
| 51 |
+
r'*/sympy/matrices/repmatrix.py',
|
| 52 |
+
|
| 53 |
+
# Explanation of symbols uses greek letters
|
| 54 |
+
r'*/sympy/core/symbol.py',
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
unicode_strict_whitelist = [
|
| 58 |
+
r'*/sympy/parsing/latex/_antlr/__init__.py',
|
| 59 |
+
# test_mathematica.py uses some unicode for testing Greek characters are working #24055
|
| 60 |
+
r'*/sympy/parsing/tests/test_mathematica.py',
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def _test_this_file_encoding(
|
| 65 |
+
fname, test_file,
|
| 66 |
+
unicode_whitelist=unicode_whitelist,
|
| 67 |
+
unicode_strict_whitelist=unicode_strict_whitelist):
|
| 68 |
+
"""Test helper function for unicode test
|
| 69 |
+
|
| 70 |
+
The test may have to operate on filewise manner, so it had moved
|
| 71 |
+
to a separate process.
|
| 72 |
+
"""
|
| 73 |
+
has_unicode = False
|
| 74 |
+
|
| 75 |
+
is_in_whitelist = False
|
| 76 |
+
is_in_strict_whitelist = False
|
| 77 |
+
for patt in unicode_whitelist:
|
| 78 |
+
if fnmatch.fnmatch(fname, patt):
|
| 79 |
+
is_in_whitelist = True
|
| 80 |
+
break
|
| 81 |
+
for patt in unicode_strict_whitelist:
|
| 82 |
+
if fnmatch.fnmatch(fname, patt):
|
| 83 |
+
is_in_strict_whitelist = True
|
| 84 |
+
is_in_whitelist = True
|
| 85 |
+
break
|
| 86 |
+
|
| 87 |
+
if is_in_whitelist:
|
| 88 |
+
for idx, line in enumerate(test_file):
|
| 89 |
+
try:
|
| 90 |
+
line.encode(encoding='ascii')
|
| 91 |
+
except (UnicodeEncodeError, UnicodeDecodeError):
|
| 92 |
+
has_unicode = True
|
| 93 |
+
|
| 94 |
+
if not has_unicode and not is_in_strict_whitelist:
|
| 95 |
+
assert False, message_unicode_D % fname
|
| 96 |
+
|
| 97 |
+
else:
|
| 98 |
+
for idx, line in enumerate(test_file):
|
| 99 |
+
try:
|
| 100 |
+
line.encode(encoding='ascii')
|
| 101 |
+
except (UnicodeEncodeError, UnicodeDecodeError):
|
| 102 |
+
assert False, message_unicode_B % (fname, idx + 1)
|
mplug_owl2/lib/python3.10/site-packages/sympy/testing/randtest.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
.. deprecated:: 1.10
|
| 3 |
+
|
| 4 |
+
``sympy.testing.randtest`` functions have been moved to
|
| 5 |
+
:mod:`sympy.core.random`.
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
from sympy.utilities.exceptions import sympy_deprecation_warning
|
| 9 |
+
|
| 10 |
+
sympy_deprecation_warning("The sympy.testing.randtest submodule is deprecated. Use sympy.core.random instead.",
|
| 11 |
+
deprecated_since_version="1.10",
|
| 12 |
+
active_deprecations_target="deprecated-sympy-testing-randtest")
|
| 13 |
+
|
| 14 |
+
from sympy.core.random import ( # noqa:F401
|
| 15 |
+
random_complex_number,
|
| 16 |
+
verify_numerically,
|
| 17 |
+
test_derivative_numerically,
|
| 18 |
+
_randrange,
|
| 19 |
+
_randint)
|
mplug_owl2/lib/python3.10/site-packages/sympy/testing/runtests.py
ADDED
|
@@ -0,0 +1,2409 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This is our testing framework.
|
| 3 |
+
|
| 4 |
+
Goals:
|
| 5 |
+
|
| 6 |
+
* it should be compatible with py.test and operate very similarly
|
| 7 |
+
(or identically)
|
| 8 |
+
* does not require any external dependencies
|
| 9 |
+
* preferably all the functionality should be in this file only
|
| 10 |
+
* no magic, just import the test file and execute the test functions, that's it
|
| 11 |
+
* portable
|
| 12 |
+
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
import sys
|
| 17 |
+
import platform
|
| 18 |
+
import inspect
|
| 19 |
+
import traceback
|
| 20 |
+
import pdb
|
| 21 |
+
import re
|
| 22 |
+
import linecache
|
| 23 |
+
import time
|
| 24 |
+
from fnmatch import fnmatch
|
| 25 |
+
from timeit import default_timer as clock
|
| 26 |
+
import doctest as pdoctest # avoid clashing with our doctest() function
|
| 27 |
+
from doctest import DocTestFinder, DocTestRunner
|
| 28 |
+
import random
|
| 29 |
+
import subprocess
|
| 30 |
+
import shutil
|
| 31 |
+
import signal
|
| 32 |
+
import stat
|
| 33 |
+
import tempfile
|
| 34 |
+
import warnings
|
| 35 |
+
from contextlib import contextmanager
|
| 36 |
+
from inspect import unwrap
|
| 37 |
+
|
| 38 |
+
from sympy.core.cache import clear_cache
|
| 39 |
+
from sympy.external import import_module
|
| 40 |
+
from sympy.external.gmpy import GROUND_TYPES
|
| 41 |
+
|
| 42 |
+
IS_WINDOWS = (os.name == 'nt')
|
| 43 |
+
ON_CI = os.getenv('CI', None)
|
| 44 |
+
|
| 45 |
+
# empirically generated list of the proportion of time spent running
|
| 46 |
+
# an even split of tests. This should periodically be regenerated.
|
| 47 |
+
# A list of [.6, .1, .3] would mean that if the tests are evenly split
|
| 48 |
+
# into '1/3', '2/3', '3/3', the first split would take 60% of the time,
|
| 49 |
+
# the second 10% and the third 30%. These lists are normalized to sum
|
| 50 |
+
# to 1, so [60, 10, 30] has the same behavior as [6, 1, 3] or [.6, .1, .3].
|
| 51 |
+
#
|
| 52 |
+
# This list can be generated with the code:
|
| 53 |
+
# from time import time
|
| 54 |
+
# import sympy
|
| 55 |
+
# import os
|
| 56 |
+
# os.environ["CI"] = 'true' # Mock CI to get more correct densities
|
| 57 |
+
# delays, num_splits = [], 30
|
| 58 |
+
# for i in range(1, num_splits + 1):
|
| 59 |
+
# tic = time()
|
| 60 |
+
# sympy.test(split='{}/{}'.format(i, num_splits), time_balance=False) # Add slow=True for slow tests
|
| 61 |
+
# delays.append(time() - tic)
|
| 62 |
+
# tot = sum(delays)
|
| 63 |
+
# print([round(x / tot, 4) for x in delays])
|
| 64 |
+
SPLIT_DENSITY = [
|
| 65 |
+
0.0059, 0.0027, 0.0068, 0.0011, 0.0006,
|
| 66 |
+
0.0058, 0.0047, 0.0046, 0.004, 0.0257,
|
| 67 |
+
0.0017, 0.0026, 0.004, 0.0032, 0.0016,
|
| 68 |
+
0.0015, 0.0004, 0.0011, 0.0016, 0.0014,
|
| 69 |
+
0.0077, 0.0137, 0.0217, 0.0074, 0.0043,
|
| 70 |
+
0.0067, 0.0236, 0.0004, 0.1189, 0.0142,
|
| 71 |
+
0.0234, 0.0003, 0.0003, 0.0047, 0.0006,
|
| 72 |
+
0.0013, 0.0004, 0.0008, 0.0007, 0.0006,
|
| 73 |
+
0.0139, 0.0013, 0.0007, 0.0051, 0.002,
|
| 74 |
+
0.0004, 0.0005, 0.0213, 0.0048, 0.0016,
|
| 75 |
+
0.0012, 0.0014, 0.0024, 0.0015, 0.0004,
|
| 76 |
+
0.0005, 0.0007, 0.011, 0.0062, 0.0015,
|
| 77 |
+
0.0021, 0.0049, 0.0006, 0.0006, 0.0011,
|
| 78 |
+
0.0006, 0.0019, 0.003, 0.0044, 0.0054,
|
| 79 |
+
0.0057, 0.0049, 0.0016, 0.0006, 0.0009,
|
| 80 |
+
0.0006, 0.0012, 0.0006, 0.0149, 0.0532,
|
| 81 |
+
0.0076, 0.0041, 0.0024, 0.0135, 0.0081,
|
| 82 |
+
0.2209, 0.0459, 0.0438, 0.0488, 0.0137,
|
| 83 |
+
0.002, 0.0003, 0.0008, 0.0039, 0.0024,
|
| 84 |
+
0.0005, 0.0004, 0.003, 0.056, 0.0026]
|
| 85 |
+
SPLIT_DENSITY_SLOW = [0.0086, 0.0004, 0.0568, 0.0003, 0.0032, 0.0005, 0.0004, 0.0013, 0.0016, 0.0648, 0.0198, 0.1285, 0.098, 0.0005, 0.0064, 0.0003, 0.0004, 0.0026, 0.0007, 0.0051, 0.0089, 0.0024, 0.0033, 0.0057, 0.0005, 0.0003, 0.001, 0.0045, 0.0091, 0.0006, 0.0005, 0.0321, 0.0059, 0.1105, 0.216, 0.1489, 0.0004, 0.0003, 0.0006, 0.0483]
|
| 86 |
+
|
| 87 |
+
class Skipped(Exception):
|
| 88 |
+
pass
|
| 89 |
+
|
| 90 |
+
class TimeOutError(Exception):
|
| 91 |
+
pass
|
| 92 |
+
|
| 93 |
+
class DependencyError(Exception):
|
| 94 |
+
pass
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def _indent(s, indent=4):
|
| 98 |
+
"""
|
| 99 |
+
Add the given number of space characters to the beginning of
|
| 100 |
+
every non-blank line in ``s``, and return the result.
|
| 101 |
+
If the string ``s`` is Unicode, it is encoded using the stdout
|
| 102 |
+
encoding and the ``backslashreplace`` error handler.
|
| 103 |
+
"""
|
| 104 |
+
# This regexp matches the start of non-blank lines:
|
| 105 |
+
return re.sub('(?m)^(?!$)', indent*' ', s)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
pdoctest._indent = _indent # type: ignore
|
| 109 |
+
|
| 110 |
+
# override reporter to maintain windows and python3
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def _report_failure(self, out, test, example, got):
|
| 114 |
+
"""
|
| 115 |
+
Report that the given example failed.
|
| 116 |
+
"""
|
| 117 |
+
s = self._checker.output_difference(example, got, self.optionflags)
|
| 118 |
+
s = s.encode('raw_unicode_escape').decode('utf8', 'ignore')
|
| 119 |
+
out(self._failure_header(test, example) + s)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
if IS_WINDOWS:
|
| 123 |
+
DocTestRunner.report_failure = _report_failure # type: ignore
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def convert_to_native_paths(lst):
|
| 127 |
+
"""
|
| 128 |
+
Converts a list of '/' separated paths into a list of
|
| 129 |
+
native (os.sep separated) paths and converts to lowercase
|
| 130 |
+
if the system is case insensitive.
|
| 131 |
+
"""
|
| 132 |
+
newlst = []
|
| 133 |
+
for i, rv in enumerate(lst):
|
| 134 |
+
rv = os.path.join(*rv.split("/"))
|
| 135 |
+
# on windows the slash after the colon is dropped
|
| 136 |
+
if sys.platform == "win32":
|
| 137 |
+
pos = rv.find(':')
|
| 138 |
+
if pos != -1:
|
| 139 |
+
if rv[pos + 1] != '\\':
|
| 140 |
+
rv = rv[:pos + 1] + '\\' + rv[pos + 1:]
|
| 141 |
+
newlst.append(os.path.normcase(rv))
|
| 142 |
+
return newlst
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def get_sympy_dir():
|
| 146 |
+
"""
|
| 147 |
+
Returns the root SymPy directory and set the global value
|
| 148 |
+
indicating whether the system is case sensitive or not.
|
| 149 |
+
"""
|
| 150 |
+
this_file = os.path.abspath(__file__)
|
| 151 |
+
sympy_dir = os.path.join(os.path.dirname(this_file), "..", "..")
|
| 152 |
+
sympy_dir = os.path.normpath(sympy_dir)
|
| 153 |
+
return os.path.normcase(sympy_dir)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def setup_pprint(disable_line_wrap=True):
|
| 157 |
+
from sympy.interactive.printing import init_printing
|
| 158 |
+
from sympy.printing.pretty.pretty import pprint_use_unicode
|
| 159 |
+
import sympy.interactive.printing as interactive_printing
|
| 160 |
+
from sympy.printing.pretty import stringpict
|
| 161 |
+
|
| 162 |
+
# Prevent init_printing() in doctests from affecting other doctests
|
| 163 |
+
interactive_printing.NO_GLOBAL = True
|
| 164 |
+
|
| 165 |
+
# force pprint to be in ascii mode in doctests
|
| 166 |
+
use_unicode_prev = pprint_use_unicode(False)
|
| 167 |
+
|
| 168 |
+
# disable line wrapping for pprint() outputs
|
| 169 |
+
wrap_line_prev = stringpict._GLOBAL_WRAP_LINE
|
| 170 |
+
if disable_line_wrap:
|
| 171 |
+
stringpict._GLOBAL_WRAP_LINE = False
|
| 172 |
+
|
| 173 |
+
# hook our nice, hash-stable strprinter
|
| 174 |
+
init_printing(pretty_print=False)
|
| 175 |
+
|
| 176 |
+
return use_unicode_prev, wrap_line_prev
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
@contextmanager
|
| 180 |
+
def raise_on_deprecated():
|
| 181 |
+
"""Context manager to make DeprecationWarning raise an error
|
| 182 |
+
|
| 183 |
+
This is to catch SymPyDeprecationWarning from library code while running
|
| 184 |
+
tests and doctests. It is important to use this context manager around
|
| 185 |
+
each individual test/doctest in case some tests modify the warning
|
| 186 |
+
filters.
|
| 187 |
+
"""
|
| 188 |
+
with warnings.catch_warnings():
|
| 189 |
+
warnings.filterwarnings('error', '.*', DeprecationWarning, module='sympy.*')
|
| 190 |
+
yield
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def run_in_subprocess_with_hash_randomization(
|
| 194 |
+
function, function_args=(),
|
| 195 |
+
function_kwargs=None, command=sys.executable,
|
| 196 |
+
module='sympy.testing.runtests', force=False):
|
| 197 |
+
"""
|
| 198 |
+
Run a function in a Python subprocess with hash randomization enabled.
|
| 199 |
+
|
| 200 |
+
If hash randomization is not supported by the version of Python given, it
|
| 201 |
+
returns False. Otherwise, it returns the exit value of the command. The
|
| 202 |
+
function is passed to sys.exit(), so the return value of the function will
|
| 203 |
+
be the return value.
|
| 204 |
+
|
| 205 |
+
The environment variable PYTHONHASHSEED is used to seed Python's hash
|
| 206 |
+
randomization. If it is set, this function will return False, because
|
| 207 |
+
starting a new subprocess is unnecessary in that case. If it is not set,
|
| 208 |
+
one is set at random, and the tests are run. Note that if this
|
| 209 |
+
environment variable is set when Python starts, hash randomization is
|
| 210 |
+
automatically enabled. To force a subprocess to be created even if
|
| 211 |
+
PYTHONHASHSEED is set, pass ``force=True``. This flag will not force a
|
| 212 |
+
subprocess in Python versions that do not support hash randomization (see
|
| 213 |
+
below), because those versions of Python do not support the ``-R`` flag.
|
| 214 |
+
|
| 215 |
+
``function`` should be a string name of a function that is importable from
|
| 216 |
+
the module ``module``, like "_test". The default for ``module`` is
|
| 217 |
+
"sympy.testing.runtests". ``function_args`` and ``function_kwargs``
|
| 218 |
+
should be a repr-able tuple and dict, respectively. The default Python
|
| 219 |
+
command is sys.executable, which is the currently running Python command.
|
| 220 |
+
|
| 221 |
+
This function is necessary because the seed for hash randomization must be
|
| 222 |
+
set by the environment variable before Python starts. Hence, in order to
|
| 223 |
+
use a predetermined seed for tests, we must start Python in a separate
|
| 224 |
+
subprocess.
|
| 225 |
+
|
| 226 |
+
Hash randomization was added in the minor Python versions 2.6.8, 2.7.3,
|
| 227 |
+
3.1.5, and 3.2.3, and is enabled by default in all Python versions after
|
| 228 |
+
and including 3.3.0.
|
| 229 |
+
|
| 230 |
+
Examples
|
| 231 |
+
========
|
| 232 |
+
|
| 233 |
+
>>> from sympy.testing.runtests import (
|
| 234 |
+
... run_in_subprocess_with_hash_randomization)
|
| 235 |
+
>>> # run the core tests in verbose mode
|
| 236 |
+
>>> run_in_subprocess_with_hash_randomization("_test",
|
| 237 |
+
... function_args=("core",),
|
| 238 |
+
... function_kwargs={'verbose': True}) # doctest: +SKIP
|
| 239 |
+
# Will return 0 if sys.executable supports hash randomization and tests
|
| 240 |
+
# pass, 1 if they fail, and False if it does not support hash
|
| 241 |
+
# randomization.
|
| 242 |
+
|
| 243 |
+
"""
|
| 244 |
+
cwd = get_sympy_dir()
|
| 245 |
+
# Note, we must return False everywhere, not None, as subprocess.call will
|
| 246 |
+
# sometimes return None.
|
| 247 |
+
|
| 248 |
+
# First check if the Python version supports hash randomization
|
| 249 |
+
# If it does not have this support, it won't recognize the -R flag
|
| 250 |
+
p = subprocess.Popen([command, "-RV"], stdout=subprocess.PIPE,
|
| 251 |
+
stderr=subprocess.STDOUT, cwd=cwd)
|
| 252 |
+
p.communicate()
|
| 253 |
+
if p.returncode != 0:
|
| 254 |
+
return False
|
| 255 |
+
|
| 256 |
+
hash_seed = os.getenv("PYTHONHASHSEED")
|
| 257 |
+
if not hash_seed:
|
| 258 |
+
os.environ["PYTHONHASHSEED"] = str(random.randrange(2**32))
|
| 259 |
+
else:
|
| 260 |
+
if not force:
|
| 261 |
+
return False
|
| 262 |
+
|
| 263 |
+
function_kwargs = function_kwargs or {}
|
| 264 |
+
|
| 265 |
+
# Now run the command
|
| 266 |
+
commandstring = ("import sys; from %s import %s;sys.exit(%s(*%s, **%s))" %
|
| 267 |
+
(module, function, function, repr(function_args),
|
| 268 |
+
repr(function_kwargs)))
|
| 269 |
+
|
| 270 |
+
try:
|
| 271 |
+
p = subprocess.Popen([command, "-R", "-c", commandstring], cwd=cwd)
|
| 272 |
+
p.communicate()
|
| 273 |
+
except KeyboardInterrupt:
|
| 274 |
+
p.wait()
|
| 275 |
+
finally:
|
| 276 |
+
# Put the environment variable back, so that it reads correctly for
|
| 277 |
+
# the current Python process.
|
| 278 |
+
if hash_seed is None:
|
| 279 |
+
del os.environ["PYTHONHASHSEED"]
|
| 280 |
+
else:
|
| 281 |
+
os.environ["PYTHONHASHSEED"] = hash_seed
|
| 282 |
+
return p.returncode
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def run_all_tests(test_args=(), test_kwargs=None,
|
| 286 |
+
doctest_args=(), doctest_kwargs=None,
|
| 287 |
+
examples_args=(), examples_kwargs=None):
|
| 288 |
+
"""
|
| 289 |
+
Run all tests.
|
| 290 |
+
|
| 291 |
+
Right now, this runs the regular tests (bin/test), the doctests
|
| 292 |
+
(bin/doctest), and the examples (examples/all.py).
|
| 293 |
+
|
| 294 |
+
This is what ``setup.py test`` uses.
|
| 295 |
+
|
| 296 |
+
You can pass arguments and keyword arguments to the test functions that
|
| 297 |
+
support them (for now, test, doctest, and the examples). See the
|
| 298 |
+
docstrings of those functions for a description of the available options.
|
| 299 |
+
|
| 300 |
+
For example, to run the solvers tests with colors turned off:
|
| 301 |
+
|
| 302 |
+
>>> from sympy.testing.runtests import run_all_tests
|
| 303 |
+
>>> run_all_tests(test_args=("solvers",),
|
| 304 |
+
... test_kwargs={"colors:False"}) # doctest: +SKIP
|
| 305 |
+
|
| 306 |
+
"""
|
| 307 |
+
tests_successful = True
|
| 308 |
+
|
| 309 |
+
test_kwargs = test_kwargs or {}
|
| 310 |
+
doctest_kwargs = doctest_kwargs or {}
|
| 311 |
+
examples_kwargs = examples_kwargs or {'quiet': True}
|
| 312 |
+
|
| 313 |
+
try:
|
| 314 |
+
# Regular tests
|
| 315 |
+
if not test(*test_args, **test_kwargs):
|
| 316 |
+
# some regular test fails, so set the tests_successful
|
| 317 |
+
# flag to false and continue running the doctests
|
| 318 |
+
tests_successful = False
|
| 319 |
+
|
| 320 |
+
# Doctests
|
| 321 |
+
print()
|
| 322 |
+
if not doctest(*doctest_args, **doctest_kwargs):
|
| 323 |
+
tests_successful = False
|
| 324 |
+
|
| 325 |
+
# Examples
|
| 326 |
+
print()
|
| 327 |
+
sys.path.append("examples") # examples/all.py
|
| 328 |
+
from all import run_examples # type: ignore
|
| 329 |
+
if not run_examples(*examples_args, **examples_kwargs):
|
| 330 |
+
tests_successful = False
|
| 331 |
+
|
| 332 |
+
if tests_successful:
|
| 333 |
+
return
|
| 334 |
+
else:
|
| 335 |
+
# Return nonzero exit code
|
| 336 |
+
sys.exit(1)
|
| 337 |
+
except KeyboardInterrupt:
|
| 338 |
+
print()
|
| 339 |
+
print("DO *NOT* COMMIT!")
|
| 340 |
+
sys.exit(1)
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
def test(*paths, subprocess=True, rerun=0, **kwargs):
|
| 344 |
+
"""
|
| 345 |
+
Run tests in the specified test_*.py files.
|
| 346 |
+
|
| 347 |
+
Tests in a particular test_*.py file are run if any of the given strings
|
| 348 |
+
in ``paths`` matches a part of the test file's path. If ``paths=[]``,
|
| 349 |
+
tests in all test_*.py files are run.
|
| 350 |
+
|
| 351 |
+
Notes:
|
| 352 |
+
|
| 353 |
+
- If sort=False, tests are run in random order (not default).
|
| 354 |
+
- Paths can be entered in native system format or in unix,
|
| 355 |
+
forward-slash format.
|
| 356 |
+
- Files that are on the blacklist can be tested by providing
|
| 357 |
+
their path; they are only excluded if no paths are given.
|
| 358 |
+
|
| 359 |
+
**Explanation of test results**
|
| 360 |
+
|
| 361 |
+
====== ===============================================================
|
| 362 |
+
Output Meaning
|
| 363 |
+
====== ===============================================================
|
| 364 |
+
. passed
|
| 365 |
+
F failed
|
| 366 |
+
X XPassed (expected to fail but passed)
|
| 367 |
+
f XFAILed (expected to fail and indeed failed)
|
| 368 |
+
s skipped
|
| 369 |
+
w slow
|
| 370 |
+
T timeout (e.g., when ``--timeout`` is used)
|
| 371 |
+
K KeyboardInterrupt (when running the slow tests with ``--slow``,
|
| 372 |
+
you can interrupt one of them without killing the test runner)
|
| 373 |
+
====== ===============================================================
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
Colors have no additional meaning and are used just to facilitate
|
| 377 |
+
interpreting the output.
|
| 378 |
+
|
| 379 |
+
Examples
|
| 380 |
+
========
|
| 381 |
+
|
| 382 |
+
>>> import sympy
|
| 383 |
+
|
| 384 |
+
Run all tests:
|
| 385 |
+
|
| 386 |
+
>>> sympy.test() # doctest: +SKIP
|
| 387 |
+
|
| 388 |
+
Run one file:
|
| 389 |
+
|
| 390 |
+
>>> sympy.test("sympy/core/tests/test_basic.py") # doctest: +SKIP
|
| 391 |
+
>>> sympy.test("_basic") # doctest: +SKIP
|
| 392 |
+
|
| 393 |
+
Run all tests in sympy/functions/ and some particular file:
|
| 394 |
+
|
| 395 |
+
>>> sympy.test("sympy/core/tests/test_basic.py",
|
| 396 |
+
... "sympy/functions") # doctest: +SKIP
|
| 397 |
+
|
| 398 |
+
Run all tests in sympy/core and sympy/utilities:
|
| 399 |
+
|
| 400 |
+
>>> sympy.test("/core", "/util") # doctest: +SKIP
|
| 401 |
+
|
| 402 |
+
Run specific test from a file:
|
| 403 |
+
|
| 404 |
+
>>> sympy.test("sympy/core/tests/test_basic.py",
|
| 405 |
+
... kw="test_equality") # doctest: +SKIP
|
| 406 |
+
|
| 407 |
+
Run specific test from any file:
|
| 408 |
+
|
| 409 |
+
>>> sympy.test(kw="subs") # doctest: +SKIP
|
| 410 |
+
|
| 411 |
+
Run the tests with verbose mode on:
|
| 412 |
+
|
| 413 |
+
>>> sympy.test(verbose=True) # doctest: +SKIP
|
| 414 |
+
|
| 415 |
+
Do not sort the test output:
|
| 416 |
+
|
| 417 |
+
>>> sympy.test(sort=False) # doctest: +SKIP
|
| 418 |
+
|
| 419 |
+
Turn on post-mortem pdb:
|
| 420 |
+
|
| 421 |
+
>>> sympy.test(pdb=True) # doctest: +SKIP
|
| 422 |
+
|
| 423 |
+
Turn off colors:
|
| 424 |
+
|
| 425 |
+
>>> sympy.test(colors=False) # doctest: +SKIP
|
| 426 |
+
|
| 427 |
+
Force colors, even when the output is not to a terminal (this is useful,
|
| 428 |
+
e.g., if you are piping to ``less -r`` and you still want colors)
|
| 429 |
+
|
| 430 |
+
>>> sympy.test(force_colors=False) # doctest: +SKIP
|
| 431 |
+
|
| 432 |
+
The traceback verboseness can be set to "short" or "no" (default is
|
| 433 |
+
"short")
|
| 434 |
+
|
| 435 |
+
>>> sympy.test(tb='no') # doctest: +SKIP
|
| 436 |
+
|
| 437 |
+
The ``split`` option can be passed to split the test run into parts. The
|
| 438 |
+
split currently only splits the test files, though this may change in the
|
| 439 |
+
future. ``split`` should be a string of the form 'a/b', which will run
|
| 440 |
+
part ``a`` of ``b``. For instance, to run the first half of the test suite:
|
| 441 |
+
|
| 442 |
+
>>> sympy.test(split='1/2') # doctest: +SKIP
|
| 443 |
+
|
| 444 |
+
The ``time_balance`` option can be passed in conjunction with ``split``.
|
| 445 |
+
If ``time_balance=True`` (the default for ``sympy.test``), SymPy will attempt
|
| 446 |
+
to split the tests such that each split takes equal time. This heuristic
|
| 447 |
+
for balancing is based on pre-recorded test data.
|
| 448 |
+
|
| 449 |
+
>>> sympy.test(split='1/2', time_balance=True) # doctest: +SKIP
|
| 450 |
+
|
| 451 |
+
You can disable running the tests in a separate subprocess using
|
| 452 |
+
``subprocess=False``. This is done to support seeding hash randomization,
|
| 453 |
+
which is enabled by default in the Python versions where it is supported.
|
| 454 |
+
If subprocess=False, hash randomization is enabled/disabled according to
|
| 455 |
+
whether it has been enabled or not in the calling Python process.
|
| 456 |
+
However, even if it is enabled, the seed cannot be printed unless it is
|
| 457 |
+
called from a new Python process.
|
| 458 |
+
|
| 459 |
+
Hash randomization was added in the minor Python versions 2.6.8, 2.7.3,
|
| 460 |
+
3.1.5, and 3.2.3, and is enabled by default in all Python versions after
|
| 461 |
+
and including 3.3.0.
|
| 462 |
+
|
| 463 |
+
If hash randomization is not supported ``subprocess=False`` is used
|
| 464 |
+
automatically.
|
| 465 |
+
|
| 466 |
+
>>> sympy.test(subprocess=False) # doctest: +SKIP
|
| 467 |
+
|
| 468 |
+
To set the hash randomization seed, set the environment variable
|
| 469 |
+
``PYTHONHASHSEED`` before running the tests. This can be done from within
|
| 470 |
+
Python using
|
| 471 |
+
|
| 472 |
+
>>> import os
|
| 473 |
+
>>> os.environ['PYTHONHASHSEED'] = '42' # doctest: +SKIP
|
| 474 |
+
|
| 475 |
+
Or from the command line using
|
| 476 |
+
|
| 477 |
+
$ PYTHONHASHSEED=42 ./bin/test
|
| 478 |
+
|
| 479 |
+
If the seed is not set, a random seed will be chosen.
|
| 480 |
+
|
| 481 |
+
Note that to reproduce the same hash values, you must use both the same seed
|
| 482 |
+
as well as the same architecture (32-bit vs. 64-bit).
|
| 483 |
+
|
| 484 |
+
"""
|
| 485 |
+
# count up from 0, do not print 0
|
| 486 |
+
print_counter = lambda i : (print("rerun %d" % (rerun-i))
|
| 487 |
+
if rerun-i else None)
|
| 488 |
+
|
| 489 |
+
if subprocess:
|
| 490 |
+
# loop backwards so last i is 0
|
| 491 |
+
for i in range(rerun, -1, -1):
|
| 492 |
+
print_counter(i)
|
| 493 |
+
ret = run_in_subprocess_with_hash_randomization("_test",
|
| 494 |
+
function_args=paths, function_kwargs=kwargs)
|
| 495 |
+
if ret is False:
|
| 496 |
+
break
|
| 497 |
+
val = not bool(ret)
|
| 498 |
+
# exit on the first failure or if done
|
| 499 |
+
if not val or i == 0:
|
| 500 |
+
return val
|
| 501 |
+
|
| 502 |
+
# rerun even if hash randomization is not supported
|
| 503 |
+
for i in range(rerun, -1, -1):
|
| 504 |
+
print_counter(i)
|
| 505 |
+
val = not bool(_test(*paths, **kwargs))
|
| 506 |
+
if not val or i == 0:
|
| 507 |
+
return val
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
def _test(*paths,
|
| 511 |
+
verbose=False, tb="short", kw=None, pdb=False, colors=True,
|
| 512 |
+
force_colors=False, sort=True, seed=None, timeout=False,
|
| 513 |
+
fail_on_timeout=False, slow=False, enhance_asserts=False, split=None,
|
| 514 |
+
time_balance=True, blacklist=(),
|
| 515 |
+
fast_threshold=None, slow_threshold=None):
|
| 516 |
+
"""
|
| 517 |
+
Internal function that actually runs the tests.
|
| 518 |
+
|
| 519 |
+
All keyword arguments from ``test()`` are passed to this function except for
|
| 520 |
+
``subprocess``.
|
| 521 |
+
|
| 522 |
+
Returns 0 if tests passed and 1 if they failed. See the docstring of
|
| 523 |
+
``test()`` for more information.
|
| 524 |
+
"""
|
| 525 |
+
kw = kw or ()
|
| 526 |
+
# ensure that kw is a tuple
|
| 527 |
+
if isinstance(kw, str):
|
| 528 |
+
kw = (kw,)
|
| 529 |
+
post_mortem = pdb
|
| 530 |
+
if seed is None:
|
| 531 |
+
seed = random.randrange(100000000)
|
| 532 |
+
if ON_CI and timeout is False:
|
| 533 |
+
timeout = 595
|
| 534 |
+
fail_on_timeout = True
|
| 535 |
+
if ON_CI:
|
| 536 |
+
blacklist = list(blacklist) + ['sympy/plotting/pygletplot/tests']
|
| 537 |
+
blacklist = convert_to_native_paths(blacklist)
|
| 538 |
+
r = PyTestReporter(verbose=verbose, tb=tb, colors=colors,
|
| 539 |
+
force_colors=force_colors, split=split)
|
| 540 |
+
# This won't strictly run the test for the corresponding file, but it is
|
| 541 |
+
# good enough for copying and pasting the failing test.
|
| 542 |
+
_paths = []
|
| 543 |
+
for path in paths:
|
| 544 |
+
if '::' in path:
|
| 545 |
+
path, _kw = path.split('::', 1)
|
| 546 |
+
kw += (_kw,)
|
| 547 |
+
_paths.append(path)
|
| 548 |
+
paths = _paths
|
| 549 |
+
|
| 550 |
+
t = SymPyTests(r, kw, post_mortem, seed,
|
| 551 |
+
fast_threshold=fast_threshold,
|
| 552 |
+
slow_threshold=slow_threshold)
|
| 553 |
+
|
| 554 |
+
test_files = t.get_test_files('sympy')
|
| 555 |
+
|
| 556 |
+
not_blacklisted = [f for f in test_files
|
| 557 |
+
if not any(b in f for b in blacklist)]
|
| 558 |
+
|
| 559 |
+
if len(paths) == 0:
|
| 560 |
+
matched = not_blacklisted
|
| 561 |
+
else:
|
| 562 |
+
paths = convert_to_native_paths(paths)
|
| 563 |
+
matched = []
|
| 564 |
+
for f in not_blacklisted:
|
| 565 |
+
basename = os.path.basename(f)
|
| 566 |
+
for p in paths:
|
| 567 |
+
if p in f or fnmatch(basename, p):
|
| 568 |
+
matched.append(f)
|
| 569 |
+
break
|
| 570 |
+
|
| 571 |
+
density = None
|
| 572 |
+
if time_balance:
|
| 573 |
+
if slow:
|
| 574 |
+
density = SPLIT_DENSITY_SLOW
|
| 575 |
+
else:
|
| 576 |
+
density = SPLIT_DENSITY
|
| 577 |
+
|
| 578 |
+
if split:
|
| 579 |
+
matched = split_list(matched, split, density=density)
|
| 580 |
+
|
| 581 |
+
t._testfiles.extend(matched)
|
| 582 |
+
|
| 583 |
+
return int(not t.test(sort=sort, timeout=timeout, slow=slow,
|
| 584 |
+
enhance_asserts=enhance_asserts, fail_on_timeout=fail_on_timeout))
|
| 585 |
+
|
| 586 |
+
|
| 587 |
+
def doctest(*paths, subprocess=True, rerun=0, **kwargs):
|
| 588 |
+
r"""
|
| 589 |
+
Runs doctests in all \*.py files in the SymPy directory which match
|
| 590 |
+
any of the given strings in ``paths`` or all tests if paths=[].
|
| 591 |
+
|
| 592 |
+
Notes:
|
| 593 |
+
|
| 594 |
+
- Paths can be entered in native system format or in unix,
|
| 595 |
+
forward-slash format.
|
| 596 |
+
- Files that are on the blacklist can be tested by providing
|
| 597 |
+
their path; they are only excluded if no paths are given.
|
| 598 |
+
|
| 599 |
+
Examples
|
| 600 |
+
========
|
| 601 |
+
|
| 602 |
+
>>> import sympy
|
| 603 |
+
|
| 604 |
+
Run all tests:
|
| 605 |
+
|
| 606 |
+
>>> sympy.doctest() # doctest: +SKIP
|
| 607 |
+
|
| 608 |
+
Run one file:
|
| 609 |
+
|
| 610 |
+
>>> sympy.doctest("sympy/core/basic.py") # doctest: +SKIP
|
| 611 |
+
>>> sympy.doctest("polynomial.rst") # doctest: +SKIP
|
| 612 |
+
|
| 613 |
+
Run all tests in sympy/functions/ and some particular file:
|
| 614 |
+
|
| 615 |
+
>>> sympy.doctest("/functions", "basic.py") # doctest: +SKIP
|
| 616 |
+
|
| 617 |
+
Run any file having polynomial in its name, doc/src/modules/polynomial.rst,
|
| 618 |
+
sympy/functions/special/polynomials.py, and sympy/polys/polynomial.py:
|
| 619 |
+
|
| 620 |
+
>>> sympy.doctest("polynomial") # doctest: +SKIP
|
| 621 |
+
|
| 622 |
+
The ``split`` option can be passed to split the test run into parts. The
|
| 623 |
+
split currently only splits the test files, though this may change in the
|
| 624 |
+
future. ``split`` should be a string of the form 'a/b', which will run
|
| 625 |
+
part ``a`` of ``b``. Note that the regular doctests and the Sphinx
|
| 626 |
+
doctests are split independently. For instance, to run the first half of
|
| 627 |
+
the test suite:
|
| 628 |
+
|
| 629 |
+
>>> sympy.doctest(split='1/2') # doctest: +SKIP
|
| 630 |
+
|
| 631 |
+
The ``subprocess`` and ``verbose`` options are the same as with the function
|
| 632 |
+
``test()`` (see the docstring of that function for more information) except
|
| 633 |
+
that ``verbose`` may also be set equal to ``2`` in order to print
|
| 634 |
+
individual doctest lines, as they are being tested.
|
| 635 |
+
"""
|
| 636 |
+
# count up from 0, do not print 0
|
| 637 |
+
print_counter = lambda i : (print("rerun %d" % (rerun-i))
|
| 638 |
+
if rerun-i else None)
|
| 639 |
+
|
| 640 |
+
if subprocess:
|
| 641 |
+
# loop backwards so last i is 0
|
| 642 |
+
for i in range(rerun, -1, -1):
|
| 643 |
+
print_counter(i)
|
| 644 |
+
ret = run_in_subprocess_with_hash_randomization("_doctest",
|
| 645 |
+
function_args=paths, function_kwargs=kwargs)
|
| 646 |
+
if ret is False:
|
| 647 |
+
break
|
| 648 |
+
val = not bool(ret)
|
| 649 |
+
# exit on the first failure or if done
|
| 650 |
+
if not val or i == 0:
|
| 651 |
+
return val
|
| 652 |
+
|
| 653 |
+
# rerun even if hash randomization is not supported
|
| 654 |
+
for i in range(rerun, -1, -1):
|
| 655 |
+
print_counter(i)
|
| 656 |
+
val = not bool(_doctest(*paths, **kwargs))
|
| 657 |
+
if not val or i == 0:
|
| 658 |
+
return val
|
| 659 |
+
|
| 660 |
+
|
| 661 |
+
def _get_doctest_blacklist():
|
| 662 |
+
'''Get the default blacklist for the doctests'''
|
| 663 |
+
blacklist = []
|
| 664 |
+
|
| 665 |
+
blacklist.extend([
|
| 666 |
+
"doc/src/modules/plotting.rst", # generates live plots
|
| 667 |
+
"doc/src/modules/physics/mechanics/autolev_parser.rst",
|
| 668 |
+
"sympy/codegen/array_utils.py", # raises deprecation warning
|
| 669 |
+
"sympy/core/compatibility.py", # backwards compatibility shim, importing it triggers a deprecation warning
|
| 670 |
+
"sympy/core/trace.py", # backwards compatibility shim, importing it triggers a deprecation warning
|
| 671 |
+
"sympy/galgebra.py", # no longer part of SymPy
|
| 672 |
+
"sympy/parsing/autolev/_antlr/autolevlexer.py", # generated code
|
| 673 |
+
"sympy/parsing/autolev/_antlr/autolevlistener.py", # generated code
|
| 674 |
+
"sympy/parsing/autolev/_antlr/autolevparser.py", # generated code
|
| 675 |
+
"sympy/parsing/latex/_antlr/latexlexer.py", # generated code
|
| 676 |
+
"sympy/parsing/latex/_antlr/latexparser.py", # generated code
|
| 677 |
+
"sympy/plotting/pygletplot/__init__.py", # crashes on some systems
|
| 678 |
+
"sympy/plotting/pygletplot/plot.py", # crashes on some systems
|
| 679 |
+
"sympy/printing/ccode.py", # backwards compatibility shim, importing it breaks the codegen doctests
|
| 680 |
+
"sympy/printing/cxxcode.py", # backwards compatibility shim, importing it breaks the codegen doctests
|
| 681 |
+
"sympy/printing/fcode.py", # backwards compatibility shim, importing it breaks the codegen doctests
|
| 682 |
+
"sympy/testing/randtest.py", # backwards compatibility shim, importing it triggers a deprecation warning
|
| 683 |
+
"sympy/this.py", # prints text
|
| 684 |
+
])
|
| 685 |
+
# autolev parser tests
|
| 686 |
+
num = 12
|
| 687 |
+
for i in range (1, num+1):
|
| 688 |
+
blacklist.append("sympy/parsing/autolev/test-examples/ruletest" + str(i) + ".py")
|
| 689 |
+
blacklist.extend(["sympy/parsing/autolev/test-examples/pydy-example-repo/mass_spring_damper.py",
|
| 690 |
+
"sympy/parsing/autolev/test-examples/pydy-example-repo/chaos_pendulum.py",
|
| 691 |
+
"sympy/parsing/autolev/test-examples/pydy-example-repo/double_pendulum.py",
|
| 692 |
+
"sympy/parsing/autolev/test-examples/pydy-example-repo/non_min_pendulum.py"])
|
| 693 |
+
|
| 694 |
+
if import_module('numpy') is None:
|
| 695 |
+
blacklist.extend([
|
| 696 |
+
"sympy/plotting/experimental_lambdify.py",
|
| 697 |
+
"sympy/plotting/plot_implicit.py",
|
| 698 |
+
"examples/advanced/autowrap_integrators.py",
|
| 699 |
+
"examples/advanced/autowrap_ufuncify.py",
|
| 700 |
+
"examples/intermediate/sample.py",
|
| 701 |
+
"examples/intermediate/mplot2d.py",
|
| 702 |
+
"examples/intermediate/mplot3d.py",
|
| 703 |
+
"doc/src/modules/numeric-computation.rst",
|
| 704 |
+
"doc/src/explanation/best-practices.md",
|
| 705 |
+
"doc/src/tutorials/physics/biomechanics/biomechanical-model-example.rst",
|
| 706 |
+
"doc/src/tutorials/physics/biomechanics/biomechanics.rst",
|
| 707 |
+
])
|
| 708 |
+
else:
|
| 709 |
+
if import_module('matplotlib') is None:
|
| 710 |
+
blacklist.extend([
|
| 711 |
+
"examples/intermediate/mplot2d.py",
|
| 712 |
+
"examples/intermediate/mplot3d.py"
|
| 713 |
+
])
|
| 714 |
+
else:
|
| 715 |
+
# Use a non-windowed backend, so that the tests work on CI
|
| 716 |
+
import matplotlib
|
| 717 |
+
matplotlib.use('Agg')
|
| 718 |
+
|
| 719 |
+
if ON_CI or import_module('pyglet') is None:
|
| 720 |
+
blacklist.extend(["sympy/plotting/pygletplot"])
|
| 721 |
+
|
| 722 |
+
if import_module('aesara') is None:
|
| 723 |
+
blacklist.extend([
|
| 724 |
+
"sympy/printing/aesaracode.py",
|
| 725 |
+
"doc/src/modules/numeric-computation.rst",
|
| 726 |
+
])
|
| 727 |
+
|
| 728 |
+
if import_module('cupy') is None:
|
| 729 |
+
blacklist.extend([
|
| 730 |
+
"doc/src/modules/numeric-computation.rst",
|
| 731 |
+
])
|
| 732 |
+
|
| 733 |
+
if import_module('jax') is None:
|
| 734 |
+
blacklist.extend([
|
| 735 |
+
"doc/src/modules/numeric-computation.rst",
|
| 736 |
+
])
|
| 737 |
+
|
| 738 |
+
if import_module('antlr4') is None:
|
| 739 |
+
blacklist.extend([
|
| 740 |
+
"sympy/parsing/autolev/__init__.py",
|
| 741 |
+
"sympy/parsing/latex/_parse_latex_antlr.py",
|
| 742 |
+
])
|
| 743 |
+
|
| 744 |
+
if import_module('lfortran') is None:
|
| 745 |
+
#throws ImportError when lfortran not installed
|
| 746 |
+
blacklist.extend([
|
| 747 |
+
"sympy/parsing/sym_expr.py",
|
| 748 |
+
])
|
| 749 |
+
|
| 750 |
+
if import_module("scipy") is None:
|
| 751 |
+
# throws ModuleNotFoundError when scipy not installed
|
| 752 |
+
blacklist.extend([
|
| 753 |
+
"doc/src/guides/solving/solve-numerically.md",
|
| 754 |
+
"doc/src/guides/solving/solve-ode.md",
|
| 755 |
+
])
|
| 756 |
+
|
| 757 |
+
if import_module("numpy") is None:
|
| 758 |
+
# throws ModuleNotFoundError when numpy not installed
|
| 759 |
+
blacklist.extend([
|
| 760 |
+
"doc/src/guides/solving/solve-ode.md",
|
| 761 |
+
"doc/src/guides/solving/solve-numerically.md",
|
| 762 |
+
])
|
| 763 |
+
|
| 764 |
+
# disabled because of doctest failures in asmeurer's bot
|
| 765 |
+
blacklist.extend([
|
| 766 |
+
"sympy/utilities/autowrap.py",
|
| 767 |
+
"examples/advanced/autowrap_integrators.py",
|
| 768 |
+
"examples/advanced/autowrap_ufuncify.py"
|
| 769 |
+
])
|
| 770 |
+
|
| 771 |
+
blacklist.extend([
|
| 772 |
+
"sympy/conftest.py", # Depends on pytest
|
| 773 |
+
])
|
| 774 |
+
|
| 775 |
+
# These are deprecated stubs to be removed:
|
| 776 |
+
blacklist.extend([
|
| 777 |
+
"sympy/utilities/tmpfiles.py",
|
| 778 |
+
"sympy/utilities/pytest.py",
|
| 779 |
+
"sympy/utilities/runtests.py",
|
| 780 |
+
"sympy/utilities/quality_unicode.py",
|
| 781 |
+
"sympy/utilities/randtest.py",
|
| 782 |
+
])
|
| 783 |
+
|
| 784 |
+
blacklist = convert_to_native_paths(blacklist)
|
| 785 |
+
return blacklist
|
| 786 |
+
|
| 787 |
+
|
| 788 |
+
def _doctest(*paths, **kwargs):
|
| 789 |
+
"""
|
| 790 |
+
Internal function that actually runs the doctests.
|
| 791 |
+
|
| 792 |
+
All keyword arguments from ``doctest()`` are passed to this function
|
| 793 |
+
except for ``subprocess``.
|
| 794 |
+
|
| 795 |
+
Returns 0 if tests passed and 1 if they failed. See the docstrings of
|
| 796 |
+
``doctest()`` and ``test()`` for more information.
|
| 797 |
+
"""
|
| 798 |
+
from sympy.printing.pretty.pretty import pprint_use_unicode
|
| 799 |
+
from sympy.printing.pretty import stringpict
|
| 800 |
+
|
| 801 |
+
normal = kwargs.get("normal", False)
|
| 802 |
+
verbose = kwargs.get("verbose", False)
|
| 803 |
+
colors = kwargs.get("colors", True)
|
| 804 |
+
force_colors = kwargs.get("force_colors", False)
|
| 805 |
+
blacklist = kwargs.get("blacklist", [])
|
| 806 |
+
split = kwargs.get('split', None)
|
| 807 |
+
|
| 808 |
+
blacklist.extend(_get_doctest_blacklist())
|
| 809 |
+
|
| 810 |
+
# Use a non-windowed backend, so that the tests work on CI
|
| 811 |
+
if import_module('matplotlib') is not None:
|
| 812 |
+
import matplotlib
|
| 813 |
+
matplotlib.use('Agg')
|
| 814 |
+
|
| 815 |
+
# Disable warnings for external modules
|
| 816 |
+
import sympy.external
|
| 817 |
+
sympy.external.importtools.WARN_OLD_VERSION = False
|
| 818 |
+
sympy.external.importtools.WARN_NOT_INSTALLED = False
|
| 819 |
+
|
| 820 |
+
# Disable showing up of plots
|
| 821 |
+
from sympy.plotting.plot import unset_show
|
| 822 |
+
unset_show()
|
| 823 |
+
|
| 824 |
+
r = PyTestReporter(verbose, split=split, colors=colors,\
|
| 825 |
+
force_colors=force_colors)
|
| 826 |
+
t = SymPyDocTests(r, normal)
|
| 827 |
+
|
| 828 |
+
test_files = t.get_test_files('sympy')
|
| 829 |
+
test_files.extend(t.get_test_files('examples', init_only=False))
|
| 830 |
+
|
| 831 |
+
not_blacklisted = [f for f in test_files
|
| 832 |
+
if not any(b in f for b in blacklist)]
|
| 833 |
+
if len(paths) == 0:
|
| 834 |
+
matched = not_blacklisted
|
| 835 |
+
else:
|
| 836 |
+
# take only what was requested...but not blacklisted items
|
| 837 |
+
# and allow for partial match anywhere or fnmatch of name
|
| 838 |
+
paths = convert_to_native_paths(paths)
|
| 839 |
+
matched = []
|
| 840 |
+
for f in not_blacklisted:
|
| 841 |
+
basename = os.path.basename(f)
|
| 842 |
+
for p in paths:
|
| 843 |
+
if p in f or fnmatch(basename, p):
|
| 844 |
+
matched.append(f)
|
| 845 |
+
break
|
| 846 |
+
|
| 847 |
+
matched.sort()
|
| 848 |
+
|
| 849 |
+
if split:
|
| 850 |
+
matched = split_list(matched, split)
|
| 851 |
+
|
| 852 |
+
t._testfiles.extend(matched)
|
| 853 |
+
|
| 854 |
+
# run the tests and record the result for this *py portion of the tests
|
| 855 |
+
if t._testfiles:
|
| 856 |
+
failed = not t.test()
|
| 857 |
+
else:
|
| 858 |
+
failed = False
|
| 859 |
+
|
| 860 |
+
# N.B.
|
| 861 |
+
# --------------------------------------------------------------------
|
| 862 |
+
# Here we test *.rst and *.md files at or below doc/src. Code from these
|
| 863 |
+
# must be self supporting in terms of imports since there is no importing
|
| 864 |
+
# of necessary modules by doctest.testfile. If you try to pass *.py files
|
| 865 |
+
# through this they might fail because they will lack the needed imports
|
| 866 |
+
# and smarter parsing that can be done with source code.
|
| 867 |
+
#
|
| 868 |
+
test_files_rst = t.get_test_files('doc/src', '*.rst', init_only=False)
|
| 869 |
+
test_files_md = t.get_test_files('doc/src', '*.md', init_only=False)
|
| 870 |
+
test_files = test_files_rst + test_files_md
|
| 871 |
+
test_files.sort()
|
| 872 |
+
|
| 873 |
+
not_blacklisted = [f for f in test_files
|
| 874 |
+
if not any(b in f for b in blacklist)]
|
| 875 |
+
|
| 876 |
+
if len(paths) == 0:
|
| 877 |
+
matched = not_blacklisted
|
| 878 |
+
else:
|
| 879 |
+
# Take only what was requested as long as it's not on the blacklist.
|
| 880 |
+
# Paths were already made native in *py tests so don't repeat here.
|
| 881 |
+
# There's no chance of having a *py file slip through since we
|
| 882 |
+
# only have *rst files in test_files.
|
| 883 |
+
matched = []
|
| 884 |
+
for f in not_blacklisted:
|
| 885 |
+
basename = os.path.basename(f)
|
| 886 |
+
for p in paths:
|
| 887 |
+
if p in f or fnmatch(basename, p):
|
| 888 |
+
matched.append(f)
|
| 889 |
+
break
|
| 890 |
+
|
| 891 |
+
if split:
|
| 892 |
+
matched = split_list(matched, split)
|
| 893 |
+
|
| 894 |
+
first_report = True
|
| 895 |
+
for rst_file in matched:
|
| 896 |
+
if not os.path.isfile(rst_file):
|
| 897 |
+
continue
|
| 898 |
+
old_displayhook = sys.displayhook
|
| 899 |
+
try:
|
| 900 |
+
use_unicode_prev, wrap_line_prev = setup_pprint()
|
| 901 |
+
out = sympytestfile(
|
| 902 |
+
rst_file, module_relative=False, encoding='utf-8',
|
| 903 |
+
optionflags=pdoctest.ELLIPSIS | pdoctest.NORMALIZE_WHITESPACE |
|
| 904 |
+
pdoctest.IGNORE_EXCEPTION_DETAIL)
|
| 905 |
+
finally:
|
| 906 |
+
# make sure we return to the original displayhook in case some
|
| 907 |
+
# doctest has changed that
|
| 908 |
+
sys.displayhook = old_displayhook
|
| 909 |
+
# The NO_GLOBAL flag overrides the no_global flag to init_printing
|
| 910 |
+
# if True
|
| 911 |
+
import sympy.interactive.printing as interactive_printing
|
| 912 |
+
interactive_printing.NO_GLOBAL = False
|
| 913 |
+
pprint_use_unicode(use_unicode_prev)
|
| 914 |
+
stringpict._GLOBAL_WRAP_LINE = wrap_line_prev
|
| 915 |
+
|
| 916 |
+
rstfailed, tested = out
|
| 917 |
+
if tested:
|
| 918 |
+
failed = rstfailed or failed
|
| 919 |
+
if first_report:
|
| 920 |
+
first_report = False
|
| 921 |
+
msg = 'rst/md doctests start'
|
| 922 |
+
if not t._testfiles:
|
| 923 |
+
r.start(msg=msg)
|
| 924 |
+
else:
|
| 925 |
+
r.write_center(msg)
|
| 926 |
+
print()
|
| 927 |
+
# use as the id, everything past the first 'sympy'
|
| 928 |
+
file_id = rst_file[rst_file.find('sympy') + len('sympy') + 1:]
|
| 929 |
+
print(file_id, end=" ")
|
| 930 |
+
# get at least the name out so it is know who is being tested
|
| 931 |
+
wid = r.terminal_width - len(file_id) - 1 # update width
|
| 932 |
+
test_file = '[%s]' % (tested)
|
| 933 |
+
report = '[%s]' % (rstfailed or 'OK')
|
| 934 |
+
print(''.join(
|
| 935 |
+
[test_file, ' '*(wid - len(test_file) - len(report)), report])
|
| 936 |
+
)
|
| 937 |
+
|
| 938 |
+
# the doctests for *py will have printed this message already if there was
|
| 939 |
+
# a failure, so now only print it if there was intervening reporting by
|
| 940 |
+
# testing the *rst as evidenced by first_report no longer being True.
|
| 941 |
+
if not first_report and failed:
|
| 942 |
+
print()
|
| 943 |
+
print("DO *NOT* COMMIT!")
|
| 944 |
+
|
| 945 |
+
return int(failed)
|
| 946 |
+
|
| 947 |
+
sp = re.compile(r'([0-9]+)/([1-9][0-9]*)')
|
| 948 |
+
|
| 949 |
+
def split_list(l, split, density=None):
|
| 950 |
+
"""
|
| 951 |
+
Splits a list into part a of b
|
| 952 |
+
|
| 953 |
+
split should be a string of the form 'a/b'. For instance, '1/3' would give
|
| 954 |
+
the split one of three.
|
| 955 |
+
|
| 956 |
+
If the length of the list is not divisible by the number of splits, the
|
| 957 |
+
last split will have more items.
|
| 958 |
+
|
| 959 |
+
`density` may be specified as a list. If specified,
|
| 960 |
+
tests will be balanced so that each split has as equal-as-possible
|
| 961 |
+
amount of mass according to `density`.
|
| 962 |
+
|
| 963 |
+
>>> from sympy.testing.runtests import split_list
|
| 964 |
+
>>> a = list(range(10))
|
| 965 |
+
>>> split_list(a, '1/3')
|
| 966 |
+
[0, 1, 2]
|
| 967 |
+
>>> split_list(a, '2/3')
|
| 968 |
+
[3, 4, 5]
|
| 969 |
+
>>> split_list(a, '3/3')
|
| 970 |
+
[6, 7, 8, 9]
|
| 971 |
+
"""
|
| 972 |
+
m = sp.match(split)
|
| 973 |
+
if not m:
|
| 974 |
+
raise ValueError("split must be a string of the form a/b where a and b are ints")
|
| 975 |
+
i, t = map(int, m.groups())
|
| 976 |
+
|
| 977 |
+
if not density:
|
| 978 |
+
return l[(i - 1)*len(l)//t : i*len(l)//t]
|
| 979 |
+
|
| 980 |
+
# normalize density
|
| 981 |
+
tot = sum(density)
|
| 982 |
+
density = [x / tot for x in density]
|
| 983 |
+
|
| 984 |
+
def density_inv(x):
|
| 985 |
+
"""Interpolate the inverse to the cumulative
|
| 986 |
+
distribution function given by density"""
|
| 987 |
+
if x <= 0:
|
| 988 |
+
return 0
|
| 989 |
+
if x >= sum(density):
|
| 990 |
+
return 1
|
| 991 |
+
|
| 992 |
+
# find the first time the cumulative sum surpasses x
|
| 993 |
+
# and linearly interpolate
|
| 994 |
+
cumm = 0
|
| 995 |
+
for i, d in enumerate(density):
|
| 996 |
+
cumm += d
|
| 997 |
+
if cumm >= x:
|
| 998 |
+
break
|
| 999 |
+
frac = (d - (cumm - x)) / d
|
| 1000 |
+
return (i + frac) / len(density)
|
| 1001 |
+
|
| 1002 |
+
lower_frac = density_inv((i - 1) / t)
|
| 1003 |
+
higher_frac = density_inv(i / t)
|
| 1004 |
+
return l[int(lower_frac*len(l)) : int(higher_frac*len(l))]
|
| 1005 |
+
|
| 1006 |
+
from collections import namedtuple
|
| 1007 |
+
SymPyTestResults = namedtuple('SymPyTestResults', 'failed attempted')
|
| 1008 |
+
|
| 1009 |
+
def sympytestfile(filename, module_relative=True, name=None, package=None,
|
| 1010 |
+
globs=None, verbose=None, report=True, optionflags=0,
|
| 1011 |
+
extraglobs=None, raise_on_error=False,
|
| 1012 |
+
parser=pdoctest.DocTestParser(), encoding=None):
|
| 1013 |
+
|
| 1014 |
+
"""
|
| 1015 |
+
Test examples in the given file. Return (#failures, #tests).
|
| 1016 |
+
|
| 1017 |
+
Optional keyword arg ``module_relative`` specifies how filenames
|
| 1018 |
+
should be interpreted:
|
| 1019 |
+
|
| 1020 |
+
- If ``module_relative`` is True (the default), then ``filename``
|
| 1021 |
+
specifies a module-relative path. By default, this path is
|
| 1022 |
+
relative to the calling module's directory; but if the
|
| 1023 |
+
``package`` argument is specified, then it is relative to that
|
| 1024 |
+
package. To ensure os-independence, ``filename`` should use
|
| 1025 |
+
"/" characters to separate path segments, and should not
|
| 1026 |
+
be an absolute path (i.e., it may not begin with "/").
|
| 1027 |
+
|
| 1028 |
+
- If ``module_relative`` is False, then ``filename`` specifies an
|
| 1029 |
+
os-specific path. The path may be absolute or relative (to
|
| 1030 |
+
the current working directory).
|
| 1031 |
+
|
| 1032 |
+
Optional keyword arg ``name`` gives the name of the test; by default
|
| 1033 |
+
use the file's basename.
|
| 1034 |
+
|
| 1035 |
+
Optional keyword argument ``package`` is a Python package or the
|
| 1036 |
+
name of a Python package whose directory should be used as the
|
| 1037 |
+
base directory for a module relative filename. If no package is
|
| 1038 |
+
specified, then the calling module's directory is used as the base
|
| 1039 |
+
directory for module relative filenames. It is an error to
|
| 1040 |
+
specify ``package`` if ``module_relative`` is False.
|
| 1041 |
+
|
| 1042 |
+
Optional keyword arg ``globs`` gives a dict to be used as the globals
|
| 1043 |
+
when executing examples; by default, use {}. A copy of this dict
|
| 1044 |
+
is actually used for each docstring, so that each docstring's
|
| 1045 |
+
examples start with a clean slate.
|
| 1046 |
+
|
| 1047 |
+
Optional keyword arg ``extraglobs`` gives a dictionary that should be
|
| 1048 |
+
merged into the globals that are used to execute examples. By
|
| 1049 |
+
default, no extra globals are used.
|
| 1050 |
+
|
| 1051 |
+
Optional keyword arg ``verbose`` prints lots of stuff if true, prints
|
| 1052 |
+
only failures if false; by default, it's true iff "-v" is in sys.argv.
|
| 1053 |
+
|
| 1054 |
+
Optional keyword arg ``report`` prints a summary at the end when true,
|
| 1055 |
+
else prints nothing at the end. In verbose mode, the summary is
|
| 1056 |
+
detailed, else very brief (in fact, empty if all tests passed).
|
| 1057 |
+
|
| 1058 |
+
Optional keyword arg ``optionflags`` or's together module constants,
|
| 1059 |
+
and defaults to 0. Possible values (see the docs for details):
|
| 1060 |
+
|
| 1061 |
+
- DONT_ACCEPT_TRUE_FOR_1
|
| 1062 |
+
- DONT_ACCEPT_BLANKLINE
|
| 1063 |
+
- NORMALIZE_WHITESPACE
|
| 1064 |
+
- ELLIPSIS
|
| 1065 |
+
- SKIP
|
| 1066 |
+
- IGNORE_EXCEPTION_DETAIL
|
| 1067 |
+
- REPORT_UDIFF
|
| 1068 |
+
- REPORT_CDIFF
|
| 1069 |
+
- REPORT_NDIFF
|
| 1070 |
+
- REPORT_ONLY_FIRST_FAILURE
|
| 1071 |
+
|
| 1072 |
+
Optional keyword arg ``raise_on_error`` raises an exception on the
|
| 1073 |
+
first unexpected exception or failure. This allows failures to be
|
| 1074 |
+
post-mortem debugged.
|
| 1075 |
+
|
| 1076 |
+
Optional keyword arg ``parser`` specifies a DocTestParser (or
|
| 1077 |
+
subclass) that should be used to extract tests from the files.
|
| 1078 |
+
|
| 1079 |
+
Optional keyword arg ``encoding`` specifies an encoding that should
|
| 1080 |
+
be used to convert the file to unicode.
|
| 1081 |
+
|
| 1082 |
+
Advanced tomfoolery: testmod runs methods of a local instance of
|
| 1083 |
+
class doctest.Tester, then merges the results into (or creates)
|
| 1084 |
+
global Tester instance doctest.master. Methods of doctest.master
|
| 1085 |
+
can be called directly too, if you want to do something unusual.
|
| 1086 |
+
Passing report=0 to testmod is especially useful then, to delay
|
| 1087 |
+
displaying a summary. Invoke doctest.master.summarize(verbose)
|
| 1088 |
+
when you're done fiddling.
|
| 1089 |
+
"""
|
| 1090 |
+
if package and not module_relative:
|
| 1091 |
+
raise ValueError("Package may only be specified for module-"
|
| 1092 |
+
"relative paths.")
|
| 1093 |
+
|
| 1094 |
+
# Relativize the path
|
| 1095 |
+
text, filename = pdoctest._load_testfile(
|
| 1096 |
+
filename, package, module_relative, encoding)
|
| 1097 |
+
|
| 1098 |
+
# If no name was given, then use the file's name.
|
| 1099 |
+
if name is None:
|
| 1100 |
+
name = os.path.basename(filename)
|
| 1101 |
+
|
| 1102 |
+
# Assemble the globals.
|
| 1103 |
+
if globs is None:
|
| 1104 |
+
globs = {}
|
| 1105 |
+
else:
|
| 1106 |
+
globs = globs.copy()
|
| 1107 |
+
if extraglobs is not None:
|
| 1108 |
+
globs.update(extraglobs)
|
| 1109 |
+
if '__name__' not in globs:
|
| 1110 |
+
globs['__name__'] = '__main__'
|
| 1111 |
+
|
| 1112 |
+
if raise_on_error:
|
| 1113 |
+
runner = pdoctest.DebugRunner(verbose=verbose, optionflags=optionflags)
|
| 1114 |
+
else:
|
| 1115 |
+
runner = SymPyDocTestRunner(verbose=verbose, optionflags=optionflags)
|
| 1116 |
+
runner._checker = SymPyOutputChecker()
|
| 1117 |
+
|
| 1118 |
+
# Read the file, convert it to a test, and run it.
|
| 1119 |
+
test = parser.get_doctest(text, globs, name, filename, 0)
|
| 1120 |
+
runner.run(test)
|
| 1121 |
+
|
| 1122 |
+
if report:
|
| 1123 |
+
runner.summarize()
|
| 1124 |
+
|
| 1125 |
+
if pdoctest.master is None:
|
| 1126 |
+
pdoctest.master = runner
|
| 1127 |
+
else:
|
| 1128 |
+
pdoctest.master.merge(runner)
|
| 1129 |
+
|
| 1130 |
+
return SymPyTestResults(runner.failures, runner.tries)
|
| 1131 |
+
|
| 1132 |
+
|
| 1133 |
+
class SymPyTests:
|
| 1134 |
+
|
| 1135 |
+
def __init__(self, reporter, kw="", post_mortem=False,
|
| 1136 |
+
seed=None, fast_threshold=None, slow_threshold=None):
|
| 1137 |
+
self._post_mortem = post_mortem
|
| 1138 |
+
self._kw = kw
|
| 1139 |
+
self._count = 0
|
| 1140 |
+
self._root_dir = get_sympy_dir()
|
| 1141 |
+
self._reporter = reporter
|
| 1142 |
+
self._reporter.root_dir(self._root_dir)
|
| 1143 |
+
self._testfiles = []
|
| 1144 |
+
self._seed = seed if seed is not None else random.random()
|
| 1145 |
+
|
| 1146 |
+
# Defaults in seconds, from human / UX design limits
|
| 1147 |
+
# http://www.nngroup.com/articles/response-times-3-important-limits/
|
| 1148 |
+
#
|
| 1149 |
+
# These defaults are *NOT* set in stone as we are measuring different
|
| 1150 |
+
# things, so others feel free to come up with a better yardstick :)
|
| 1151 |
+
if fast_threshold:
|
| 1152 |
+
self._fast_threshold = float(fast_threshold)
|
| 1153 |
+
else:
|
| 1154 |
+
self._fast_threshold = 8
|
| 1155 |
+
if slow_threshold:
|
| 1156 |
+
self._slow_threshold = float(slow_threshold)
|
| 1157 |
+
else:
|
| 1158 |
+
self._slow_threshold = 10
|
| 1159 |
+
|
| 1160 |
+
def test(self, sort=False, timeout=False, slow=False,
|
| 1161 |
+
enhance_asserts=False, fail_on_timeout=False):
|
| 1162 |
+
"""
|
| 1163 |
+
Runs the tests returning True if all tests pass, otherwise False.
|
| 1164 |
+
|
| 1165 |
+
If sort=False run tests in random order.
|
| 1166 |
+
"""
|
| 1167 |
+
if sort:
|
| 1168 |
+
self._testfiles.sort()
|
| 1169 |
+
elif slow:
|
| 1170 |
+
pass
|
| 1171 |
+
else:
|
| 1172 |
+
random.seed(self._seed)
|
| 1173 |
+
random.shuffle(self._testfiles)
|
| 1174 |
+
self._reporter.start(self._seed)
|
| 1175 |
+
for f in self._testfiles:
|
| 1176 |
+
try:
|
| 1177 |
+
self.test_file(f, sort, timeout, slow,
|
| 1178 |
+
enhance_asserts, fail_on_timeout)
|
| 1179 |
+
except KeyboardInterrupt:
|
| 1180 |
+
print(" interrupted by user")
|
| 1181 |
+
self._reporter.finish()
|
| 1182 |
+
raise
|
| 1183 |
+
return self._reporter.finish()
|
| 1184 |
+
|
| 1185 |
+
def _enhance_asserts(self, source):
|
| 1186 |
+
from ast import (NodeTransformer, Compare, Name, Store, Load, Tuple,
|
| 1187 |
+
Assign, BinOp, Str, Mod, Assert, parse, fix_missing_locations)
|
| 1188 |
+
|
| 1189 |
+
ops = {"Eq": '==', "NotEq": '!=', "Lt": '<', "LtE": '<=',
|
| 1190 |
+
"Gt": '>', "GtE": '>=', "Is": 'is', "IsNot": 'is not',
|
| 1191 |
+
"In": 'in', "NotIn": 'not in'}
|
| 1192 |
+
|
| 1193 |
+
class Transform(NodeTransformer):
|
| 1194 |
+
def visit_Assert(self, stmt):
|
| 1195 |
+
if isinstance(stmt.test, Compare):
|
| 1196 |
+
compare = stmt.test
|
| 1197 |
+
values = [compare.left] + compare.comparators
|
| 1198 |
+
names = [ "_%s" % i for i, _ in enumerate(values) ]
|
| 1199 |
+
names_store = [ Name(n, Store()) for n in names ]
|
| 1200 |
+
names_load = [ Name(n, Load()) for n in names ]
|
| 1201 |
+
target = Tuple(names_store, Store())
|
| 1202 |
+
value = Tuple(values, Load())
|
| 1203 |
+
assign = Assign([target], value)
|
| 1204 |
+
new_compare = Compare(names_load[0], compare.ops, names_load[1:])
|
| 1205 |
+
msg_format = "\n%s " + "\n%s ".join([ ops[op.__class__.__name__] for op in compare.ops ]) + "\n%s"
|
| 1206 |
+
msg = BinOp(Str(msg_format), Mod(), Tuple(names_load, Load()))
|
| 1207 |
+
test = Assert(new_compare, msg, lineno=stmt.lineno, col_offset=stmt.col_offset)
|
| 1208 |
+
return [assign, test]
|
| 1209 |
+
else:
|
| 1210 |
+
return stmt
|
| 1211 |
+
|
| 1212 |
+
tree = parse(source)
|
| 1213 |
+
new_tree = Transform().visit(tree)
|
| 1214 |
+
return fix_missing_locations(new_tree)
|
| 1215 |
+
|
| 1216 |
+
def test_file(self, filename, sort=True, timeout=False, slow=False,
|
| 1217 |
+
enhance_asserts=False, fail_on_timeout=False):
|
| 1218 |
+
reporter = self._reporter
|
| 1219 |
+
funcs = []
|
| 1220 |
+
try:
|
| 1221 |
+
gl = {'__file__': filename}
|
| 1222 |
+
try:
|
| 1223 |
+
open_file = lambda: open(filename, encoding="utf8")
|
| 1224 |
+
|
| 1225 |
+
with open_file() as f:
|
| 1226 |
+
source = f.read()
|
| 1227 |
+
if self._kw:
|
| 1228 |
+
for l in source.splitlines():
|
| 1229 |
+
if l.lstrip().startswith('def '):
|
| 1230 |
+
if any(l.lower().find(k.lower()) != -1 for k in self._kw):
|
| 1231 |
+
break
|
| 1232 |
+
else:
|
| 1233 |
+
return
|
| 1234 |
+
|
| 1235 |
+
if enhance_asserts:
|
| 1236 |
+
try:
|
| 1237 |
+
source = self._enhance_asserts(source)
|
| 1238 |
+
except ImportError:
|
| 1239 |
+
pass
|
| 1240 |
+
|
| 1241 |
+
code = compile(source, filename, "exec", flags=0, dont_inherit=True)
|
| 1242 |
+
exec(code, gl)
|
| 1243 |
+
except (SystemExit, KeyboardInterrupt):
|
| 1244 |
+
raise
|
| 1245 |
+
except ImportError:
|
| 1246 |
+
reporter.import_error(filename, sys.exc_info())
|
| 1247 |
+
return
|
| 1248 |
+
except Exception:
|
| 1249 |
+
reporter.test_exception(sys.exc_info())
|
| 1250 |
+
|
| 1251 |
+
clear_cache()
|
| 1252 |
+
self._count += 1
|
| 1253 |
+
random.seed(self._seed)
|
| 1254 |
+
disabled = gl.get("disabled", False)
|
| 1255 |
+
if not disabled:
|
| 1256 |
+
# we need to filter only those functions that begin with 'test_'
|
| 1257 |
+
# We have to be careful about decorated functions. As long as
|
| 1258 |
+
# the decorator uses functools.wraps, we can detect it.
|
| 1259 |
+
funcs = []
|
| 1260 |
+
for f in gl:
|
| 1261 |
+
if (f.startswith("test_") and (inspect.isfunction(gl[f])
|
| 1262 |
+
or inspect.ismethod(gl[f]))):
|
| 1263 |
+
func = gl[f]
|
| 1264 |
+
# Handle multiple decorators
|
| 1265 |
+
while hasattr(func, '__wrapped__'):
|
| 1266 |
+
func = func.__wrapped__
|
| 1267 |
+
|
| 1268 |
+
if inspect.getsourcefile(func) == filename:
|
| 1269 |
+
funcs.append(gl[f])
|
| 1270 |
+
if slow:
|
| 1271 |
+
funcs = [f for f in funcs if getattr(f, '_slow', False)]
|
| 1272 |
+
# Sorting of XFAILed functions isn't fixed yet :-(
|
| 1273 |
+
funcs.sort(key=lambda x: inspect.getsourcelines(x)[1])
|
| 1274 |
+
i = 0
|
| 1275 |
+
while i < len(funcs):
|
| 1276 |
+
if inspect.isgeneratorfunction(funcs[i]):
|
| 1277 |
+
# some tests can be generators, that return the actual
|
| 1278 |
+
# test functions. We unpack it below:
|
| 1279 |
+
f = funcs.pop(i)
|
| 1280 |
+
for fg in f():
|
| 1281 |
+
func = fg[0]
|
| 1282 |
+
args = fg[1:]
|
| 1283 |
+
fgw = lambda: func(*args)
|
| 1284 |
+
funcs.insert(i, fgw)
|
| 1285 |
+
i += 1
|
| 1286 |
+
else:
|
| 1287 |
+
i += 1
|
| 1288 |
+
# drop functions that are not selected with the keyword expression:
|
| 1289 |
+
funcs = [x for x in funcs if self.matches(x)]
|
| 1290 |
+
|
| 1291 |
+
if not funcs:
|
| 1292 |
+
return
|
| 1293 |
+
except Exception:
|
| 1294 |
+
reporter.entering_filename(filename, len(funcs))
|
| 1295 |
+
raise
|
| 1296 |
+
|
| 1297 |
+
reporter.entering_filename(filename, len(funcs))
|
| 1298 |
+
if not sort:
|
| 1299 |
+
random.shuffle(funcs)
|
| 1300 |
+
|
| 1301 |
+
for f in funcs:
|
| 1302 |
+
start = time.time()
|
| 1303 |
+
reporter.entering_test(f)
|
| 1304 |
+
try:
|
| 1305 |
+
if getattr(f, '_slow', False) and not slow:
|
| 1306 |
+
raise Skipped("Slow")
|
| 1307 |
+
with raise_on_deprecated():
|
| 1308 |
+
if timeout:
|
| 1309 |
+
self._timeout(f, timeout, fail_on_timeout)
|
| 1310 |
+
else:
|
| 1311 |
+
random.seed(self._seed)
|
| 1312 |
+
f()
|
| 1313 |
+
except KeyboardInterrupt:
|
| 1314 |
+
if getattr(f, '_slow', False):
|
| 1315 |
+
reporter.test_skip("KeyboardInterrupt")
|
| 1316 |
+
else:
|
| 1317 |
+
raise
|
| 1318 |
+
except Exception:
|
| 1319 |
+
if timeout:
|
| 1320 |
+
signal.alarm(0) # Disable the alarm. It could not be handled before.
|
| 1321 |
+
t, v, tr = sys.exc_info()
|
| 1322 |
+
if t is AssertionError:
|
| 1323 |
+
reporter.test_fail((t, v, tr))
|
| 1324 |
+
if self._post_mortem:
|
| 1325 |
+
pdb.post_mortem(tr)
|
| 1326 |
+
elif t.__name__ == "Skipped":
|
| 1327 |
+
reporter.test_skip(v)
|
| 1328 |
+
elif t.__name__ == "XFail":
|
| 1329 |
+
reporter.test_xfail()
|
| 1330 |
+
elif t.__name__ == "XPass":
|
| 1331 |
+
reporter.test_xpass(v)
|
| 1332 |
+
else:
|
| 1333 |
+
reporter.test_exception((t, v, tr))
|
| 1334 |
+
if self._post_mortem:
|
| 1335 |
+
pdb.post_mortem(tr)
|
| 1336 |
+
else:
|
| 1337 |
+
reporter.test_pass()
|
| 1338 |
+
taken = time.time() - start
|
| 1339 |
+
if taken > self._slow_threshold:
|
| 1340 |
+
filename = os.path.relpath(filename, reporter._root_dir)
|
| 1341 |
+
reporter.slow_test_functions.append(
|
| 1342 |
+
(filename + "::" + f.__name__, taken))
|
| 1343 |
+
if getattr(f, '_slow', False) and slow:
|
| 1344 |
+
if taken < self._fast_threshold:
|
| 1345 |
+
filename = os.path.relpath(filename, reporter._root_dir)
|
| 1346 |
+
reporter.fast_test_functions.append(
|
| 1347 |
+
(filename + "::" + f.__name__, taken))
|
| 1348 |
+
reporter.leaving_filename()
|
| 1349 |
+
|
| 1350 |
+
def _timeout(self, function, timeout, fail_on_timeout):
|
| 1351 |
+
def callback(x, y):
|
| 1352 |
+
signal.alarm(0)
|
| 1353 |
+
if fail_on_timeout:
|
| 1354 |
+
raise TimeOutError("Timed out after %d seconds" % timeout)
|
| 1355 |
+
else:
|
| 1356 |
+
raise Skipped("Timeout")
|
| 1357 |
+
signal.signal(signal.SIGALRM, callback)
|
| 1358 |
+
signal.alarm(timeout) # Set an alarm with a given timeout
|
| 1359 |
+
function()
|
| 1360 |
+
signal.alarm(0) # Disable the alarm
|
| 1361 |
+
|
| 1362 |
+
def matches(self, x):
|
| 1363 |
+
"""
|
| 1364 |
+
Does the keyword expression self._kw match "x"? Returns True/False.
|
| 1365 |
+
|
| 1366 |
+
Always returns True if self._kw is "".
|
| 1367 |
+
"""
|
| 1368 |
+
if not self._kw:
|
| 1369 |
+
return True
|
| 1370 |
+
for kw in self._kw:
|
| 1371 |
+
if x.__name__.lower().find(kw.lower()) != -1:
|
| 1372 |
+
return True
|
| 1373 |
+
return False
|
| 1374 |
+
|
| 1375 |
+
def get_test_files(self, dir, pat='test_*.py'):
|
| 1376 |
+
"""
|
| 1377 |
+
Returns the list of test_*.py (default) files at or below directory
|
| 1378 |
+
``dir`` relative to the SymPy home directory.
|
| 1379 |
+
"""
|
| 1380 |
+
dir = os.path.join(self._root_dir, convert_to_native_paths([dir])[0])
|
| 1381 |
+
|
| 1382 |
+
g = []
|
| 1383 |
+
for path, folders, files in os.walk(dir):
|
| 1384 |
+
g.extend([os.path.join(path, f) for f in files if fnmatch(f, pat)])
|
| 1385 |
+
|
| 1386 |
+
return sorted([os.path.normcase(gi) for gi in g])
|
| 1387 |
+
|
| 1388 |
+
|
| 1389 |
+
class SymPyDocTests:
|
| 1390 |
+
|
| 1391 |
+
def __init__(self, reporter, normal):
|
| 1392 |
+
self._count = 0
|
| 1393 |
+
self._root_dir = get_sympy_dir()
|
| 1394 |
+
self._reporter = reporter
|
| 1395 |
+
self._reporter.root_dir(self._root_dir)
|
| 1396 |
+
self._normal = normal
|
| 1397 |
+
|
| 1398 |
+
self._testfiles = []
|
| 1399 |
+
|
| 1400 |
+
def test(self):
|
| 1401 |
+
"""
|
| 1402 |
+
Runs the tests and returns True if all tests pass, otherwise False.
|
| 1403 |
+
"""
|
| 1404 |
+
self._reporter.start()
|
| 1405 |
+
for f in self._testfiles:
|
| 1406 |
+
try:
|
| 1407 |
+
self.test_file(f)
|
| 1408 |
+
except KeyboardInterrupt:
|
| 1409 |
+
print(" interrupted by user")
|
| 1410 |
+
self._reporter.finish()
|
| 1411 |
+
raise
|
| 1412 |
+
return self._reporter.finish()
|
| 1413 |
+
|
| 1414 |
+
def test_file(self, filename):
|
| 1415 |
+
clear_cache()
|
| 1416 |
+
|
| 1417 |
+
from io import StringIO
|
| 1418 |
+
import sympy.interactive.printing as interactive_printing
|
| 1419 |
+
from sympy.printing.pretty.pretty import pprint_use_unicode
|
| 1420 |
+
from sympy.printing.pretty import stringpict
|
| 1421 |
+
|
| 1422 |
+
rel_name = filename[len(self._root_dir) + 1:]
|
| 1423 |
+
dirname, file = os.path.split(filename)
|
| 1424 |
+
module = rel_name.replace(os.sep, '.')[:-3]
|
| 1425 |
+
|
| 1426 |
+
if rel_name.startswith("examples"):
|
| 1427 |
+
# Examples files do not have __init__.py files,
|
| 1428 |
+
# So we have to temporarily extend sys.path to import them
|
| 1429 |
+
sys.path.insert(0, dirname)
|
| 1430 |
+
module = file[:-3] # remove ".py"
|
| 1431 |
+
try:
|
| 1432 |
+
module = pdoctest._normalize_module(module)
|
| 1433 |
+
tests = SymPyDocTestFinder().find(module)
|
| 1434 |
+
except (SystemExit, KeyboardInterrupt):
|
| 1435 |
+
raise
|
| 1436 |
+
except ImportError:
|
| 1437 |
+
self._reporter.import_error(filename, sys.exc_info())
|
| 1438 |
+
return
|
| 1439 |
+
finally:
|
| 1440 |
+
if rel_name.startswith("examples"):
|
| 1441 |
+
del sys.path[0]
|
| 1442 |
+
|
| 1443 |
+
tests = [test for test in tests if len(test.examples) > 0]
|
| 1444 |
+
# By default tests are sorted by alphabetical order by function name.
|
| 1445 |
+
# We sort by line number so one can edit the file sequentially from
|
| 1446 |
+
# bottom to top. However, if there are decorated functions, their line
|
| 1447 |
+
# numbers will be too large and for now one must just search for these
|
| 1448 |
+
# by text and function name.
|
| 1449 |
+
tests.sort(key=lambda x: -x.lineno)
|
| 1450 |
+
|
| 1451 |
+
if not tests:
|
| 1452 |
+
return
|
| 1453 |
+
self._reporter.entering_filename(filename, len(tests))
|
| 1454 |
+
for test in tests:
|
| 1455 |
+
assert len(test.examples) != 0
|
| 1456 |
+
|
| 1457 |
+
if self._reporter._verbose:
|
| 1458 |
+
self._reporter.write("\n{} ".format(test.name))
|
| 1459 |
+
|
| 1460 |
+
# check if there are external dependencies which need to be met
|
| 1461 |
+
if '_doctest_depends_on' in test.globs:
|
| 1462 |
+
try:
|
| 1463 |
+
self._check_dependencies(**test.globs['_doctest_depends_on'])
|
| 1464 |
+
except DependencyError as e:
|
| 1465 |
+
self._reporter.test_skip(v=str(e))
|
| 1466 |
+
continue
|
| 1467 |
+
|
| 1468 |
+
runner = SymPyDocTestRunner(verbose=self._reporter._verbose==2,
|
| 1469 |
+
optionflags=pdoctest.ELLIPSIS |
|
| 1470 |
+
pdoctest.NORMALIZE_WHITESPACE |
|
| 1471 |
+
pdoctest.IGNORE_EXCEPTION_DETAIL)
|
| 1472 |
+
runner._checker = SymPyOutputChecker()
|
| 1473 |
+
old = sys.stdout
|
| 1474 |
+
new = old if self._reporter._verbose==2 else StringIO()
|
| 1475 |
+
sys.stdout = new
|
| 1476 |
+
# If the testing is normal, the doctests get importing magic to
|
| 1477 |
+
# provide the global namespace. If not normal (the default) then
|
| 1478 |
+
# then must run on their own; all imports must be explicit within
|
| 1479 |
+
# a function's docstring. Once imported that import will be
|
| 1480 |
+
# available to the rest of the tests in a given function's
|
| 1481 |
+
# docstring (unless clear_globs=True below).
|
| 1482 |
+
if not self._normal:
|
| 1483 |
+
test.globs = {}
|
| 1484 |
+
# if this is uncommented then all the test would get is what
|
| 1485 |
+
# comes by default with a "from sympy import *"
|
| 1486 |
+
#exec('from sympy import *') in test.globs
|
| 1487 |
+
old_displayhook = sys.displayhook
|
| 1488 |
+
use_unicode_prev, wrap_line_prev = setup_pprint()
|
| 1489 |
+
|
| 1490 |
+
try:
|
| 1491 |
+
f, t = runner.run(test,
|
| 1492 |
+
out=new.write, clear_globs=False)
|
| 1493 |
+
except KeyboardInterrupt:
|
| 1494 |
+
raise
|
| 1495 |
+
finally:
|
| 1496 |
+
sys.stdout = old
|
| 1497 |
+
if f > 0:
|
| 1498 |
+
self._reporter.doctest_fail(test.name, new.getvalue())
|
| 1499 |
+
else:
|
| 1500 |
+
self._reporter.test_pass()
|
| 1501 |
+
sys.displayhook = old_displayhook
|
| 1502 |
+
interactive_printing.NO_GLOBAL = False
|
| 1503 |
+
pprint_use_unicode(use_unicode_prev)
|
| 1504 |
+
stringpict._GLOBAL_WRAP_LINE = wrap_line_prev
|
| 1505 |
+
|
| 1506 |
+
self._reporter.leaving_filename()
|
| 1507 |
+
|
| 1508 |
+
def get_test_files(self, dir, pat='*.py', init_only=True):
|
| 1509 |
+
r"""
|
| 1510 |
+
Returns the list of \*.py files (default) from which docstrings
|
| 1511 |
+
will be tested which are at or below directory ``dir``. By default,
|
| 1512 |
+
only those that have an __init__.py in their parent directory
|
| 1513 |
+
and do not start with ``test_`` will be included.
|
| 1514 |
+
"""
|
| 1515 |
+
def importable(x):
|
| 1516 |
+
"""
|
| 1517 |
+
Checks if given pathname x is an importable module by checking for
|
| 1518 |
+
__init__.py file.
|
| 1519 |
+
|
| 1520 |
+
Returns True/False.
|
| 1521 |
+
|
| 1522 |
+
Currently we only test if the __init__.py file exists in the
|
| 1523 |
+
directory with the file "x" (in theory we should also test all the
|
| 1524 |
+
parent dirs).
|
| 1525 |
+
"""
|
| 1526 |
+
init_py = os.path.join(os.path.dirname(x), "__init__.py")
|
| 1527 |
+
return os.path.exists(init_py)
|
| 1528 |
+
|
| 1529 |
+
dir = os.path.join(self._root_dir, convert_to_native_paths([dir])[0])
|
| 1530 |
+
|
| 1531 |
+
g = []
|
| 1532 |
+
for path, folders, files in os.walk(dir):
|
| 1533 |
+
g.extend([os.path.join(path, f) for f in files
|
| 1534 |
+
if not f.startswith('test_') and fnmatch(f, pat)])
|
| 1535 |
+
if init_only:
|
| 1536 |
+
# skip files that are not importable (i.e. missing __init__.py)
|
| 1537 |
+
g = [x for x in g if importable(x)]
|
| 1538 |
+
|
| 1539 |
+
return [os.path.normcase(gi) for gi in g]
|
| 1540 |
+
|
| 1541 |
+
def _check_dependencies(self,
|
| 1542 |
+
executables=(),
|
| 1543 |
+
modules=(),
|
| 1544 |
+
disable_viewers=(),
|
| 1545 |
+
python_version=(3, 5),
|
| 1546 |
+
ground_types=None):
|
| 1547 |
+
"""
|
| 1548 |
+
Checks if the dependencies for the test are installed.
|
| 1549 |
+
|
| 1550 |
+
Raises ``DependencyError`` it at least one dependency is not installed.
|
| 1551 |
+
"""
|
| 1552 |
+
|
| 1553 |
+
for executable in executables:
|
| 1554 |
+
if not shutil.which(executable):
|
| 1555 |
+
raise DependencyError("Could not find %s" % executable)
|
| 1556 |
+
|
| 1557 |
+
for module in modules:
|
| 1558 |
+
if module == 'matplotlib':
|
| 1559 |
+
matplotlib = import_module(
|
| 1560 |
+
'matplotlib',
|
| 1561 |
+
import_kwargs={'fromlist':
|
| 1562 |
+
['pyplot', 'cm', 'collections']},
|
| 1563 |
+
min_module_version='1.0.0', catch=(RuntimeError,))
|
| 1564 |
+
if matplotlib is None:
|
| 1565 |
+
raise DependencyError("Could not import matplotlib")
|
| 1566 |
+
else:
|
| 1567 |
+
if not import_module(module):
|
| 1568 |
+
raise DependencyError("Could not import %s" % module)
|
| 1569 |
+
|
| 1570 |
+
if disable_viewers:
|
| 1571 |
+
tempdir = tempfile.mkdtemp()
|
| 1572 |
+
os.environ['PATH'] = '%s:%s' % (tempdir, os.environ['PATH'])
|
| 1573 |
+
|
| 1574 |
+
vw = ('#!/usr/bin/env python3\n'
|
| 1575 |
+
'import sys\n'
|
| 1576 |
+
'if len(sys.argv) <= 1:\n'
|
| 1577 |
+
' exit("wrong number of args")\n')
|
| 1578 |
+
|
| 1579 |
+
for viewer in disable_viewers:
|
| 1580 |
+
with open(os.path.join(tempdir, viewer), 'w') as fh:
|
| 1581 |
+
fh.write(vw)
|
| 1582 |
+
|
| 1583 |
+
# make the file executable
|
| 1584 |
+
os.chmod(os.path.join(tempdir, viewer),
|
| 1585 |
+
stat.S_IREAD | stat.S_IWRITE | stat.S_IXUSR)
|
| 1586 |
+
|
| 1587 |
+
if python_version:
|
| 1588 |
+
if sys.version_info < python_version:
|
| 1589 |
+
raise DependencyError("Requires Python >= " + '.'.join(map(str, python_version)))
|
| 1590 |
+
|
| 1591 |
+
if ground_types is not None:
|
| 1592 |
+
if GROUND_TYPES not in ground_types:
|
| 1593 |
+
raise DependencyError("Requires ground_types in " + str(ground_types))
|
| 1594 |
+
|
| 1595 |
+
if 'pyglet' in modules:
|
| 1596 |
+
# monkey-patch pyglet s.t. it does not open a window during
|
| 1597 |
+
# doctesting
|
| 1598 |
+
import pyglet
|
| 1599 |
+
class DummyWindow:
|
| 1600 |
+
def __init__(self, *args, **kwargs):
|
| 1601 |
+
self.has_exit = True
|
| 1602 |
+
self.width = 600
|
| 1603 |
+
self.height = 400
|
| 1604 |
+
|
| 1605 |
+
def set_vsync(self, x):
|
| 1606 |
+
pass
|
| 1607 |
+
|
| 1608 |
+
def switch_to(self):
|
| 1609 |
+
pass
|
| 1610 |
+
|
| 1611 |
+
def push_handlers(self, x):
|
| 1612 |
+
pass
|
| 1613 |
+
|
| 1614 |
+
def close(self):
|
| 1615 |
+
pass
|
| 1616 |
+
|
| 1617 |
+
pyglet.window.Window = DummyWindow
|
| 1618 |
+
|
| 1619 |
+
|
| 1620 |
+
class SymPyDocTestFinder(DocTestFinder):
|
| 1621 |
+
"""
|
| 1622 |
+
A class used to extract the DocTests that are relevant to a given
|
| 1623 |
+
object, from its docstring and the docstrings of its contained
|
| 1624 |
+
objects. Doctests can currently be extracted from the following
|
| 1625 |
+
object types: modules, functions, classes, methods, staticmethods,
|
| 1626 |
+
classmethods, and properties.
|
| 1627 |
+
|
| 1628 |
+
Modified from doctest's version to look harder for code that
|
| 1629 |
+
appears comes from a different module. For example, the @vectorize
|
| 1630 |
+
decorator makes it look like functions come from multidimensional.py
|
| 1631 |
+
even though their code exists elsewhere.
|
| 1632 |
+
"""
|
| 1633 |
+
|
| 1634 |
+
def _find(self, tests, obj, name, module, source_lines, globs, seen):
|
| 1635 |
+
"""
|
| 1636 |
+
Find tests for the given object and any contained objects, and
|
| 1637 |
+
add them to ``tests``.
|
| 1638 |
+
"""
|
| 1639 |
+
if self._verbose:
|
| 1640 |
+
print('Finding tests in %s' % name)
|
| 1641 |
+
|
| 1642 |
+
# If we've already processed this object, then ignore it.
|
| 1643 |
+
if id(obj) in seen:
|
| 1644 |
+
return
|
| 1645 |
+
seen[id(obj)] = 1
|
| 1646 |
+
|
| 1647 |
+
# Make sure we don't run doctests for classes outside of sympy, such
|
| 1648 |
+
# as in numpy or scipy.
|
| 1649 |
+
if inspect.isclass(obj):
|
| 1650 |
+
if obj.__module__.split('.')[0] != 'sympy':
|
| 1651 |
+
return
|
| 1652 |
+
|
| 1653 |
+
# Find a test for this object, and add it to the list of tests.
|
| 1654 |
+
test = self._get_test(obj, name, module, globs, source_lines)
|
| 1655 |
+
if test is not None:
|
| 1656 |
+
tests.append(test)
|
| 1657 |
+
|
| 1658 |
+
if not self._recurse:
|
| 1659 |
+
return
|
| 1660 |
+
|
| 1661 |
+
# Look for tests in a module's contained objects.
|
| 1662 |
+
if inspect.ismodule(obj):
|
| 1663 |
+
for rawname, val in obj.__dict__.items():
|
| 1664 |
+
# Recurse to functions & classes.
|
| 1665 |
+
if inspect.isfunction(val) or inspect.isclass(val):
|
| 1666 |
+
# Make sure we don't run doctests functions or classes
|
| 1667 |
+
# from different modules
|
| 1668 |
+
if val.__module__ != module.__name__:
|
| 1669 |
+
continue
|
| 1670 |
+
|
| 1671 |
+
assert self._from_module(module, val), \
|
| 1672 |
+
"%s is not in module %s (rawname %s)" % (val, module, rawname)
|
| 1673 |
+
|
| 1674 |
+
try:
|
| 1675 |
+
valname = '%s.%s' % (name, rawname)
|
| 1676 |
+
self._find(tests, val, valname, module,
|
| 1677 |
+
source_lines, globs, seen)
|
| 1678 |
+
except KeyboardInterrupt:
|
| 1679 |
+
raise
|
| 1680 |
+
|
| 1681 |
+
# Look for tests in a module's __test__ dictionary.
|
| 1682 |
+
for valname, val in getattr(obj, '__test__', {}).items():
|
| 1683 |
+
if not isinstance(valname, str):
|
| 1684 |
+
raise ValueError("SymPyDocTestFinder.find: __test__ keys "
|
| 1685 |
+
"must be strings: %r" %
|
| 1686 |
+
(type(valname),))
|
| 1687 |
+
if not (inspect.isfunction(val) or inspect.isclass(val) or
|
| 1688 |
+
inspect.ismethod(val) or inspect.ismodule(val) or
|
| 1689 |
+
isinstance(val, str)):
|
| 1690 |
+
raise ValueError("SymPyDocTestFinder.find: __test__ values "
|
| 1691 |
+
"must be strings, functions, methods, "
|
| 1692 |
+
"classes, or modules: %r" %
|
| 1693 |
+
(type(val),))
|
| 1694 |
+
valname = '%s.__test__.%s' % (name, valname)
|
| 1695 |
+
self._find(tests, val, valname, module, source_lines,
|
| 1696 |
+
globs, seen)
|
| 1697 |
+
|
| 1698 |
+
|
| 1699 |
+
# Look for tests in a class's contained objects.
|
| 1700 |
+
if inspect.isclass(obj):
|
| 1701 |
+
for valname, val in obj.__dict__.items():
|
| 1702 |
+
# Special handling for staticmethod/classmethod.
|
| 1703 |
+
if isinstance(val, staticmethod):
|
| 1704 |
+
val = getattr(obj, valname)
|
| 1705 |
+
if isinstance(val, classmethod):
|
| 1706 |
+
val = getattr(obj, valname).__func__
|
| 1707 |
+
|
| 1708 |
+
|
| 1709 |
+
# Recurse to methods, properties, and nested classes.
|
| 1710 |
+
if ((inspect.isfunction(unwrap(val)) or
|
| 1711 |
+
inspect.isclass(val) or
|
| 1712 |
+
isinstance(val, property)) and
|
| 1713 |
+
self._from_module(module, val)):
|
| 1714 |
+
# Make sure we don't run doctests functions or classes
|
| 1715 |
+
# from different modules
|
| 1716 |
+
if isinstance(val, property):
|
| 1717 |
+
if hasattr(val.fget, '__module__'):
|
| 1718 |
+
if val.fget.__module__ != module.__name__:
|
| 1719 |
+
continue
|
| 1720 |
+
else:
|
| 1721 |
+
if val.__module__ != module.__name__:
|
| 1722 |
+
continue
|
| 1723 |
+
|
| 1724 |
+
assert self._from_module(module, val), \
|
| 1725 |
+
"%s is not in module %s (valname %s)" % (
|
| 1726 |
+
val, module, valname)
|
| 1727 |
+
|
| 1728 |
+
valname = '%s.%s' % (name, valname)
|
| 1729 |
+
self._find(tests, val, valname, module, source_lines,
|
| 1730 |
+
globs, seen)
|
| 1731 |
+
|
| 1732 |
+
def _get_test(self, obj, name, module, globs, source_lines):
|
| 1733 |
+
"""
|
| 1734 |
+
Return a DocTest for the given object, if it defines a docstring;
|
| 1735 |
+
otherwise, return None.
|
| 1736 |
+
"""
|
| 1737 |
+
|
| 1738 |
+
lineno = None
|
| 1739 |
+
|
| 1740 |
+
# Extract the object's docstring. If it does not have one,
|
| 1741 |
+
# then return None (no test for this object).
|
| 1742 |
+
if isinstance(obj, str):
|
| 1743 |
+
# obj is a string in the case for objects in the polys package.
|
| 1744 |
+
# Note that source_lines is a binary string (compiled polys
|
| 1745 |
+
# modules), which can't be handled by _find_lineno so determine
|
| 1746 |
+
# the line number here.
|
| 1747 |
+
|
| 1748 |
+
docstring = obj
|
| 1749 |
+
|
| 1750 |
+
matches = re.findall(r"line \d+", name)
|
| 1751 |
+
assert len(matches) == 1, \
|
| 1752 |
+
"string '%s' does not contain lineno " % name
|
| 1753 |
+
|
| 1754 |
+
# NOTE: this is not the exact linenumber but its better than no
|
| 1755 |
+
# lineno ;)
|
| 1756 |
+
lineno = int(matches[0][5:])
|
| 1757 |
+
|
| 1758 |
+
else:
|
| 1759 |
+
docstring = getattr(obj, '__doc__', '')
|
| 1760 |
+
if docstring is None:
|
| 1761 |
+
docstring = ''
|
| 1762 |
+
if not isinstance(docstring, str):
|
| 1763 |
+
docstring = str(docstring)
|
| 1764 |
+
|
| 1765 |
+
# Don't bother if the docstring is empty.
|
| 1766 |
+
if self._exclude_empty and not docstring:
|
| 1767 |
+
return None
|
| 1768 |
+
|
| 1769 |
+
# check that properties have a docstring because _find_lineno
|
| 1770 |
+
# assumes it
|
| 1771 |
+
if isinstance(obj, property):
|
| 1772 |
+
if obj.fget.__doc__ is None:
|
| 1773 |
+
return None
|
| 1774 |
+
|
| 1775 |
+
# Find the docstring's location in the file.
|
| 1776 |
+
if lineno is None:
|
| 1777 |
+
obj = unwrap(obj)
|
| 1778 |
+
# handling of properties is not implemented in _find_lineno so do
|
| 1779 |
+
# it here
|
| 1780 |
+
if hasattr(obj, 'func_closure') and obj.func_closure is not None:
|
| 1781 |
+
tobj = obj.func_closure[0].cell_contents
|
| 1782 |
+
elif isinstance(obj, property):
|
| 1783 |
+
tobj = obj.fget
|
| 1784 |
+
else:
|
| 1785 |
+
tobj = obj
|
| 1786 |
+
lineno = self._find_lineno(tobj, source_lines)
|
| 1787 |
+
|
| 1788 |
+
if lineno is None:
|
| 1789 |
+
return None
|
| 1790 |
+
|
| 1791 |
+
# Return a DocTest for this object.
|
| 1792 |
+
if module is None:
|
| 1793 |
+
filename = None
|
| 1794 |
+
else:
|
| 1795 |
+
filename = getattr(module, '__file__', module.__name__)
|
| 1796 |
+
if filename[-4:] in (".pyc", ".pyo"):
|
| 1797 |
+
filename = filename[:-1]
|
| 1798 |
+
|
| 1799 |
+
globs['_doctest_depends_on'] = getattr(obj, '_doctest_depends_on', {})
|
| 1800 |
+
|
| 1801 |
+
return self._parser.get_doctest(docstring, globs, name,
|
| 1802 |
+
filename, lineno)
|
| 1803 |
+
|
| 1804 |
+
|
| 1805 |
+
class SymPyDocTestRunner(DocTestRunner):
|
| 1806 |
+
"""
|
| 1807 |
+
A class used to run DocTest test cases, and accumulate statistics.
|
| 1808 |
+
The ``run`` method is used to process a single DocTest case. It
|
| 1809 |
+
returns a tuple ``(f, t)``, where ``t`` is the number of test cases
|
| 1810 |
+
tried, and ``f`` is the number of test cases that failed.
|
| 1811 |
+
|
| 1812 |
+
Modified from the doctest version to not reset the sys.displayhook (see
|
| 1813 |
+
issue 5140).
|
| 1814 |
+
|
| 1815 |
+
See the docstring of the original DocTestRunner for more information.
|
| 1816 |
+
"""
|
| 1817 |
+
|
| 1818 |
+
def run(self, test, compileflags=None, out=None, clear_globs=True):
|
| 1819 |
+
"""
|
| 1820 |
+
Run the examples in ``test``, and display the results using the
|
| 1821 |
+
writer function ``out``.
|
| 1822 |
+
|
| 1823 |
+
The examples are run in the namespace ``test.globs``. If
|
| 1824 |
+
``clear_globs`` is true (the default), then this namespace will
|
| 1825 |
+
be cleared after the test runs, to help with garbage
|
| 1826 |
+
collection. If you would like to examine the namespace after
|
| 1827 |
+
the test completes, then use ``clear_globs=False``.
|
| 1828 |
+
|
| 1829 |
+
``compileflags`` gives the set of flags that should be used by
|
| 1830 |
+
the Python compiler when running the examples. If not
|
| 1831 |
+
specified, then it will default to the set of future-import
|
| 1832 |
+
flags that apply to ``globs``.
|
| 1833 |
+
|
| 1834 |
+
The output of each example is checked using
|
| 1835 |
+
``SymPyDocTestRunner.check_output``, and the results are
|
| 1836 |
+
formatted by the ``SymPyDocTestRunner.report_*`` methods.
|
| 1837 |
+
"""
|
| 1838 |
+
self.test = test
|
| 1839 |
+
|
| 1840 |
+
# Remove ``` from the end of example, which may appear in Markdown
|
| 1841 |
+
# files
|
| 1842 |
+
for example in test.examples:
|
| 1843 |
+
example.want = example.want.replace('```\n', '')
|
| 1844 |
+
example.exc_msg = example.exc_msg and example.exc_msg.replace('```\n', '')
|
| 1845 |
+
|
| 1846 |
+
|
| 1847 |
+
if compileflags is None:
|
| 1848 |
+
compileflags = pdoctest._extract_future_flags(test.globs)
|
| 1849 |
+
|
| 1850 |
+
save_stdout = sys.stdout
|
| 1851 |
+
if out is None:
|
| 1852 |
+
out = save_stdout.write
|
| 1853 |
+
sys.stdout = self._fakeout
|
| 1854 |
+
|
| 1855 |
+
# Patch pdb.set_trace to restore sys.stdout during interactive
|
| 1856 |
+
# debugging (so it's not still redirected to self._fakeout).
|
| 1857 |
+
# Note that the interactive output will go to *our*
|
| 1858 |
+
# save_stdout, even if that's not the real sys.stdout; this
|
| 1859 |
+
# allows us to write test cases for the set_trace behavior.
|
| 1860 |
+
save_set_trace = pdb.set_trace
|
| 1861 |
+
self.debugger = pdoctest._OutputRedirectingPdb(save_stdout)
|
| 1862 |
+
self.debugger.reset()
|
| 1863 |
+
pdb.set_trace = self.debugger.set_trace
|
| 1864 |
+
|
| 1865 |
+
# Patch linecache.getlines, so we can see the example's source
|
| 1866 |
+
# when we're inside the debugger.
|
| 1867 |
+
self.save_linecache_getlines = pdoctest.linecache.getlines
|
| 1868 |
+
linecache.getlines = self.__patched_linecache_getlines
|
| 1869 |
+
|
| 1870 |
+
# Fail for deprecation warnings
|
| 1871 |
+
with raise_on_deprecated():
|
| 1872 |
+
try:
|
| 1873 |
+
return self.__run(test, compileflags, out)
|
| 1874 |
+
finally:
|
| 1875 |
+
sys.stdout = save_stdout
|
| 1876 |
+
pdb.set_trace = save_set_trace
|
| 1877 |
+
linecache.getlines = self.save_linecache_getlines
|
| 1878 |
+
if clear_globs:
|
| 1879 |
+
test.globs.clear()
|
| 1880 |
+
|
| 1881 |
+
|
| 1882 |
+
# We have to override the name mangled methods.
|
| 1883 |
+
monkeypatched_methods = [
|
| 1884 |
+
'patched_linecache_getlines',
|
| 1885 |
+
'run',
|
| 1886 |
+
'record_outcome'
|
| 1887 |
+
]
|
| 1888 |
+
for method in monkeypatched_methods:
|
| 1889 |
+
oldname = '_DocTestRunner__' + method
|
| 1890 |
+
newname = '_SymPyDocTestRunner__' + method
|
| 1891 |
+
setattr(SymPyDocTestRunner, newname, getattr(DocTestRunner, oldname))
|
| 1892 |
+
|
| 1893 |
+
|
| 1894 |
+
class SymPyOutputChecker(pdoctest.OutputChecker):
|
| 1895 |
+
"""
|
| 1896 |
+
Compared to the OutputChecker from the stdlib our OutputChecker class
|
| 1897 |
+
supports numerical comparison of floats occurring in the output of the
|
| 1898 |
+
doctest examples
|
| 1899 |
+
"""
|
| 1900 |
+
|
| 1901 |
+
def __init__(self):
|
| 1902 |
+
# NOTE OutputChecker is an old-style class with no __init__ method,
|
| 1903 |
+
# so we can't call the base class version of __init__ here
|
| 1904 |
+
|
| 1905 |
+
got_floats = r'(\d+\.\d*|\.\d+)'
|
| 1906 |
+
|
| 1907 |
+
# floats in the 'want' string may contain ellipses
|
| 1908 |
+
want_floats = got_floats + r'(\.{3})?'
|
| 1909 |
+
|
| 1910 |
+
front_sep = r'\s|\+|\-|\*|,'
|
| 1911 |
+
back_sep = front_sep + r'|j|e'
|
| 1912 |
+
|
| 1913 |
+
fbeg = r'^%s(?=%s|$)' % (got_floats, back_sep)
|
| 1914 |
+
fmidend = r'(?<=%s)%s(?=%s|$)' % (front_sep, got_floats, back_sep)
|
| 1915 |
+
self.num_got_rgx = re.compile(r'(%s|%s)' %(fbeg, fmidend))
|
| 1916 |
+
|
| 1917 |
+
fbeg = r'^%s(?=%s|$)' % (want_floats, back_sep)
|
| 1918 |
+
fmidend = r'(?<=%s)%s(?=%s|$)' % (front_sep, want_floats, back_sep)
|
| 1919 |
+
self.num_want_rgx = re.compile(r'(%s|%s)' %(fbeg, fmidend))
|
| 1920 |
+
|
| 1921 |
+
def check_output(self, want, got, optionflags):
|
| 1922 |
+
"""
|
| 1923 |
+
Return True iff the actual output from an example (`got`)
|
| 1924 |
+
matches the expected output (`want`). These strings are
|
| 1925 |
+
always considered to match if they are identical; but
|
| 1926 |
+
depending on what option flags the test runner is using,
|
| 1927 |
+
several non-exact match types are also possible. See the
|
| 1928 |
+
documentation for `TestRunner` for more information about
|
| 1929 |
+
option flags.
|
| 1930 |
+
"""
|
| 1931 |
+
# Handle the common case first, for efficiency:
|
| 1932 |
+
# if they're string-identical, always return true.
|
| 1933 |
+
if got == want:
|
| 1934 |
+
return True
|
| 1935 |
+
|
| 1936 |
+
# TODO parse integers as well ?
|
| 1937 |
+
# Parse floats and compare them. If some of the parsed floats contain
|
| 1938 |
+
# ellipses, skip the comparison.
|
| 1939 |
+
matches = self.num_got_rgx.finditer(got)
|
| 1940 |
+
numbers_got = [match.group(1) for match in matches] # list of strs
|
| 1941 |
+
matches = self.num_want_rgx.finditer(want)
|
| 1942 |
+
numbers_want = [match.group(1) for match in matches] # list of strs
|
| 1943 |
+
if len(numbers_got) != len(numbers_want):
|
| 1944 |
+
return False
|
| 1945 |
+
|
| 1946 |
+
if len(numbers_got) > 0:
|
| 1947 |
+
nw_ = []
|
| 1948 |
+
for ng, nw in zip(numbers_got, numbers_want):
|
| 1949 |
+
if '...' in nw:
|
| 1950 |
+
nw_.append(ng)
|
| 1951 |
+
continue
|
| 1952 |
+
else:
|
| 1953 |
+
nw_.append(nw)
|
| 1954 |
+
|
| 1955 |
+
if abs(float(ng)-float(nw)) > 1e-5:
|
| 1956 |
+
return False
|
| 1957 |
+
|
| 1958 |
+
got = self.num_got_rgx.sub(r'%s', got)
|
| 1959 |
+
got = got % tuple(nw_)
|
| 1960 |
+
|
| 1961 |
+
# <BLANKLINE> can be used as a special sequence to signify a
|
| 1962 |
+
# blank line, unless the DONT_ACCEPT_BLANKLINE flag is used.
|
| 1963 |
+
if not (optionflags & pdoctest.DONT_ACCEPT_BLANKLINE):
|
| 1964 |
+
# Replace <BLANKLINE> in want with a blank line.
|
| 1965 |
+
want = re.sub(r'(?m)^%s\s*?$' % re.escape(pdoctest.BLANKLINE_MARKER),
|
| 1966 |
+
'', want)
|
| 1967 |
+
# If a line in got contains only spaces, then remove the
|
| 1968 |
+
# spaces.
|
| 1969 |
+
got = re.sub(r'(?m)^\s*?$', '', got)
|
| 1970 |
+
if got == want:
|
| 1971 |
+
return True
|
| 1972 |
+
|
| 1973 |
+
# This flag causes doctest to ignore any differences in the
|
| 1974 |
+
# contents of whitespace strings. Note that this can be used
|
| 1975 |
+
# in conjunction with the ELLIPSIS flag.
|
| 1976 |
+
if optionflags & pdoctest.NORMALIZE_WHITESPACE:
|
| 1977 |
+
got = ' '.join(got.split())
|
| 1978 |
+
want = ' '.join(want.split())
|
| 1979 |
+
if got == want:
|
| 1980 |
+
return True
|
| 1981 |
+
|
| 1982 |
+
# The ELLIPSIS flag says to let the sequence "..." in `want`
|
| 1983 |
+
# match any substring in `got`.
|
| 1984 |
+
if optionflags & pdoctest.ELLIPSIS:
|
| 1985 |
+
if pdoctest._ellipsis_match(want, got):
|
| 1986 |
+
return True
|
| 1987 |
+
|
| 1988 |
+
# We didn't find any match; return false.
|
| 1989 |
+
return False
|
| 1990 |
+
|
| 1991 |
+
|
| 1992 |
+
class Reporter:
|
| 1993 |
+
"""
|
| 1994 |
+
Parent class for all reporters.
|
| 1995 |
+
"""
|
| 1996 |
+
pass
|
| 1997 |
+
|
| 1998 |
+
|
| 1999 |
+
class PyTestReporter(Reporter):
|
| 2000 |
+
"""
|
| 2001 |
+
Py.test like reporter. Should produce output identical to py.test.
|
| 2002 |
+
"""
|
| 2003 |
+
|
| 2004 |
+
def __init__(self, verbose=False, tb="short", colors=True,
|
| 2005 |
+
force_colors=False, split=None):
|
| 2006 |
+
self._verbose = verbose
|
| 2007 |
+
self._tb_style = tb
|
| 2008 |
+
self._colors = colors
|
| 2009 |
+
self._force_colors = force_colors
|
| 2010 |
+
self._xfailed = 0
|
| 2011 |
+
self._xpassed = []
|
| 2012 |
+
self._failed = []
|
| 2013 |
+
self._failed_doctest = []
|
| 2014 |
+
self._passed = 0
|
| 2015 |
+
self._skipped = 0
|
| 2016 |
+
self._exceptions = []
|
| 2017 |
+
self._terminal_width = None
|
| 2018 |
+
self._default_width = 80
|
| 2019 |
+
self._split = split
|
| 2020 |
+
self._active_file = ''
|
| 2021 |
+
self._active_f = None
|
| 2022 |
+
|
| 2023 |
+
# TODO: Should these be protected?
|
| 2024 |
+
self.slow_test_functions = []
|
| 2025 |
+
self.fast_test_functions = []
|
| 2026 |
+
|
| 2027 |
+
# this tracks the x-position of the cursor (useful for positioning
|
| 2028 |
+
# things on the screen), without the need for any readline library:
|
| 2029 |
+
self._write_pos = 0
|
| 2030 |
+
self._line_wrap = False
|
| 2031 |
+
|
| 2032 |
+
def root_dir(self, dir):
|
| 2033 |
+
self._root_dir = dir
|
| 2034 |
+
|
| 2035 |
+
@property
|
| 2036 |
+
def terminal_width(self):
|
| 2037 |
+
if self._terminal_width is not None:
|
| 2038 |
+
return self._terminal_width
|
| 2039 |
+
|
| 2040 |
+
def findout_terminal_width():
|
| 2041 |
+
if sys.platform == "win32":
|
| 2042 |
+
# Windows support is based on:
|
| 2043 |
+
#
|
| 2044 |
+
# http://code.activestate.com/recipes/
|
| 2045 |
+
# 440694-determine-size-of-console-window-on-windows/
|
| 2046 |
+
|
| 2047 |
+
from ctypes import windll, create_string_buffer
|
| 2048 |
+
|
| 2049 |
+
h = windll.kernel32.GetStdHandle(-12)
|
| 2050 |
+
csbi = create_string_buffer(22)
|
| 2051 |
+
res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
|
| 2052 |
+
|
| 2053 |
+
if res:
|
| 2054 |
+
import struct
|
| 2055 |
+
(_, _, _, _, _, left, _, right, _, _, _) = \
|
| 2056 |
+
struct.unpack("hhhhHhhhhhh", csbi.raw)
|
| 2057 |
+
return right - left
|
| 2058 |
+
else:
|
| 2059 |
+
return self._default_width
|
| 2060 |
+
|
| 2061 |
+
if hasattr(sys.stdout, 'isatty') and not sys.stdout.isatty():
|
| 2062 |
+
return self._default_width # leave PIPEs alone
|
| 2063 |
+
|
| 2064 |
+
try:
|
| 2065 |
+
process = subprocess.Popen(['stty', '-a'],
|
| 2066 |
+
stdout=subprocess.PIPE,
|
| 2067 |
+
stderr=subprocess.PIPE)
|
| 2068 |
+
stdout, stderr = process.communicate()
|
| 2069 |
+
stdout = stdout.decode("utf-8")
|
| 2070 |
+
except OSError:
|
| 2071 |
+
pass
|
| 2072 |
+
else:
|
| 2073 |
+
# We support the following output formats from stty:
|
| 2074 |
+
#
|
| 2075 |
+
# 1) Linux -> columns 80
|
| 2076 |
+
# 2) OS X -> 80 columns
|
| 2077 |
+
# 3) Solaris -> columns = 80
|
| 2078 |
+
|
| 2079 |
+
re_linux = r"columns\s+(?P<columns>\d+);"
|
| 2080 |
+
re_osx = r"(?P<columns>\d+)\s*columns;"
|
| 2081 |
+
re_solaris = r"columns\s+=\s+(?P<columns>\d+);"
|
| 2082 |
+
|
| 2083 |
+
for regex in (re_linux, re_osx, re_solaris):
|
| 2084 |
+
match = re.search(regex, stdout)
|
| 2085 |
+
|
| 2086 |
+
if match is not None:
|
| 2087 |
+
columns = match.group('columns')
|
| 2088 |
+
|
| 2089 |
+
try:
|
| 2090 |
+
width = int(columns)
|
| 2091 |
+
except ValueError:
|
| 2092 |
+
pass
|
| 2093 |
+
if width != 0:
|
| 2094 |
+
return width
|
| 2095 |
+
|
| 2096 |
+
return self._default_width
|
| 2097 |
+
|
| 2098 |
+
width = findout_terminal_width()
|
| 2099 |
+
self._terminal_width = width
|
| 2100 |
+
|
| 2101 |
+
return width
|
| 2102 |
+
|
| 2103 |
+
def write(self, text, color="", align="left", width=None,
|
| 2104 |
+
force_colors=False):
|
| 2105 |
+
"""
|
| 2106 |
+
Prints a text on the screen.
|
| 2107 |
+
|
| 2108 |
+
It uses sys.stdout.write(), so no readline library is necessary.
|
| 2109 |
+
|
| 2110 |
+
Parameters
|
| 2111 |
+
==========
|
| 2112 |
+
|
| 2113 |
+
color : choose from the colors below, "" means default color
|
| 2114 |
+
align : "left"/"right", "left" is a normal print, "right" is aligned on
|
| 2115 |
+
the right-hand side of the screen, filled with spaces if
|
| 2116 |
+
necessary
|
| 2117 |
+
width : the screen width
|
| 2118 |
+
|
| 2119 |
+
"""
|
| 2120 |
+
color_templates = (
|
| 2121 |
+
("Black", "0;30"),
|
| 2122 |
+
("Red", "0;31"),
|
| 2123 |
+
("Green", "0;32"),
|
| 2124 |
+
("Brown", "0;33"),
|
| 2125 |
+
("Blue", "0;34"),
|
| 2126 |
+
("Purple", "0;35"),
|
| 2127 |
+
("Cyan", "0;36"),
|
| 2128 |
+
("LightGray", "0;37"),
|
| 2129 |
+
("DarkGray", "1;30"),
|
| 2130 |
+
("LightRed", "1;31"),
|
| 2131 |
+
("LightGreen", "1;32"),
|
| 2132 |
+
("Yellow", "1;33"),
|
| 2133 |
+
("LightBlue", "1;34"),
|
| 2134 |
+
("LightPurple", "1;35"),
|
| 2135 |
+
("LightCyan", "1;36"),
|
| 2136 |
+
("White", "1;37"),
|
| 2137 |
+
)
|
| 2138 |
+
|
| 2139 |
+
colors = {}
|
| 2140 |
+
|
| 2141 |
+
for name, value in color_templates:
|
| 2142 |
+
colors[name] = value
|
| 2143 |
+
c_normal = '\033[0m'
|
| 2144 |
+
c_color = '\033[%sm'
|
| 2145 |
+
|
| 2146 |
+
if width is None:
|
| 2147 |
+
width = self.terminal_width
|
| 2148 |
+
|
| 2149 |
+
if align == "right":
|
| 2150 |
+
if self._write_pos + len(text) > width:
|
| 2151 |
+
# we don't fit on the current line, create a new line
|
| 2152 |
+
self.write("\n")
|
| 2153 |
+
self.write(" "*(width - self._write_pos - len(text)))
|
| 2154 |
+
|
| 2155 |
+
if not self._force_colors and hasattr(sys.stdout, 'isatty') and not \
|
| 2156 |
+
sys.stdout.isatty():
|
| 2157 |
+
# the stdout is not a terminal, this for example happens if the
|
| 2158 |
+
# output is piped to less, e.g. "bin/test | less". In this case,
|
| 2159 |
+
# the terminal control sequences would be printed verbatim, so
|
| 2160 |
+
# don't use any colors.
|
| 2161 |
+
color = ""
|
| 2162 |
+
elif sys.platform == "win32":
|
| 2163 |
+
# Windows consoles don't support ANSI escape sequences
|
| 2164 |
+
color = ""
|
| 2165 |
+
elif not self._colors:
|
| 2166 |
+
color = ""
|
| 2167 |
+
|
| 2168 |
+
if self._line_wrap:
|
| 2169 |
+
if text[0] != "\n":
|
| 2170 |
+
sys.stdout.write("\n")
|
| 2171 |
+
|
| 2172 |
+
# Avoid UnicodeEncodeError when printing out test failures
|
| 2173 |
+
if IS_WINDOWS:
|
| 2174 |
+
text = text.encode('raw_unicode_escape').decode('utf8', 'ignore')
|
| 2175 |
+
elif not sys.stdout.encoding.lower().startswith('utf'):
|
| 2176 |
+
text = text.encode(sys.stdout.encoding, 'backslashreplace'
|
| 2177 |
+
).decode(sys.stdout.encoding)
|
| 2178 |
+
|
| 2179 |
+
if color == "":
|
| 2180 |
+
sys.stdout.write(text)
|
| 2181 |
+
else:
|
| 2182 |
+
sys.stdout.write("%s%s%s" %
|
| 2183 |
+
(c_color % colors[color], text, c_normal))
|
| 2184 |
+
sys.stdout.flush()
|
| 2185 |
+
l = text.rfind("\n")
|
| 2186 |
+
if l == -1:
|
| 2187 |
+
self._write_pos += len(text)
|
| 2188 |
+
else:
|
| 2189 |
+
self._write_pos = len(text) - l - 1
|
| 2190 |
+
self._line_wrap = self._write_pos >= width
|
| 2191 |
+
self._write_pos %= width
|
| 2192 |
+
|
| 2193 |
+
def write_center(self, text, delim="="):
|
| 2194 |
+
width = self.terminal_width
|
| 2195 |
+
if text != "":
|
| 2196 |
+
text = " %s " % text
|
| 2197 |
+
idx = (width - len(text)) // 2
|
| 2198 |
+
t = delim*idx + text + delim*(width - idx - len(text))
|
| 2199 |
+
self.write(t + "\n")
|
| 2200 |
+
|
| 2201 |
+
def write_exception(self, e, val, tb):
|
| 2202 |
+
# remove the first item, as that is always runtests.py
|
| 2203 |
+
tb = tb.tb_next
|
| 2204 |
+
t = traceback.format_exception(e, val, tb)
|
| 2205 |
+
self.write("".join(t))
|
| 2206 |
+
|
| 2207 |
+
def start(self, seed=None, msg="test process starts"):
|
| 2208 |
+
self.write_center(msg)
|
| 2209 |
+
executable = sys.executable
|
| 2210 |
+
v = tuple(sys.version_info)
|
| 2211 |
+
python_version = "%s.%s.%s-%s-%s" % v
|
| 2212 |
+
implementation = platform.python_implementation()
|
| 2213 |
+
if implementation == 'PyPy':
|
| 2214 |
+
implementation += " %s.%s.%s-%s-%s" % sys.pypy_version_info
|
| 2215 |
+
self.write("executable: %s (%s) [%s]\n" %
|
| 2216 |
+
(executable, python_version, implementation))
|
| 2217 |
+
from sympy.utilities.misc import ARCH
|
| 2218 |
+
self.write("architecture: %s\n" % ARCH)
|
| 2219 |
+
from sympy.core.cache import USE_CACHE
|
| 2220 |
+
self.write("cache: %s\n" % USE_CACHE)
|
| 2221 |
+
version = ''
|
| 2222 |
+
if GROUND_TYPES =='gmpy':
|
| 2223 |
+
import gmpy2 as gmpy
|
| 2224 |
+
version = gmpy.version()
|
| 2225 |
+
self.write("ground types: %s %s\n" % (GROUND_TYPES, version))
|
| 2226 |
+
numpy = import_module('numpy')
|
| 2227 |
+
self.write("numpy: %s\n" % (None if not numpy else numpy.__version__))
|
| 2228 |
+
if seed is not None:
|
| 2229 |
+
self.write("random seed: %d\n" % seed)
|
| 2230 |
+
from sympy.utilities.misc import HASH_RANDOMIZATION
|
| 2231 |
+
self.write("hash randomization: ")
|
| 2232 |
+
hash_seed = os.getenv("PYTHONHASHSEED") or '0'
|
| 2233 |
+
if HASH_RANDOMIZATION and (hash_seed == "random" or int(hash_seed)):
|
| 2234 |
+
self.write("on (PYTHONHASHSEED=%s)\n" % hash_seed)
|
| 2235 |
+
else:
|
| 2236 |
+
self.write("off\n")
|
| 2237 |
+
if self._split:
|
| 2238 |
+
self.write("split: %s\n" % self._split)
|
| 2239 |
+
self.write('\n')
|
| 2240 |
+
self._t_start = clock()
|
| 2241 |
+
|
| 2242 |
+
def finish(self):
|
| 2243 |
+
self._t_end = clock()
|
| 2244 |
+
self.write("\n")
|
| 2245 |
+
global text, linelen
|
| 2246 |
+
text = "tests finished: %d passed, " % self._passed
|
| 2247 |
+
linelen = len(text)
|
| 2248 |
+
|
| 2249 |
+
def add_text(mytext):
|
| 2250 |
+
global text, linelen
|
| 2251 |
+
"""Break new text if too long."""
|
| 2252 |
+
if linelen + len(mytext) > self.terminal_width:
|
| 2253 |
+
text += '\n'
|
| 2254 |
+
linelen = 0
|
| 2255 |
+
text += mytext
|
| 2256 |
+
linelen += len(mytext)
|
| 2257 |
+
|
| 2258 |
+
if len(self._failed) > 0:
|
| 2259 |
+
add_text("%d failed, " % len(self._failed))
|
| 2260 |
+
if len(self._failed_doctest) > 0:
|
| 2261 |
+
add_text("%d failed, " % len(self._failed_doctest))
|
| 2262 |
+
if self._skipped > 0:
|
| 2263 |
+
add_text("%d skipped, " % self._skipped)
|
| 2264 |
+
if self._xfailed > 0:
|
| 2265 |
+
add_text("%d expected to fail, " % self._xfailed)
|
| 2266 |
+
if len(self._xpassed) > 0:
|
| 2267 |
+
add_text("%d expected to fail but passed, " % len(self._xpassed))
|
| 2268 |
+
if len(self._exceptions) > 0:
|
| 2269 |
+
add_text("%d exceptions, " % len(self._exceptions))
|
| 2270 |
+
add_text("in %.2f seconds" % (self._t_end - self._t_start))
|
| 2271 |
+
|
| 2272 |
+
if self.slow_test_functions:
|
| 2273 |
+
self.write_center('slowest tests', '_')
|
| 2274 |
+
sorted_slow = sorted(self.slow_test_functions, key=lambda r: r[1])
|
| 2275 |
+
for slow_func_name, taken in sorted_slow:
|
| 2276 |
+
print('%s - Took %.3f seconds' % (slow_func_name, taken))
|
| 2277 |
+
|
| 2278 |
+
if self.fast_test_functions:
|
| 2279 |
+
self.write_center('unexpectedly fast tests', '_')
|
| 2280 |
+
sorted_fast = sorted(self.fast_test_functions,
|
| 2281 |
+
key=lambda r: r[1])
|
| 2282 |
+
for fast_func_name, taken in sorted_fast:
|
| 2283 |
+
print('%s - Took %.3f seconds' % (fast_func_name, taken))
|
| 2284 |
+
|
| 2285 |
+
if len(self._xpassed) > 0:
|
| 2286 |
+
self.write_center("xpassed tests", "_")
|
| 2287 |
+
for e in self._xpassed:
|
| 2288 |
+
self.write("%s: %s\n" % (e[0], e[1]))
|
| 2289 |
+
self.write("\n")
|
| 2290 |
+
|
| 2291 |
+
if self._tb_style != "no" and len(self._exceptions) > 0:
|
| 2292 |
+
for e in self._exceptions:
|
| 2293 |
+
filename, f, (t, val, tb) = e
|
| 2294 |
+
self.write_center("", "_")
|
| 2295 |
+
if f is None:
|
| 2296 |
+
s = "%s" % filename
|
| 2297 |
+
else:
|
| 2298 |
+
s = "%s:%s" % (filename, f.__name__)
|
| 2299 |
+
self.write_center(s, "_")
|
| 2300 |
+
self.write_exception(t, val, tb)
|
| 2301 |
+
self.write("\n")
|
| 2302 |
+
|
| 2303 |
+
if self._tb_style != "no" and len(self._failed) > 0:
|
| 2304 |
+
for e in self._failed:
|
| 2305 |
+
filename, f, (t, val, tb) = e
|
| 2306 |
+
self.write_center("", "_")
|
| 2307 |
+
self.write_center("%s::%s" % (filename, f.__name__), "_")
|
| 2308 |
+
self.write_exception(t, val, tb)
|
| 2309 |
+
self.write("\n")
|
| 2310 |
+
|
| 2311 |
+
if self._tb_style != "no" and len(self._failed_doctest) > 0:
|
| 2312 |
+
for e in self._failed_doctest:
|
| 2313 |
+
filename, msg = e
|
| 2314 |
+
self.write_center("", "_")
|
| 2315 |
+
self.write_center("%s" % filename, "_")
|
| 2316 |
+
self.write(msg)
|
| 2317 |
+
self.write("\n")
|
| 2318 |
+
|
| 2319 |
+
self.write_center(text)
|
| 2320 |
+
ok = len(self._failed) == 0 and len(self._exceptions) == 0 and \
|
| 2321 |
+
len(self._failed_doctest) == 0
|
| 2322 |
+
if not ok:
|
| 2323 |
+
self.write("DO *NOT* COMMIT!\n")
|
| 2324 |
+
return ok
|
| 2325 |
+
|
| 2326 |
+
def entering_filename(self, filename, n):
|
| 2327 |
+
rel_name = filename[len(self._root_dir) + 1:]
|
| 2328 |
+
self._active_file = rel_name
|
| 2329 |
+
self._active_file_error = False
|
| 2330 |
+
self.write(rel_name)
|
| 2331 |
+
self.write("[%d] " % n)
|
| 2332 |
+
|
| 2333 |
+
def leaving_filename(self):
|
| 2334 |
+
self.write(" ")
|
| 2335 |
+
if self._active_file_error:
|
| 2336 |
+
self.write("[FAIL]", "Red", align="right")
|
| 2337 |
+
else:
|
| 2338 |
+
self.write("[OK]", "Green", align="right")
|
| 2339 |
+
self.write("\n")
|
| 2340 |
+
if self._verbose:
|
| 2341 |
+
self.write("\n")
|
| 2342 |
+
|
| 2343 |
+
def entering_test(self, f):
|
| 2344 |
+
self._active_f = f
|
| 2345 |
+
if self._verbose:
|
| 2346 |
+
self.write("\n" + f.__name__ + " ")
|
| 2347 |
+
|
| 2348 |
+
def test_xfail(self):
|
| 2349 |
+
self._xfailed += 1
|
| 2350 |
+
self.write("f", "Green")
|
| 2351 |
+
|
| 2352 |
+
def test_xpass(self, v):
|
| 2353 |
+
message = str(v)
|
| 2354 |
+
self._xpassed.append((self._active_file, message))
|
| 2355 |
+
self.write("X", "Green")
|
| 2356 |
+
|
| 2357 |
+
def test_fail(self, exc_info):
|
| 2358 |
+
self._failed.append((self._active_file, self._active_f, exc_info))
|
| 2359 |
+
self.write("F", "Red")
|
| 2360 |
+
self._active_file_error = True
|
| 2361 |
+
|
| 2362 |
+
def doctest_fail(self, name, error_msg):
|
| 2363 |
+
# the first line contains "******", remove it:
|
| 2364 |
+
error_msg = "\n".join(error_msg.split("\n")[1:])
|
| 2365 |
+
self._failed_doctest.append((name, error_msg))
|
| 2366 |
+
self.write("F", "Red")
|
| 2367 |
+
self._active_file_error = True
|
| 2368 |
+
|
| 2369 |
+
def test_pass(self, char="."):
|
| 2370 |
+
self._passed += 1
|
| 2371 |
+
if self._verbose:
|
| 2372 |
+
self.write("ok", "Green")
|
| 2373 |
+
else:
|
| 2374 |
+
self.write(char, "Green")
|
| 2375 |
+
|
| 2376 |
+
def test_skip(self, v=None):
|
| 2377 |
+
char = "s"
|
| 2378 |
+
self._skipped += 1
|
| 2379 |
+
if v is not None:
|
| 2380 |
+
message = str(v)
|
| 2381 |
+
if message == "KeyboardInterrupt":
|
| 2382 |
+
char = "K"
|
| 2383 |
+
elif message == "Timeout":
|
| 2384 |
+
char = "T"
|
| 2385 |
+
elif message == "Slow":
|
| 2386 |
+
char = "w"
|
| 2387 |
+
if self._verbose:
|
| 2388 |
+
if v is not None:
|
| 2389 |
+
self.write(message + ' ', "Blue")
|
| 2390 |
+
else:
|
| 2391 |
+
self.write(" - ", "Blue")
|
| 2392 |
+
self.write(char, "Blue")
|
| 2393 |
+
|
| 2394 |
+
def test_exception(self, exc_info):
|
| 2395 |
+
self._exceptions.append((self._active_file, self._active_f, exc_info))
|
| 2396 |
+
if exc_info[0] is TimeOutError:
|
| 2397 |
+
self.write("T", "Red")
|
| 2398 |
+
else:
|
| 2399 |
+
self.write("E", "Red")
|
| 2400 |
+
self._active_file_error = True
|
| 2401 |
+
|
| 2402 |
+
def import_error(self, filename, exc_info):
|
| 2403 |
+
self._exceptions.append((filename, None, exc_info))
|
| 2404 |
+
rel_name = filename[len(self._root_dir) + 1:]
|
| 2405 |
+
self.write(rel_name)
|
| 2406 |
+
self.write("[?] Failed to import", "Red")
|
| 2407 |
+
self.write(" ")
|
| 2408 |
+
self.write("[FAIL]", "Red", align="right")
|
| 2409 |
+
self.write("\n")
|
mplug_owl2/lib/python3.10/site-packages/sympy/testing/runtests_pytest.py
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Backwards compatible functions for running tests from SymPy using pytest.
|
| 2 |
+
|
| 3 |
+
SymPy historically had its own testing framework that aimed to:
|
| 4 |
+
- be compatible with pytest;
|
| 5 |
+
- operate similarly (or identically) to pytest;
|
| 6 |
+
- not require any external dependencies;
|
| 7 |
+
- have all the functionality in one file only;
|
| 8 |
+
- have no magic, just import the test file and execute the test functions; and
|
| 9 |
+
- be portable.
|
| 10 |
+
|
| 11 |
+
To reduce the maintence burden of developing an independent testing framework
|
| 12 |
+
and to leverage the benefits of existing Python testing infrastructure, SymPy
|
| 13 |
+
now uses pytest (and various of its plugins) to run the test suite.
|
| 14 |
+
|
| 15 |
+
To maintain backwards compatibility with the legacy testing interface of SymPy,
|
| 16 |
+
which implemented functions that allowed users to run the tests on their
|
| 17 |
+
installed version of SymPy, the functions in this module are implemented to
|
| 18 |
+
match the existing API while thinly wrapping pytest.
|
| 19 |
+
|
| 20 |
+
These two key functions are `test` and `doctest`.
|
| 21 |
+
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
import functools
|
| 25 |
+
import importlib.util
|
| 26 |
+
import os
|
| 27 |
+
import pathlib
|
| 28 |
+
import re
|
| 29 |
+
from fnmatch import fnmatch
|
| 30 |
+
from typing import List, Optional, Tuple
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
import pytest
|
| 34 |
+
except ImportError:
|
| 35 |
+
|
| 36 |
+
class NoPytestError(Exception):
|
| 37 |
+
"""Raise when an internal test helper function is called with pytest."""
|
| 38 |
+
|
| 39 |
+
class pytest: # type: ignore
|
| 40 |
+
"""Shadow to support pytest features when pytest can't be imported."""
|
| 41 |
+
|
| 42 |
+
@staticmethod
|
| 43 |
+
def main(*args, **kwargs):
|
| 44 |
+
msg = 'pytest must be installed to run tests via this function'
|
| 45 |
+
raise NoPytestError(msg)
|
| 46 |
+
|
| 47 |
+
from sympy.testing.runtests import test as test_sympy
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
TESTPATHS_DEFAULT = (
|
| 51 |
+
pathlib.Path('sympy'),
|
| 52 |
+
pathlib.Path('doc', 'src'),
|
| 53 |
+
)
|
| 54 |
+
BLACKLIST_DEFAULT = (
|
| 55 |
+
'sympy/integrals/rubi/rubi_tests/tests',
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class PytestPluginManager:
|
| 60 |
+
"""Module names for pytest plugins used by SymPy."""
|
| 61 |
+
PYTEST: str = 'pytest'
|
| 62 |
+
RANDOMLY: str = 'pytest_randomly'
|
| 63 |
+
SPLIT: str = 'pytest_split'
|
| 64 |
+
TIMEOUT: str = 'pytest_timeout'
|
| 65 |
+
XDIST: str = 'xdist'
|
| 66 |
+
|
| 67 |
+
@functools.cached_property
|
| 68 |
+
def has_pytest(self) -> bool:
|
| 69 |
+
return bool(importlib.util.find_spec(self.PYTEST))
|
| 70 |
+
|
| 71 |
+
@functools.cached_property
|
| 72 |
+
def has_randomly(self) -> bool:
|
| 73 |
+
return bool(importlib.util.find_spec(self.RANDOMLY))
|
| 74 |
+
|
| 75 |
+
@functools.cached_property
|
| 76 |
+
def has_split(self) -> bool:
|
| 77 |
+
return bool(importlib.util.find_spec(self.SPLIT))
|
| 78 |
+
|
| 79 |
+
@functools.cached_property
|
| 80 |
+
def has_timeout(self) -> bool:
|
| 81 |
+
return bool(importlib.util.find_spec(self.TIMEOUT))
|
| 82 |
+
|
| 83 |
+
@functools.cached_property
|
| 84 |
+
def has_xdist(self) -> bool:
|
| 85 |
+
return bool(importlib.util.find_spec(self.XDIST))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
split_pattern = re.compile(r'([1-9][0-9]*)/([1-9][0-9]*)')
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
@functools.lru_cache
|
| 92 |
+
def sympy_dir() -> pathlib.Path:
|
| 93 |
+
"""Returns the root SymPy directory."""
|
| 94 |
+
return pathlib.Path(__file__).parents[2]
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def update_args_with_rootdir(args: List[str]) -> List[str]:
|
| 98 |
+
"""Adds `--rootdir` and path to the args `list` passed to `pytest.main`.
|
| 99 |
+
|
| 100 |
+
This is required to ensure that pytest is able to find the SymPy tests in
|
| 101 |
+
instances where it gets confused determining the root directory, e.g. when
|
| 102 |
+
running with Pyodide (e.g. `bin/test_pyodide.mjs`).
|
| 103 |
+
|
| 104 |
+
"""
|
| 105 |
+
args.extend(['--rootdir', str(sympy_dir())])
|
| 106 |
+
return args
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def update_args_with_paths(
|
| 110 |
+
paths: List[str],
|
| 111 |
+
keywords: Optional[Tuple[str]],
|
| 112 |
+
args: List[str],
|
| 113 |
+
) -> List[str]:
|
| 114 |
+
"""Appends valid paths and flags to the args `list` passed to `pytest.main`.
|
| 115 |
+
|
| 116 |
+
The are three different types of "path" that a user may pass to the `paths`
|
| 117 |
+
positional arguments, all of which need to be handled slightly differently:
|
| 118 |
+
|
| 119 |
+
1. Nothing is passed
|
| 120 |
+
The paths to the `testpaths` defined in `pytest.ini` need to be appended
|
| 121 |
+
to the arguments list.
|
| 122 |
+
2. Full, valid paths are passed
|
| 123 |
+
These paths need to be validated but can then be directly appended to
|
| 124 |
+
the arguments list.
|
| 125 |
+
3. Partial paths are passed.
|
| 126 |
+
The `testpaths` defined in `pytest.ini` need to be recursed and any
|
| 127 |
+
matches be appended to the arguments list.
|
| 128 |
+
|
| 129 |
+
"""
|
| 130 |
+
|
| 131 |
+
def find_paths_matching_partial(partial_paths):
|
| 132 |
+
partial_path_file_patterns = []
|
| 133 |
+
for partial_path in partial_paths:
|
| 134 |
+
if len(partial_path) >= 4:
|
| 135 |
+
has_test_prefix = partial_path[:4] == 'test'
|
| 136 |
+
has_py_suffix = partial_path[-3:] == '.py'
|
| 137 |
+
elif len(partial_path) >= 3:
|
| 138 |
+
has_test_prefix = False
|
| 139 |
+
has_py_suffix = partial_path[-3:] == '.py'
|
| 140 |
+
else:
|
| 141 |
+
has_test_prefix = False
|
| 142 |
+
has_py_suffix = False
|
| 143 |
+
if has_test_prefix and has_py_suffix:
|
| 144 |
+
partial_path_file_patterns.append(partial_path)
|
| 145 |
+
elif has_test_prefix:
|
| 146 |
+
partial_path_file_patterns.append(f'{partial_path}*.py')
|
| 147 |
+
elif has_py_suffix:
|
| 148 |
+
partial_path_file_patterns.append(f'test*{partial_path}')
|
| 149 |
+
else:
|
| 150 |
+
partial_path_file_patterns.append(f'test*{partial_path}*.py')
|
| 151 |
+
matches = []
|
| 152 |
+
for testpath in valid_testpaths_default:
|
| 153 |
+
for path, dirs, files in os.walk(testpath, topdown=True):
|
| 154 |
+
zipped = zip(partial_paths, partial_path_file_patterns)
|
| 155 |
+
for (partial_path, partial_path_file) in zipped:
|
| 156 |
+
if fnmatch(path, f'*{partial_path}*'):
|
| 157 |
+
matches.append(str(pathlib.Path(path)))
|
| 158 |
+
dirs[:] = []
|
| 159 |
+
else:
|
| 160 |
+
for file in files:
|
| 161 |
+
if fnmatch(file, partial_path_file):
|
| 162 |
+
matches.append(str(pathlib.Path(path, file)))
|
| 163 |
+
return matches
|
| 164 |
+
|
| 165 |
+
def is_tests_file(filepath: str) -> bool:
|
| 166 |
+
path = pathlib.Path(filepath)
|
| 167 |
+
if not path.is_file():
|
| 168 |
+
return False
|
| 169 |
+
if not path.parts[-1].startswith('test_'):
|
| 170 |
+
return False
|
| 171 |
+
if not path.suffix == '.py':
|
| 172 |
+
return False
|
| 173 |
+
return True
|
| 174 |
+
|
| 175 |
+
def find_tests_matching_keywords(keywords, filepath):
|
| 176 |
+
matches = []
|
| 177 |
+
with open(filepath, encoding='utf-8') as tests_file:
|
| 178 |
+
source = tests_file.read()
|
| 179 |
+
for line in source.splitlines():
|
| 180 |
+
if line.lstrip().startswith('def '):
|
| 181 |
+
for kw in keywords:
|
| 182 |
+
if line.lower().find(kw.lower()) != -1:
|
| 183 |
+
test_name = line.split(' ')[1].split('(')[0]
|
| 184 |
+
full_test_path = filepath + '::' + test_name
|
| 185 |
+
matches.append(full_test_path)
|
| 186 |
+
return matches
|
| 187 |
+
|
| 188 |
+
valid_testpaths_default = []
|
| 189 |
+
for testpath in TESTPATHS_DEFAULT:
|
| 190 |
+
absolute_testpath = pathlib.Path(sympy_dir(), testpath)
|
| 191 |
+
if absolute_testpath.exists():
|
| 192 |
+
valid_testpaths_default.append(str(absolute_testpath))
|
| 193 |
+
|
| 194 |
+
candidate_paths = []
|
| 195 |
+
if paths:
|
| 196 |
+
full_paths = []
|
| 197 |
+
partial_paths = []
|
| 198 |
+
for path in paths:
|
| 199 |
+
if pathlib.Path(path).exists():
|
| 200 |
+
full_paths.append(str(pathlib.Path(sympy_dir(), path)))
|
| 201 |
+
else:
|
| 202 |
+
partial_paths.append(path)
|
| 203 |
+
matched_paths = find_paths_matching_partial(partial_paths)
|
| 204 |
+
candidate_paths.extend(full_paths)
|
| 205 |
+
candidate_paths.extend(matched_paths)
|
| 206 |
+
else:
|
| 207 |
+
candidate_paths.extend(valid_testpaths_default)
|
| 208 |
+
|
| 209 |
+
if keywords is not None and keywords != ():
|
| 210 |
+
matches = []
|
| 211 |
+
for path in candidate_paths:
|
| 212 |
+
if is_tests_file(path):
|
| 213 |
+
test_matches = find_tests_matching_keywords(keywords, path)
|
| 214 |
+
matches.extend(test_matches)
|
| 215 |
+
else:
|
| 216 |
+
for root, dirnames, filenames in os.walk(path):
|
| 217 |
+
for filename in filenames:
|
| 218 |
+
absolute_filepath = str(pathlib.Path(root, filename))
|
| 219 |
+
if is_tests_file(absolute_filepath):
|
| 220 |
+
test_matches = find_tests_matching_keywords(
|
| 221 |
+
keywords,
|
| 222 |
+
absolute_filepath,
|
| 223 |
+
)
|
| 224 |
+
matches.extend(test_matches)
|
| 225 |
+
args.extend(matches)
|
| 226 |
+
else:
|
| 227 |
+
args.extend(candidate_paths)
|
| 228 |
+
|
| 229 |
+
return args
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def make_absolute_path(partial_path: str) -> str:
|
| 233 |
+
"""Convert a partial path to an absolute path.
|
| 234 |
+
|
| 235 |
+
A path such a `sympy/core` might be needed. However, absolute paths should
|
| 236 |
+
be used in the arguments to pytest in all cases as it avoids errors that
|
| 237 |
+
arise from nonexistent paths.
|
| 238 |
+
|
| 239 |
+
This function assumes that partial_paths will be passed in such that they
|
| 240 |
+
begin with the explicit `sympy` directory, i.e. `sympy/...`.
|
| 241 |
+
|
| 242 |
+
"""
|
| 243 |
+
|
| 244 |
+
def is_valid_partial_path(partial_path: str) -> bool:
|
| 245 |
+
"""Assumption that partial paths are defined from the `sympy` root."""
|
| 246 |
+
return pathlib.Path(partial_path).parts[0] == 'sympy'
|
| 247 |
+
|
| 248 |
+
if not is_valid_partial_path(partial_path):
|
| 249 |
+
msg = (
|
| 250 |
+
f'Partial path {dir(partial_path)} is invalid, partial paths are '
|
| 251 |
+
f'expected to be defined with the `sympy` directory as the root.'
|
| 252 |
+
)
|
| 253 |
+
raise ValueError(msg)
|
| 254 |
+
|
| 255 |
+
absolute_path = str(pathlib.Path(sympy_dir(), partial_path))
|
| 256 |
+
return absolute_path
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def test(*paths, subprocess=True, rerun=0, **kwargs):
|
| 260 |
+
"""Interface to run tests via pytest compatible with SymPy's test runner.
|
| 261 |
+
|
| 262 |
+
Explanation
|
| 263 |
+
===========
|
| 264 |
+
|
| 265 |
+
Note that a `pytest.ExitCode`, which is an `enum`, is returned. This is
|
| 266 |
+
different to the legacy SymPy test runner which would return a `bool`. If
|
| 267 |
+
all tests sucessfully pass the `pytest.ExitCode.OK` with value `0` is
|
| 268 |
+
returned, whereas the legacy SymPy test runner would return `True`. In any
|
| 269 |
+
other scenario, a non-zero `enum` value is returned, whereas the legacy
|
| 270 |
+
SymPy test runner would return `False`. Users need to, therefore, be careful
|
| 271 |
+
if treating the pytest exit codes as booleans because
|
| 272 |
+
`bool(pytest.ExitCode.OK)` evaluates to `False`, the opposite of legacy
|
| 273 |
+
behaviour.
|
| 274 |
+
|
| 275 |
+
Examples
|
| 276 |
+
========
|
| 277 |
+
|
| 278 |
+
>>> import sympy # doctest: +SKIP
|
| 279 |
+
|
| 280 |
+
Run one file:
|
| 281 |
+
|
| 282 |
+
>>> sympy.test('sympy/core/tests/test_basic.py') # doctest: +SKIP
|
| 283 |
+
>>> sympy.test('_basic') # doctest: +SKIP
|
| 284 |
+
|
| 285 |
+
Run all tests in sympy/functions/ and some particular file:
|
| 286 |
+
|
| 287 |
+
>>> sympy.test("sympy/core/tests/test_basic.py",
|
| 288 |
+
... "sympy/functions") # doctest: +SKIP
|
| 289 |
+
|
| 290 |
+
Run all tests in sympy/core and sympy/utilities:
|
| 291 |
+
|
| 292 |
+
>>> sympy.test("/core", "/util") # doctest: +SKIP
|
| 293 |
+
|
| 294 |
+
Run specific test from a file:
|
| 295 |
+
|
| 296 |
+
>>> sympy.test("sympy/core/tests/test_basic.py",
|
| 297 |
+
... kw="test_equality") # doctest: +SKIP
|
| 298 |
+
|
| 299 |
+
Run specific test from any file:
|
| 300 |
+
|
| 301 |
+
>>> sympy.test(kw="subs") # doctest: +SKIP
|
| 302 |
+
|
| 303 |
+
Run the tests using the legacy SymPy runner:
|
| 304 |
+
|
| 305 |
+
>>> sympy.test(use_sympy_runner=True) # doctest: +SKIP
|
| 306 |
+
|
| 307 |
+
Note that this option is slated for deprecation in the near future and is
|
| 308 |
+
only currently provided to ensure users have an alternative option while the
|
| 309 |
+
pytest-based runner receives real-world testing.
|
| 310 |
+
|
| 311 |
+
Parameters
|
| 312 |
+
==========
|
| 313 |
+
paths : first n positional arguments of strings
|
| 314 |
+
Paths, both partial and absolute, describing which subset(s) of the test
|
| 315 |
+
suite are to be run.
|
| 316 |
+
subprocess : bool, default is True
|
| 317 |
+
Legacy option, is currently ignored.
|
| 318 |
+
rerun : int, default is 0
|
| 319 |
+
Legacy option, is ignored.
|
| 320 |
+
use_sympy_runner : bool or None, default is None
|
| 321 |
+
Temporary option to invoke the legacy SymPy test runner instead of
|
| 322 |
+
`pytest.main`. Will be removed in the near future.
|
| 323 |
+
verbose : bool, default is False
|
| 324 |
+
Sets the verbosity of the pytest output. Using `True` will add the
|
| 325 |
+
`--verbose` option to the pytest call.
|
| 326 |
+
tb : str, 'auto', 'long', 'short', 'line', 'native', or 'no'
|
| 327 |
+
Sets the traceback print mode of pytest using the `--tb` option.
|
| 328 |
+
kw : str
|
| 329 |
+
Only run tests which match the given substring expression. An expression
|
| 330 |
+
is a Python evaluatable expression where all names are substring-matched
|
| 331 |
+
against test names and their parent classes. Example: -k 'test_method or
|
| 332 |
+
test_other' matches all test functions and classes whose name contains
|
| 333 |
+
'test_method' or 'test_other', while -k 'not test_method' matches those
|
| 334 |
+
that don't contain 'test_method' in their names. -k 'not test_method and
|
| 335 |
+
not test_other' will eliminate the matches. Additionally keywords are
|
| 336 |
+
matched to classes and functions containing extra names in their
|
| 337 |
+
'extra_keyword_matches' set, as well as functions which have names
|
| 338 |
+
assigned directly to them. The matching is case-insensitive.
|
| 339 |
+
pdb : bool, default is False
|
| 340 |
+
Start the interactive Python debugger on errors or `KeyboardInterrupt`.
|
| 341 |
+
colors : bool, default is True
|
| 342 |
+
Color terminal output.
|
| 343 |
+
force_colors : bool, default is False
|
| 344 |
+
Legacy option, is ignored.
|
| 345 |
+
sort : bool, default is True
|
| 346 |
+
Run the tests in sorted order. pytest uses a sorted test order by
|
| 347 |
+
default. Requires pytest-randomly.
|
| 348 |
+
seed : int
|
| 349 |
+
Seed to use for random number generation. Requires pytest-randomly.
|
| 350 |
+
timeout : int, default is 0
|
| 351 |
+
Timeout in seconds before dumping the stacks. 0 means no timeout.
|
| 352 |
+
Requires pytest-timeout.
|
| 353 |
+
fail_on_timeout : bool, default is False
|
| 354 |
+
Legacy option, is currently ignored.
|
| 355 |
+
slow : bool, default is False
|
| 356 |
+
Run the subset of tests marked as `slow`.
|
| 357 |
+
enhance_asserts : bool, default is False
|
| 358 |
+
Legacy option, is currently ignored.
|
| 359 |
+
split : string in form `<SPLIT>/<GROUPS>` or None, default is None
|
| 360 |
+
Used to split the tests up. As an example, if `split='2/3' is used then
|
| 361 |
+
only the middle third of tests are run. Requires pytest-split.
|
| 362 |
+
time_balance : bool, default is True
|
| 363 |
+
Legacy option, is currently ignored.
|
| 364 |
+
blacklist : iterable of test paths as strings, default is BLACKLIST_DEFAULT
|
| 365 |
+
Blacklisted test paths are ignored using the `--ignore` option. Paths
|
| 366 |
+
may be partial or absolute. If partial then they are matched against
|
| 367 |
+
all paths in the pytest tests path.
|
| 368 |
+
parallel : bool, default is False
|
| 369 |
+
Parallelize the test running using pytest-xdist. If `True` then pytest
|
| 370 |
+
will automatically detect the number of CPU cores available and use them
|
| 371 |
+
all. Requires pytest-xdist.
|
| 372 |
+
store_durations : bool, False
|
| 373 |
+
Store test durations into the file `.test_durations`. The is used by
|
| 374 |
+
`pytest-split` to help determine more even splits when more than one
|
| 375 |
+
test group is being used. Requires pytest-split.
|
| 376 |
+
|
| 377 |
+
"""
|
| 378 |
+
# NOTE: to be removed alongside SymPy test runner
|
| 379 |
+
if kwargs.get('use_sympy_runner', False):
|
| 380 |
+
kwargs.pop('parallel', False)
|
| 381 |
+
kwargs.pop('store_durations', False)
|
| 382 |
+
kwargs.pop('use_sympy_runner', True)
|
| 383 |
+
if kwargs.get('slow') is None:
|
| 384 |
+
kwargs['slow'] = False
|
| 385 |
+
return test_sympy(*paths, subprocess=True, rerun=0, **kwargs)
|
| 386 |
+
|
| 387 |
+
pytest_plugin_manager = PytestPluginManager()
|
| 388 |
+
if not pytest_plugin_manager.has_pytest:
|
| 389 |
+
pytest.main()
|
| 390 |
+
|
| 391 |
+
args = []
|
| 392 |
+
args = update_args_with_rootdir(args)
|
| 393 |
+
|
| 394 |
+
if kwargs.get('verbose', False):
|
| 395 |
+
args.append('--verbose')
|
| 396 |
+
|
| 397 |
+
if tb := kwargs.get('tb'):
|
| 398 |
+
args.extend(['--tb', tb])
|
| 399 |
+
|
| 400 |
+
if kwargs.get('pdb'):
|
| 401 |
+
args.append('--pdb')
|
| 402 |
+
|
| 403 |
+
if not kwargs.get('colors', True):
|
| 404 |
+
args.extend(['--color', 'no'])
|
| 405 |
+
|
| 406 |
+
if seed := kwargs.get('seed'):
|
| 407 |
+
if not pytest_plugin_manager.has_randomly:
|
| 408 |
+
msg = '`pytest-randomly` plugin required to control random seed.'
|
| 409 |
+
raise ModuleNotFoundError(msg)
|
| 410 |
+
args.extend(['--randomly-seed', str(seed)])
|
| 411 |
+
|
| 412 |
+
if kwargs.get('sort', True) and pytest_plugin_manager.has_randomly:
|
| 413 |
+
args.append('--randomly-dont-reorganize')
|
| 414 |
+
elif not kwargs.get('sort', True) and not pytest_plugin_manager.has_randomly:
|
| 415 |
+
msg = '`pytest-randomly` plugin required to randomize test order.'
|
| 416 |
+
raise ModuleNotFoundError(msg)
|
| 417 |
+
|
| 418 |
+
if timeout := kwargs.get('timeout', None):
|
| 419 |
+
if not pytest_plugin_manager.has_timeout:
|
| 420 |
+
msg = '`pytest-timeout` plugin required to apply timeout to tests.'
|
| 421 |
+
raise ModuleNotFoundError(msg)
|
| 422 |
+
args.extend(['--timeout', str(int(timeout))])
|
| 423 |
+
|
| 424 |
+
# Skip slow tests by default and always skip tooslow tests
|
| 425 |
+
if kwargs.get('slow', False):
|
| 426 |
+
args.extend(['-m', 'slow and not tooslow'])
|
| 427 |
+
else:
|
| 428 |
+
args.extend(['-m', 'not slow and not tooslow'])
|
| 429 |
+
|
| 430 |
+
if (split := kwargs.get('split')) is not None:
|
| 431 |
+
if not pytest_plugin_manager.has_split:
|
| 432 |
+
msg = '`pytest-split` plugin required to run tests as groups.'
|
| 433 |
+
raise ModuleNotFoundError(msg)
|
| 434 |
+
match = split_pattern.match(split)
|
| 435 |
+
if not match:
|
| 436 |
+
msg = ('split must be a string of the form a/b where a and b are '
|
| 437 |
+
'positive nonzero ints')
|
| 438 |
+
raise ValueError(msg)
|
| 439 |
+
group, splits = map(str, match.groups())
|
| 440 |
+
args.extend(['--group', group, '--splits', splits])
|
| 441 |
+
if group > splits:
|
| 442 |
+
msg = (f'cannot have a group number {group} with only {splits} '
|
| 443 |
+
'splits')
|
| 444 |
+
raise ValueError(msg)
|
| 445 |
+
|
| 446 |
+
if blacklist := kwargs.get('blacklist', BLACKLIST_DEFAULT):
|
| 447 |
+
for path in blacklist:
|
| 448 |
+
args.extend(['--ignore', make_absolute_path(path)])
|
| 449 |
+
|
| 450 |
+
if kwargs.get('parallel', False):
|
| 451 |
+
if not pytest_plugin_manager.has_xdist:
|
| 452 |
+
msg = '`pytest-xdist` plugin required to run tests in parallel.'
|
| 453 |
+
raise ModuleNotFoundError(msg)
|
| 454 |
+
args.extend(['-n', 'auto'])
|
| 455 |
+
|
| 456 |
+
if kwargs.get('store_durations', False):
|
| 457 |
+
if not pytest_plugin_manager.has_split:
|
| 458 |
+
msg = '`pytest-split` plugin required to store test durations.'
|
| 459 |
+
raise ModuleNotFoundError(msg)
|
| 460 |
+
args.append('--store-durations')
|
| 461 |
+
|
| 462 |
+
if (keywords := kwargs.get('kw')) is not None:
|
| 463 |
+
keywords = tuple(str(kw) for kw in keywords)
|
| 464 |
+
else:
|
| 465 |
+
keywords = ()
|
| 466 |
+
|
| 467 |
+
args = update_args_with_paths(paths, keywords, args)
|
| 468 |
+
exit_code = pytest.main(args)
|
| 469 |
+
return exit_code
|
| 470 |
+
|
| 471 |
+
|
| 472 |
+
def doctest():
|
| 473 |
+
"""Interface to run doctests via pytest compatible with SymPy's test runner.
|
| 474 |
+
"""
|
| 475 |
+
raise NotImplementedError
|
mplug_owl2/lib/python3.10/site-packages/s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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
|
| 3 |
+
from sympy.testing.pytest import (raises, warns, ignore_warnings,
|
| 4 |
+
warns_deprecated_sympy, Failed)
|
| 5 |
+
from sympy.utilities.exceptions import sympy_deprecation_warning
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# Test callables
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_expected_exception_is_silent_callable():
|
| 13 |
+
def f():
|
| 14 |
+
raise ValueError()
|
| 15 |
+
raises(ValueError, f)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# Under pytest raises will raise Failed rather than AssertionError
|
| 19 |
+
def test_lack_of_exception_triggers_AssertionError_callable():
|
| 20 |
+
try:
|
| 21 |
+
raises(Exception, lambda: 1 + 1)
|
| 22 |
+
assert False
|
| 23 |
+
except Failed as e:
|
| 24 |
+
assert "DID NOT RAISE" in str(e)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_unexpected_exception_is_passed_through_callable():
|
| 28 |
+
def f():
|
| 29 |
+
raise ValueError("some error message")
|
| 30 |
+
try:
|
| 31 |
+
raises(TypeError, f)
|
| 32 |
+
assert False
|
| 33 |
+
except ValueError as e:
|
| 34 |
+
assert str(e) == "some error message"
|
| 35 |
+
|
| 36 |
+
# Test with statement
|
| 37 |
+
|
| 38 |
+
def test_expected_exception_is_silent_with():
|
| 39 |
+
with raises(ValueError):
|
| 40 |
+
raise ValueError()
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def test_lack_of_exception_triggers_AssertionError_with():
|
| 44 |
+
try:
|
| 45 |
+
with raises(Exception):
|
| 46 |
+
1 + 1
|
| 47 |
+
assert False
|
| 48 |
+
except Failed as e:
|
| 49 |
+
assert "DID NOT RAISE" in str(e)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def test_unexpected_exception_is_passed_through_with():
|
| 53 |
+
try:
|
| 54 |
+
with raises(TypeError):
|
| 55 |
+
raise ValueError("some error message")
|
| 56 |
+
assert False
|
| 57 |
+
except ValueError as e:
|
| 58 |
+
assert str(e) == "some error message"
|
| 59 |
+
|
| 60 |
+
# Now we can use raises() instead of try/catch
|
| 61 |
+
# to test that a specific exception class is raised
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def test_second_argument_should_be_callable_or_string():
|
| 65 |
+
raises(TypeError, lambda: raises("irrelevant", 42))
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def test_warns_catches_warning():
|
| 69 |
+
with warnings.catch_warnings(record=True) as w:
|
| 70 |
+
with warns(UserWarning):
|
| 71 |
+
warnings.warn('this is the warning message')
|
| 72 |
+
assert len(w) == 0
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def test_warns_raises_without_warning():
|
| 76 |
+
with raises(Failed):
|
| 77 |
+
with warns(UserWarning):
|
| 78 |
+
pass
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def test_warns_hides_other_warnings():
|
| 82 |
+
with raises(RuntimeWarning):
|
| 83 |
+
with warns(UserWarning):
|
| 84 |
+
warnings.warn('this is the warning message', UserWarning)
|
| 85 |
+
warnings.warn('this is the other message', RuntimeWarning)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def test_warns_continues_after_warning():
|
| 89 |
+
with warnings.catch_warnings(record=True) as w:
|
| 90 |
+
finished = False
|
| 91 |
+
with warns(UserWarning):
|
| 92 |
+
warnings.warn('this is the warning message')
|
| 93 |
+
finished = True
|
| 94 |
+
assert finished
|
| 95 |
+
assert len(w) == 0
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def test_warns_many_warnings():
|
| 99 |
+
with warns(UserWarning):
|
| 100 |
+
warnings.warn('this is the warning message', UserWarning)
|
| 101 |
+
warnings.warn('this is the other warning message', UserWarning)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def test_warns_match_matching():
|
| 105 |
+
with warnings.catch_warnings(record=True) as w:
|
| 106 |
+
with warns(UserWarning, match='this is the warning message'):
|
| 107 |
+
warnings.warn('this is the warning message', UserWarning)
|
| 108 |
+
assert len(w) == 0
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def test_warns_match_non_matching():
|
| 112 |
+
with warnings.catch_warnings(record=True) as w:
|
| 113 |
+
with raises(Failed):
|
| 114 |
+
with warns(UserWarning, match='this is the warning message'):
|
| 115 |
+
warnings.warn('this is not the expected warning message', UserWarning)
|
| 116 |
+
assert len(w) == 0
|
| 117 |
+
|
| 118 |
+
def _warn_sympy_deprecation(stacklevel=3):
|
| 119 |
+
sympy_deprecation_warning(
|
| 120 |
+
"feature",
|
| 121 |
+
active_deprecations_target="active-deprecations",
|
| 122 |
+
deprecated_since_version="0.0.0",
|
| 123 |
+
stacklevel=stacklevel,
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
def test_warns_deprecated_sympy_catches_warning():
|
| 127 |
+
with warnings.catch_warnings(record=True) as w:
|
| 128 |
+
with warns_deprecated_sympy():
|
| 129 |
+
_warn_sympy_deprecation()
|
| 130 |
+
assert len(w) == 0
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def test_warns_deprecated_sympy_raises_without_warning():
|
| 134 |
+
with raises(Failed):
|
| 135 |
+
with warns_deprecated_sympy():
|
| 136 |
+
pass
|
| 137 |
+
|
| 138 |
+
def test_warns_deprecated_sympy_wrong_stacklevel():
|
| 139 |
+
with raises(Failed):
|
| 140 |
+
with warns_deprecated_sympy():
|
| 141 |
+
_warn_sympy_deprecation(stacklevel=1)
|
| 142 |
+
|
| 143 |
+
def test_warns_deprecated_sympy_doesnt_hide_other_warnings():
|
| 144 |
+
# Unlike pytest's deprecated_call, we should not hide other warnings.
|
| 145 |
+
with raises(RuntimeWarning):
|
| 146 |
+
with warns_deprecated_sympy():
|
| 147 |
+
_warn_sympy_deprecation()
|
| 148 |
+
warnings.warn('this is the other message', RuntimeWarning)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def test_warns_deprecated_sympy_continues_after_warning():
|
| 152 |
+
with warnings.catch_warnings(record=True) as w:
|
| 153 |
+
finished = False
|
| 154 |
+
with warns_deprecated_sympy():
|
| 155 |
+
_warn_sympy_deprecation()
|
| 156 |
+
finished = True
|
| 157 |
+
assert finished
|
| 158 |
+
assert len(w) == 0
|
| 159 |
+
|
| 160 |
+
def test_ignore_ignores_warning():
|
| 161 |
+
with warnings.catch_warnings(record=True) as w:
|
| 162 |
+
with ignore_warnings(UserWarning):
|
| 163 |
+
warnings.warn('this is the warning message')
|
| 164 |
+
assert len(w) == 0
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def test_ignore_does_not_raise_without_warning():
|
| 168 |
+
with warnings.catch_warnings(record=True) as w:
|
| 169 |
+
with ignore_warnings(UserWarning):
|
| 170 |
+
pass
|
| 171 |
+
assert len(w) == 0
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def test_ignore_allows_other_warnings():
|
| 175 |
+
with warnings.catch_warnings(record=True) as w:
|
| 176 |
+
# This is needed when pytest is run as -Werror
|
| 177 |
+
# the setting is reverted at the end of the catch_Warnings block.
|
| 178 |
+
warnings.simplefilter("always")
|
| 179 |
+
with ignore_warnings(UserWarning):
|
| 180 |
+
warnings.warn('this is the warning message', UserWarning)
|
| 181 |
+
warnings.warn('this is the other message', RuntimeWarning)
|
| 182 |
+
assert len(w) == 1
|
| 183 |
+
assert isinstance(w[0].message, RuntimeWarning)
|
| 184 |
+
assert str(w[0].message) == 'this is the other message'
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def test_ignore_continues_after_warning():
|
| 188 |
+
with warnings.catch_warnings(record=True) as w:
|
| 189 |
+
finished = False
|
| 190 |
+
with ignore_warnings(UserWarning):
|
| 191 |
+
warnings.warn('this is the warning message')
|
| 192 |
+
finished = True
|
| 193 |
+
assert finished
|
| 194 |
+
assert len(w) == 0
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def test_ignore_many_warnings():
|
| 198 |
+
with warnings.catch_warnings(record=True) as w:
|
| 199 |
+
# This is needed when pytest is run as -Werror
|
| 200 |
+
# the setting is reverted at the end of the catch_Warnings block.
|
| 201 |
+
warnings.simplefilter("always")
|
| 202 |
+
with ignore_warnings(UserWarning):
|
| 203 |
+
warnings.warn('this is the warning message', UserWarning)
|
| 204 |
+
warnings.warn('this is the other message', RuntimeWarning)
|
| 205 |
+
warnings.warn('this is the warning message', UserWarning)
|
| 206 |
+
warnings.warn('this is the other message', RuntimeWarning)
|
| 207 |
+
warnings.warn('this is the other message', RuntimeWarning)
|
| 208 |
+
assert len(w) == 3
|
| 209 |
+
for wi in w:
|
| 210 |
+
assert isinstance(wi.message, RuntimeWarning)
|
| 211 |
+
assert str(wi.message) == 'this is the other message'
|
mplug_owl2/lib/python3.10/site-packages/sympy/testing/tmpfiles.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This module adds context manager for temporary files generated by the tests.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import shutil
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class TmpFileManager:
|
| 10 |
+
"""
|
| 11 |
+
A class to track record of every temporary files created by the tests.
|
| 12 |
+
"""
|
| 13 |
+
tmp_files = set('')
|
| 14 |
+
tmp_folders = set('')
|
| 15 |
+
|
| 16 |
+
@classmethod
|
| 17 |
+
def tmp_file(cls, name=''):
|
| 18 |
+
cls.tmp_files.add(name)
|
| 19 |
+
return name
|
| 20 |
+
|
| 21 |
+
@classmethod
|
| 22 |
+
def tmp_folder(cls, name=''):
|
| 23 |
+
cls.tmp_folders.add(name)
|
| 24 |
+
return name
|
| 25 |
+
|
| 26 |
+
@classmethod
|
| 27 |
+
def cleanup(cls):
|
| 28 |
+
while cls.tmp_files:
|
| 29 |
+
file = cls.tmp_files.pop()
|
| 30 |
+
if os.path.isfile(file):
|
| 31 |
+
os.remove(file)
|
| 32 |
+
while cls.tmp_folders:
|
| 33 |
+
folder = cls.tmp_folders.pop()
|
| 34 |
+
shutil.rmtree(folder)
|
| 35 |
+
|
| 36 |
+
def cleanup_tmp_files(test_func):
|
| 37 |
+
"""
|
| 38 |
+
A decorator to help test codes remove temporary files after the tests.
|
| 39 |
+
"""
|
| 40 |
+
def wrapper_function():
|
| 41 |
+
try:
|
| 42 |
+
test_func()
|
| 43 |
+
finally:
|
| 44 |
+
TmpFileManager.cleanup()
|
| 45 |
+
|
| 46 |
+
return wrapper_function
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (1.75 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/basisdependent.cpython-310.pyc
ADDED
|
Binary file (12.2 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/coordsysrect.cpython-310.pyc
ADDED
|
Binary file (31.4 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/deloperator.cpython-310.pyc
ADDED
|
Binary file (3.69 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/dyadic.cpython-310.pyc
ADDED
|
Binary file (8.97 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/implicitregion.cpython-310.pyc
ADDED
|
Binary file (12.7 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/integrals.cpython-310.pyc
ADDED
|
Binary file (6.05 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/operators.cpython-310.pyc
ADDED
|
Binary file (9.75 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/orienters.cpython-310.pyc
ADDED
|
Binary file (12.2 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/parametricregion.cpython-310.pyc
ADDED
|
Binary file (6.38 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/point.cpython-310.pyc
ADDED
|
Binary file (4.11 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/scalar.cpython-310.pyc
ADDED
|
Binary file (2.34 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/__pycache__/vector.cpython-310.pyc
ADDED
|
Binary file (18.1 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/__pycache__/test_coordsysrect.cpython-310.pyc
ADDED
|
Binary file (17.1 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/__pycache__/test_dyadic.cpython-310.pyc
ADDED
|
Binary file (4.6 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/__pycache__/test_functions.cpython-310.pyc
ADDED
|
Binary file (7.56 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/__pycache__/test_integrals.cpython-310.pyc
ADDED
|
Binary file (5.16 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/__pycache__/test_vector.cpython-310.pyc
ADDED
|
Binary file (8.81 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/test_coordsysrect.py
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 3 |
+
from sympy.vector.scalar import BaseScalar
|
| 4 |
+
from sympy.core.function import expand
|
| 5 |
+
from sympy.core.numbers import pi
|
| 6 |
+
from sympy.core.symbol import symbols
|
| 7 |
+
from sympy.functions.elementary.hyperbolic import (cosh, sinh)
|
| 8 |
+
from sympy.functions.elementary.miscellaneous import sqrt
|
| 9 |
+
from sympy.functions.elementary.trigonometric import (acos, atan2, cos, sin)
|
| 10 |
+
from sympy.matrices.dense import zeros
|
| 11 |
+
from sympy.matrices.immutable import ImmutableDenseMatrix as Matrix
|
| 12 |
+
from sympy.simplify.simplify import simplify
|
| 13 |
+
from sympy.vector.functions import express
|
| 14 |
+
from sympy.vector.point import Point
|
| 15 |
+
from sympy.vector.vector import Vector
|
| 16 |
+
from sympy.vector.orienters import (AxisOrienter, BodyOrienter,
|
| 17 |
+
SpaceOrienter, QuaternionOrienter)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
x, y, z = symbols('x y z')
|
| 21 |
+
a, b, c, q = symbols('a b c q')
|
| 22 |
+
q1, q2, q3, q4 = symbols('q1 q2 q3 q4')
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def test_func_args():
|
| 26 |
+
A = CoordSys3D('A')
|
| 27 |
+
assert A.x.func(*A.x.args) == A.x
|
| 28 |
+
expr = 3*A.x + 4*A.y
|
| 29 |
+
assert expr.func(*expr.args) == expr
|
| 30 |
+
assert A.i.func(*A.i.args) == A.i
|
| 31 |
+
v = A.x*A.i + A.y*A.j + A.z*A.k
|
| 32 |
+
assert v.func(*v.args) == v
|
| 33 |
+
assert A.origin.func(*A.origin.args) == A.origin
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def test_coordsys3d_equivalence():
|
| 37 |
+
A = CoordSys3D('A')
|
| 38 |
+
A1 = CoordSys3D('A')
|
| 39 |
+
assert A1 == A
|
| 40 |
+
B = CoordSys3D('B')
|
| 41 |
+
assert A != B
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def test_orienters():
|
| 45 |
+
A = CoordSys3D('A')
|
| 46 |
+
axis_orienter = AxisOrienter(a, A.k)
|
| 47 |
+
body_orienter = BodyOrienter(a, b, c, '123')
|
| 48 |
+
space_orienter = SpaceOrienter(a, b, c, '123')
|
| 49 |
+
q_orienter = QuaternionOrienter(q1, q2, q3, q4)
|
| 50 |
+
assert axis_orienter.rotation_matrix(A) == Matrix([
|
| 51 |
+
[ cos(a), sin(a), 0],
|
| 52 |
+
[-sin(a), cos(a), 0],
|
| 53 |
+
[ 0, 0, 1]])
|
| 54 |
+
assert body_orienter.rotation_matrix() == Matrix([
|
| 55 |
+
[ cos(b)*cos(c), sin(a)*sin(b)*cos(c) + sin(c)*cos(a),
|
| 56 |
+
sin(a)*sin(c) - sin(b)*cos(a)*cos(c)],
|
| 57 |
+
[-sin(c)*cos(b), -sin(a)*sin(b)*sin(c) + cos(a)*cos(c),
|
| 58 |
+
sin(a)*cos(c) + sin(b)*sin(c)*cos(a)],
|
| 59 |
+
[ sin(b), -sin(a)*cos(b),
|
| 60 |
+
cos(a)*cos(b)]])
|
| 61 |
+
assert space_orienter.rotation_matrix() == Matrix([
|
| 62 |
+
[cos(b)*cos(c), sin(c)*cos(b), -sin(b)],
|
| 63 |
+
[sin(a)*sin(b)*cos(c) - sin(c)*cos(a),
|
| 64 |
+
sin(a)*sin(b)*sin(c) + cos(a)*cos(c), sin(a)*cos(b)],
|
| 65 |
+
[sin(a)*sin(c) + sin(b)*cos(a)*cos(c), -sin(a)*cos(c) +
|
| 66 |
+
sin(b)*sin(c)*cos(a), cos(a)*cos(b)]])
|
| 67 |
+
assert q_orienter.rotation_matrix() == Matrix([
|
| 68 |
+
[q1**2 + q2**2 - q3**2 - q4**2, 2*q1*q4 + 2*q2*q3,
|
| 69 |
+
-2*q1*q3 + 2*q2*q4],
|
| 70 |
+
[-2*q1*q4 + 2*q2*q3, q1**2 - q2**2 + q3**2 - q4**2,
|
| 71 |
+
2*q1*q2 + 2*q3*q4],
|
| 72 |
+
[2*q1*q3 + 2*q2*q4,
|
| 73 |
+
-2*q1*q2 + 2*q3*q4, q1**2 - q2**2 - q3**2 + q4**2]])
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def test_coordinate_vars():
|
| 77 |
+
"""
|
| 78 |
+
Tests the coordinate variables functionality with respect to
|
| 79 |
+
reorientation of coordinate systems.
|
| 80 |
+
"""
|
| 81 |
+
A = CoordSys3D('A')
|
| 82 |
+
# Note that the name given on the lhs is different from A.x._name
|
| 83 |
+
assert BaseScalar(0, A, 'A_x', r'\mathbf{{x}_{A}}') == A.x
|
| 84 |
+
assert BaseScalar(1, A, 'A_y', r'\mathbf{{y}_{A}}') == A.y
|
| 85 |
+
assert BaseScalar(2, A, 'A_z', r'\mathbf{{z}_{A}}') == A.z
|
| 86 |
+
assert BaseScalar(0, A, 'A_x', r'\mathbf{{x}_{A}}').__hash__() == A.x.__hash__()
|
| 87 |
+
assert isinstance(A.x, BaseScalar) and \
|
| 88 |
+
isinstance(A.y, BaseScalar) and \
|
| 89 |
+
isinstance(A.z, BaseScalar)
|
| 90 |
+
assert A.x*A.y == A.y*A.x
|
| 91 |
+
assert A.scalar_map(A) == {A.x: A.x, A.y: A.y, A.z: A.z}
|
| 92 |
+
assert A.x.system == A
|
| 93 |
+
assert A.x.diff(A.x) == 1
|
| 94 |
+
B = A.orient_new_axis('B', q, A.k)
|
| 95 |
+
assert B.scalar_map(A) == {B.z: A.z, B.y: -A.x*sin(q) + A.y*cos(q),
|
| 96 |
+
B.x: A.x*cos(q) + A.y*sin(q)}
|
| 97 |
+
assert A.scalar_map(B) == {A.x: B.x*cos(q) - B.y*sin(q),
|
| 98 |
+
A.y: B.x*sin(q) + B.y*cos(q), A.z: B.z}
|
| 99 |
+
assert express(B.x, A, variables=True) == A.x*cos(q) + A.y*sin(q)
|
| 100 |
+
assert express(B.y, A, variables=True) == -A.x*sin(q) + A.y*cos(q)
|
| 101 |
+
assert express(B.z, A, variables=True) == A.z
|
| 102 |
+
assert expand(express(B.x*B.y*B.z, A, variables=True)) == \
|
| 103 |
+
expand(A.z*(-A.x*sin(q) + A.y*cos(q))*(A.x*cos(q) + A.y*sin(q)))
|
| 104 |
+
assert express(B.x*B.i + B.y*B.j + B.z*B.k, A) == \
|
| 105 |
+
(B.x*cos(q) - B.y*sin(q))*A.i + (B.x*sin(q) + \
|
| 106 |
+
B.y*cos(q))*A.j + B.z*A.k
|
| 107 |
+
assert simplify(express(B.x*B.i + B.y*B.j + B.z*B.k, A, \
|
| 108 |
+
variables=True)) == \
|
| 109 |
+
A.x*A.i + A.y*A.j + A.z*A.k
|
| 110 |
+
assert express(A.x*A.i + A.y*A.j + A.z*A.k, B) == \
|
| 111 |
+
(A.x*cos(q) + A.y*sin(q))*B.i + \
|
| 112 |
+
(-A.x*sin(q) + A.y*cos(q))*B.j + A.z*B.k
|
| 113 |
+
assert simplify(express(A.x*A.i + A.y*A.j + A.z*A.k, B, \
|
| 114 |
+
variables=True)) == \
|
| 115 |
+
B.x*B.i + B.y*B.j + B.z*B.k
|
| 116 |
+
N = B.orient_new_axis('N', -q, B.k)
|
| 117 |
+
assert N.scalar_map(A) == \
|
| 118 |
+
{N.x: A.x, N.z: A.z, N.y: A.y}
|
| 119 |
+
C = A.orient_new_axis('C', q, A.i + A.j + A.k)
|
| 120 |
+
mapping = A.scalar_map(C)
|
| 121 |
+
assert mapping[A.x].equals(C.x*(2*cos(q) + 1)/3 +
|
| 122 |
+
C.y*(-2*sin(q + pi/6) + 1)/3 +
|
| 123 |
+
C.z*(-2*cos(q + pi/3) + 1)/3)
|
| 124 |
+
assert mapping[A.y].equals(C.x*(-2*cos(q + pi/3) + 1)/3 +
|
| 125 |
+
C.y*(2*cos(q) + 1)/3 +
|
| 126 |
+
C.z*(-2*sin(q + pi/6) + 1)/3)
|
| 127 |
+
assert mapping[A.z].equals(C.x*(-2*sin(q + pi/6) + 1)/3 +
|
| 128 |
+
C.y*(-2*cos(q + pi/3) + 1)/3 +
|
| 129 |
+
C.z*(2*cos(q) + 1)/3)
|
| 130 |
+
D = A.locate_new('D', a*A.i + b*A.j + c*A.k)
|
| 131 |
+
assert D.scalar_map(A) == {D.z: A.z - c, D.x: A.x - a, D.y: A.y - b}
|
| 132 |
+
E = A.orient_new_axis('E', a, A.k, a*A.i + b*A.j + c*A.k)
|
| 133 |
+
assert A.scalar_map(E) == {A.z: E.z + c,
|
| 134 |
+
A.x: E.x*cos(a) - E.y*sin(a) + a,
|
| 135 |
+
A.y: E.x*sin(a) + E.y*cos(a) + b}
|
| 136 |
+
assert E.scalar_map(A) == {E.x: (A.x - a)*cos(a) + (A.y - b)*sin(a),
|
| 137 |
+
E.y: (-A.x + a)*sin(a) + (A.y - b)*cos(a),
|
| 138 |
+
E.z: A.z - c}
|
| 139 |
+
F = A.locate_new('F', Vector.zero)
|
| 140 |
+
assert A.scalar_map(F) == {A.z: F.z, A.x: F.x, A.y: F.y}
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def test_rotation_matrix():
|
| 144 |
+
N = CoordSys3D('N')
|
| 145 |
+
A = N.orient_new_axis('A', q1, N.k)
|
| 146 |
+
B = A.orient_new_axis('B', q2, A.i)
|
| 147 |
+
C = B.orient_new_axis('C', q3, B.j)
|
| 148 |
+
D = N.orient_new_axis('D', q4, N.j)
|
| 149 |
+
E = N.orient_new_space('E', q1, q2, q3, '123')
|
| 150 |
+
F = N.orient_new_quaternion('F', q1, q2, q3, q4)
|
| 151 |
+
G = N.orient_new_body('G', q1, q2, q3, '123')
|
| 152 |
+
assert N.rotation_matrix(C) == Matrix([
|
| 153 |
+
[- sin(q1) * sin(q2) * sin(q3) + cos(q1) * cos(q3), - sin(q1) *
|
| 154 |
+
cos(q2), sin(q1) * sin(q2) * cos(q3) + sin(q3) * cos(q1)], \
|
| 155 |
+
[sin(q1) * cos(q3) + sin(q2) * sin(q3) * cos(q1), \
|
| 156 |
+
cos(q1) * cos(q2), sin(q1) * sin(q3) - sin(q2) * cos(q1) * \
|
| 157 |
+
cos(q3)], [- sin(q3) * cos(q2), sin(q2), cos(q2) * cos(q3)]])
|
| 158 |
+
test_mat = D.rotation_matrix(C) - Matrix(
|
| 159 |
+
[[cos(q1) * cos(q3) * cos(q4) - sin(q3) * (- sin(q4) * cos(q2) +
|
| 160 |
+
sin(q1) * sin(q2) * cos(q4)), - sin(q2) * sin(q4) - sin(q1) *
|
| 161 |
+
cos(q2) * cos(q4), sin(q3) * cos(q1) * cos(q4) + cos(q3) * \
|
| 162 |
+
(- sin(q4) * cos(q2) + sin(q1) * sin(q2) * cos(q4))], \
|
| 163 |
+
[sin(q1) * cos(q3) + sin(q2) * sin(q3) * cos(q1), cos(q1) * \
|
| 164 |
+
cos(q2), sin(q1) * sin(q3) - sin(q2) * cos(q1) * cos(q3)], \
|
| 165 |
+
[sin(q4) * cos(q1) * cos(q3) - sin(q3) * (cos(q2) * cos(q4) + \
|
| 166 |
+
sin(q1) * sin(q2) * \
|
| 167 |
+
sin(q4)), sin(q2) *
|
| 168 |
+
cos(q4) - sin(q1) * sin(q4) * cos(q2), sin(q3) * \
|
| 169 |
+
sin(q4) * cos(q1) + cos(q3) * (cos(q2) * cos(q4) + \
|
| 170 |
+
sin(q1) * sin(q2) * sin(q4))]])
|
| 171 |
+
assert test_mat.expand() == zeros(3, 3)
|
| 172 |
+
assert E.rotation_matrix(N) == Matrix(
|
| 173 |
+
[[cos(q2)*cos(q3), sin(q3)*cos(q2), -sin(q2)],
|
| 174 |
+
[sin(q1)*sin(q2)*cos(q3) - sin(q3)*cos(q1), \
|
| 175 |
+
sin(q1)*sin(q2)*sin(q3) + cos(q1)*cos(q3), sin(q1)*cos(q2)], \
|
| 176 |
+
[sin(q1)*sin(q3) + sin(q2)*cos(q1)*cos(q3), - \
|
| 177 |
+
sin(q1)*cos(q3) + sin(q2)*sin(q3)*cos(q1), cos(q1)*cos(q2)]])
|
| 178 |
+
assert F.rotation_matrix(N) == Matrix([[
|
| 179 |
+
q1**2 + q2**2 - q3**2 - q4**2,
|
| 180 |
+
2*q1*q4 + 2*q2*q3, -2*q1*q3 + 2*q2*q4],[ -2*q1*q4 + 2*q2*q3,
|
| 181 |
+
q1**2 - q2**2 + q3**2 - q4**2, 2*q1*q2 + 2*q3*q4],
|
| 182 |
+
[2*q1*q3 + 2*q2*q4,
|
| 183 |
+
-2*q1*q2 + 2*q3*q4,
|
| 184 |
+
q1**2 - q2**2 - q3**2 + q4**2]])
|
| 185 |
+
assert G.rotation_matrix(N) == Matrix([[
|
| 186 |
+
cos(q2)*cos(q3), sin(q1)*sin(q2)*cos(q3) + sin(q3)*cos(q1),
|
| 187 |
+
sin(q1)*sin(q3) - sin(q2)*cos(q1)*cos(q3)], [
|
| 188 |
+
-sin(q3)*cos(q2), -sin(q1)*sin(q2)*sin(q3) + cos(q1)*cos(q3),
|
| 189 |
+
sin(q1)*cos(q3) + sin(q2)*sin(q3)*cos(q1)],[
|
| 190 |
+
sin(q2), -sin(q1)*cos(q2), cos(q1)*cos(q2)]])
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def test_vector_with_orientation():
|
| 194 |
+
"""
|
| 195 |
+
Tests the effects of orientation of coordinate systems on
|
| 196 |
+
basic vector operations.
|
| 197 |
+
"""
|
| 198 |
+
N = CoordSys3D('N')
|
| 199 |
+
A = N.orient_new_axis('A', q1, N.k)
|
| 200 |
+
B = A.orient_new_axis('B', q2, A.i)
|
| 201 |
+
C = B.orient_new_axis('C', q3, B.j)
|
| 202 |
+
|
| 203 |
+
# Test to_matrix
|
| 204 |
+
v1 = a*N.i + b*N.j + c*N.k
|
| 205 |
+
assert v1.to_matrix(A) == Matrix([[ a*cos(q1) + b*sin(q1)],
|
| 206 |
+
[-a*sin(q1) + b*cos(q1)],
|
| 207 |
+
[ c]])
|
| 208 |
+
|
| 209 |
+
# Test dot
|
| 210 |
+
assert N.i.dot(A.i) == cos(q1)
|
| 211 |
+
assert N.i.dot(A.j) == -sin(q1)
|
| 212 |
+
assert N.i.dot(A.k) == 0
|
| 213 |
+
assert N.j.dot(A.i) == sin(q1)
|
| 214 |
+
assert N.j.dot(A.j) == cos(q1)
|
| 215 |
+
assert N.j.dot(A.k) == 0
|
| 216 |
+
assert N.k.dot(A.i) == 0
|
| 217 |
+
assert N.k.dot(A.j) == 0
|
| 218 |
+
assert N.k.dot(A.k) == 1
|
| 219 |
+
|
| 220 |
+
assert N.i.dot(A.i + A.j) == -sin(q1) + cos(q1) == \
|
| 221 |
+
(A.i + A.j).dot(N.i)
|
| 222 |
+
|
| 223 |
+
assert A.i.dot(C.i) == cos(q3)
|
| 224 |
+
assert A.i.dot(C.j) == 0
|
| 225 |
+
assert A.i.dot(C.k) == sin(q3)
|
| 226 |
+
assert A.j.dot(C.i) == sin(q2)*sin(q3)
|
| 227 |
+
assert A.j.dot(C.j) == cos(q2)
|
| 228 |
+
assert A.j.dot(C.k) == -sin(q2)*cos(q3)
|
| 229 |
+
assert A.k.dot(C.i) == -cos(q2)*sin(q3)
|
| 230 |
+
assert A.k.dot(C.j) == sin(q2)
|
| 231 |
+
assert A.k.dot(C.k) == cos(q2)*cos(q3)
|
| 232 |
+
|
| 233 |
+
# Test cross
|
| 234 |
+
assert N.i.cross(A.i) == sin(q1)*A.k
|
| 235 |
+
assert N.i.cross(A.j) == cos(q1)*A.k
|
| 236 |
+
assert N.i.cross(A.k) == -sin(q1)*A.i - cos(q1)*A.j
|
| 237 |
+
assert N.j.cross(A.i) == -cos(q1)*A.k
|
| 238 |
+
assert N.j.cross(A.j) == sin(q1)*A.k
|
| 239 |
+
assert N.j.cross(A.k) == cos(q1)*A.i - sin(q1)*A.j
|
| 240 |
+
assert N.k.cross(A.i) == A.j
|
| 241 |
+
assert N.k.cross(A.j) == -A.i
|
| 242 |
+
assert N.k.cross(A.k) == Vector.zero
|
| 243 |
+
|
| 244 |
+
assert N.i.cross(A.i) == sin(q1)*A.k
|
| 245 |
+
assert N.i.cross(A.j) == cos(q1)*A.k
|
| 246 |
+
assert N.i.cross(A.i + A.j) == sin(q1)*A.k + cos(q1)*A.k
|
| 247 |
+
assert (A.i + A.j).cross(N.i) == (-sin(q1) - cos(q1))*N.k
|
| 248 |
+
|
| 249 |
+
assert A.i.cross(C.i) == sin(q3)*C.j
|
| 250 |
+
assert A.i.cross(C.j) == -sin(q3)*C.i + cos(q3)*C.k
|
| 251 |
+
assert A.i.cross(C.k) == -cos(q3)*C.j
|
| 252 |
+
assert C.i.cross(A.i) == (-sin(q3)*cos(q2))*A.j + \
|
| 253 |
+
(-sin(q2)*sin(q3))*A.k
|
| 254 |
+
assert C.j.cross(A.i) == (sin(q2))*A.j + (-cos(q2))*A.k
|
| 255 |
+
assert express(C.k.cross(A.i), C).trigsimp() == cos(q3)*C.j
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def test_orient_new_methods():
|
| 259 |
+
N = CoordSys3D('N')
|
| 260 |
+
orienter1 = AxisOrienter(q4, N.j)
|
| 261 |
+
orienter2 = SpaceOrienter(q1, q2, q3, '123')
|
| 262 |
+
orienter3 = QuaternionOrienter(q1, q2, q3, q4)
|
| 263 |
+
orienter4 = BodyOrienter(q1, q2, q3, '123')
|
| 264 |
+
D = N.orient_new('D', (orienter1, ))
|
| 265 |
+
E = N.orient_new('E', (orienter2, ))
|
| 266 |
+
F = N.orient_new('F', (orienter3, ))
|
| 267 |
+
G = N.orient_new('G', (orienter4, ))
|
| 268 |
+
assert D == N.orient_new_axis('D', q4, N.j)
|
| 269 |
+
assert E == N.orient_new_space('E', q1, q2, q3, '123')
|
| 270 |
+
assert F == N.orient_new_quaternion('F', q1, q2, q3, q4)
|
| 271 |
+
assert G == N.orient_new_body('G', q1, q2, q3, '123')
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def test_locatenew_point():
|
| 275 |
+
"""
|
| 276 |
+
Tests Point class, and locate_new method in CoordSys3D.
|
| 277 |
+
"""
|
| 278 |
+
A = CoordSys3D('A')
|
| 279 |
+
assert isinstance(A.origin, Point)
|
| 280 |
+
v = a*A.i + b*A.j + c*A.k
|
| 281 |
+
C = A.locate_new('C', v)
|
| 282 |
+
assert C.origin.position_wrt(A) == \
|
| 283 |
+
C.position_wrt(A) == \
|
| 284 |
+
C.origin.position_wrt(A.origin) == v
|
| 285 |
+
assert A.origin.position_wrt(C) == \
|
| 286 |
+
A.position_wrt(C) == \
|
| 287 |
+
A.origin.position_wrt(C.origin) == -v
|
| 288 |
+
assert A.origin.express_coordinates(C) == (-a, -b, -c)
|
| 289 |
+
p = A.origin.locate_new('p', -v)
|
| 290 |
+
assert p.express_coordinates(A) == (-a, -b, -c)
|
| 291 |
+
assert p.position_wrt(C.origin) == p.position_wrt(C) == \
|
| 292 |
+
-2 * v
|
| 293 |
+
p1 = p.locate_new('p1', 2*v)
|
| 294 |
+
assert p1.position_wrt(C.origin) == Vector.zero
|
| 295 |
+
assert p1.express_coordinates(C) == (0, 0, 0)
|
| 296 |
+
p2 = p.locate_new('p2', A.i)
|
| 297 |
+
assert p1.position_wrt(p2) == 2*v - A.i
|
| 298 |
+
assert p2.express_coordinates(C) == (-2*a + 1, -2*b, -2*c)
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
def test_create_new():
|
| 302 |
+
a = CoordSys3D('a')
|
| 303 |
+
c = a.create_new('c', transformation='spherical')
|
| 304 |
+
assert c._parent == a
|
| 305 |
+
assert c.transformation_to_parent() == \
|
| 306 |
+
(c.r*sin(c.theta)*cos(c.phi), c.r*sin(c.theta)*sin(c.phi), c.r*cos(c.theta))
|
| 307 |
+
assert c.transformation_from_parent() == \
|
| 308 |
+
(sqrt(a.x**2 + a.y**2 + a.z**2), acos(a.z/sqrt(a.x**2 + a.y**2 + a.z**2)), atan2(a.y, a.x))
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
def test_evalf():
|
| 312 |
+
A = CoordSys3D('A')
|
| 313 |
+
v = 3*A.i + 4*A.j + a*A.k
|
| 314 |
+
assert v.n() == v.evalf()
|
| 315 |
+
assert v.evalf(subs={a:1}) == v.subs(a, 1).evalf()
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
def test_lame_coefficients():
|
| 319 |
+
a = CoordSys3D('a', 'spherical')
|
| 320 |
+
assert a.lame_coefficients() == (1, a.r, sin(a.theta)*a.r)
|
| 321 |
+
a = CoordSys3D('a')
|
| 322 |
+
assert a.lame_coefficients() == (1, 1, 1)
|
| 323 |
+
a = CoordSys3D('a', 'cartesian')
|
| 324 |
+
assert a.lame_coefficients() == (1, 1, 1)
|
| 325 |
+
a = CoordSys3D('a', 'cylindrical')
|
| 326 |
+
assert a.lame_coefficients() == (1, a.r, 1)
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
def test_transformation_equations():
|
| 330 |
+
|
| 331 |
+
x, y, z = symbols('x y z')
|
| 332 |
+
# Str
|
| 333 |
+
a = CoordSys3D('a', transformation='spherical',
|
| 334 |
+
variable_names=["r", "theta", "phi"])
|
| 335 |
+
r, theta, phi = a.base_scalars()
|
| 336 |
+
|
| 337 |
+
assert r == a.r
|
| 338 |
+
assert theta == a.theta
|
| 339 |
+
assert phi == a.phi
|
| 340 |
+
|
| 341 |
+
raises(AttributeError, lambda: a.x)
|
| 342 |
+
raises(AttributeError, lambda: a.y)
|
| 343 |
+
raises(AttributeError, lambda: a.z)
|
| 344 |
+
|
| 345 |
+
assert a.transformation_to_parent() == (
|
| 346 |
+
r*sin(theta)*cos(phi),
|
| 347 |
+
r*sin(theta)*sin(phi),
|
| 348 |
+
r*cos(theta)
|
| 349 |
+
)
|
| 350 |
+
assert a.lame_coefficients() == (1, r, r*sin(theta))
|
| 351 |
+
assert a.transformation_from_parent_function()(x, y, z) == (
|
| 352 |
+
sqrt(x ** 2 + y ** 2 + z ** 2),
|
| 353 |
+
acos((z) / sqrt(x**2 + y**2 + z**2)),
|
| 354 |
+
atan2(y, x)
|
| 355 |
+
)
|
| 356 |
+
a = CoordSys3D('a', transformation='cylindrical',
|
| 357 |
+
variable_names=["r", "theta", "z"])
|
| 358 |
+
r, theta, z = a.base_scalars()
|
| 359 |
+
assert a.transformation_to_parent() == (
|
| 360 |
+
r*cos(theta),
|
| 361 |
+
r*sin(theta),
|
| 362 |
+
z
|
| 363 |
+
)
|
| 364 |
+
assert a.lame_coefficients() == (1, a.r, 1)
|
| 365 |
+
assert a.transformation_from_parent_function()(x, y, z) == (sqrt(x**2 + y**2),
|
| 366 |
+
atan2(y, x), z)
|
| 367 |
+
|
| 368 |
+
a = CoordSys3D('a', 'cartesian')
|
| 369 |
+
assert a.transformation_to_parent() == (a.x, a.y, a.z)
|
| 370 |
+
assert a.lame_coefficients() == (1, 1, 1)
|
| 371 |
+
assert a.transformation_from_parent_function()(x, y, z) == (x, y, z)
|
| 372 |
+
|
| 373 |
+
# Variables and expressions
|
| 374 |
+
|
| 375 |
+
# Cartesian with equation tuple:
|
| 376 |
+
x, y, z = symbols('x y z')
|
| 377 |
+
a = CoordSys3D('a', ((x, y, z), (x, y, z)))
|
| 378 |
+
a._calculate_inv_trans_equations()
|
| 379 |
+
assert a.transformation_to_parent() == (a.x1, a.x2, a.x3)
|
| 380 |
+
assert a.lame_coefficients() == (1, 1, 1)
|
| 381 |
+
assert a.transformation_from_parent_function()(x, y, z) == (x, y, z)
|
| 382 |
+
r, theta, z = symbols("r theta z")
|
| 383 |
+
|
| 384 |
+
# Cylindrical with equation tuple:
|
| 385 |
+
a = CoordSys3D('a', [(r, theta, z), (r*cos(theta), r*sin(theta), z)],
|
| 386 |
+
variable_names=["r", "theta", "z"])
|
| 387 |
+
r, theta, z = a.base_scalars()
|
| 388 |
+
assert a.transformation_to_parent() == (
|
| 389 |
+
r*cos(theta), r*sin(theta), z
|
| 390 |
+
)
|
| 391 |
+
assert a.lame_coefficients() == (
|
| 392 |
+
sqrt(sin(theta)**2 + cos(theta)**2),
|
| 393 |
+
sqrt(r**2*sin(theta)**2 + r**2*cos(theta)**2),
|
| 394 |
+
1
|
| 395 |
+
) # ==> this should simplify to (1, r, 1), tests are too slow with `simplify`.
|
| 396 |
+
|
| 397 |
+
# Definitions with `lambda`:
|
| 398 |
+
|
| 399 |
+
# Cartesian with `lambda`
|
| 400 |
+
a = CoordSys3D('a', lambda x, y, z: (x, y, z))
|
| 401 |
+
assert a.transformation_to_parent() == (a.x1, a.x2, a.x3)
|
| 402 |
+
assert a.lame_coefficients() == (1, 1, 1)
|
| 403 |
+
a._calculate_inv_trans_equations()
|
| 404 |
+
assert a.transformation_from_parent_function()(x, y, z) == (x, y, z)
|
| 405 |
+
|
| 406 |
+
# Spherical with `lambda`
|
| 407 |
+
a = CoordSys3D('a', lambda r, theta, phi: (r*sin(theta)*cos(phi), r*sin(theta)*sin(phi), r*cos(theta)),
|
| 408 |
+
variable_names=["r", "theta", "phi"])
|
| 409 |
+
r, theta, phi = a.base_scalars()
|
| 410 |
+
assert a.transformation_to_parent() == (
|
| 411 |
+
r*sin(theta)*cos(phi), r*sin(phi)*sin(theta), r*cos(theta)
|
| 412 |
+
)
|
| 413 |
+
assert a.lame_coefficients() == (
|
| 414 |
+
sqrt(sin(phi)**2*sin(theta)**2 + sin(theta)**2*cos(phi)**2 + cos(theta)**2),
|
| 415 |
+
sqrt(r**2*sin(phi)**2*cos(theta)**2 + r**2*sin(theta)**2 + r**2*cos(phi)**2*cos(theta)**2),
|
| 416 |
+
sqrt(r**2*sin(phi)**2*sin(theta)**2 + r**2*sin(theta)**2*cos(phi)**2)
|
| 417 |
+
) # ==> this should simplify to (1, r, sin(theta)*r), `simplify` is too slow.
|
| 418 |
+
|
| 419 |
+
# Cylindrical with `lambda`
|
| 420 |
+
a = CoordSys3D('a', lambda r, theta, z:
|
| 421 |
+
(r*cos(theta), r*sin(theta), z),
|
| 422 |
+
variable_names=["r", "theta", "z"]
|
| 423 |
+
)
|
| 424 |
+
r, theta, z = a.base_scalars()
|
| 425 |
+
assert a.transformation_to_parent() == (r*cos(theta), r*sin(theta), z)
|
| 426 |
+
assert a.lame_coefficients() == (
|
| 427 |
+
sqrt(sin(theta)**2 + cos(theta)**2),
|
| 428 |
+
sqrt(r**2*sin(theta)**2 + r**2*cos(theta)**2),
|
| 429 |
+
1
|
| 430 |
+
) # ==> this should simplify to (1, a.x, 1)
|
| 431 |
+
|
| 432 |
+
raises(TypeError, lambda: CoordSys3D('a', transformation={
|
| 433 |
+
x: x*sin(y)*cos(z), y:x*sin(y)*sin(z), z: x*cos(y)}))
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
def test_check_orthogonality():
|
| 437 |
+
x, y, z = symbols('x y z')
|
| 438 |
+
u,v = symbols('u, v')
|
| 439 |
+
a = CoordSys3D('a', transformation=((x, y, z), (x*sin(y)*cos(z), x*sin(y)*sin(z), x*cos(y))))
|
| 440 |
+
assert a._check_orthogonality(a._transformation) is True
|
| 441 |
+
a = CoordSys3D('a', transformation=((x, y, z), (x * cos(y), x * sin(y), z)))
|
| 442 |
+
assert a._check_orthogonality(a._transformation) is True
|
| 443 |
+
a = CoordSys3D('a', transformation=((u, v, z), (cosh(u) * cos(v), sinh(u) * sin(v), z)))
|
| 444 |
+
assert a._check_orthogonality(a._transformation) is True
|
| 445 |
+
|
| 446 |
+
raises(ValueError, lambda: CoordSys3D('a', transformation=((x, y, z), (x, x, z))))
|
| 447 |
+
raises(ValueError, lambda: CoordSys3D('a', transformation=(
|
| 448 |
+
(x, y, z), (x*sin(y/2)*cos(z), x*sin(y)*sin(z), x*cos(y)))))
|
| 449 |
+
|
| 450 |
+
|
| 451 |
+
def test_rotation_trans_equations():
|
| 452 |
+
a = CoordSys3D('a')
|
| 453 |
+
from sympy.core.symbol import symbols
|
| 454 |
+
q0 = symbols('q0')
|
| 455 |
+
assert a._rotation_trans_equations(a._parent_rotation_matrix, a.base_scalars()) == (a.x, a.y, a.z)
|
| 456 |
+
assert a._rotation_trans_equations(a._inverse_rotation_matrix(), a.base_scalars()) == (a.x, a.y, a.z)
|
| 457 |
+
b = a.orient_new_axis('b', 0, -a.k)
|
| 458 |
+
assert b._rotation_trans_equations(b._parent_rotation_matrix, b.base_scalars()) == (b.x, b.y, b.z)
|
| 459 |
+
assert b._rotation_trans_equations(b._inverse_rotation_matrix(), b.base_scalars()) == (b.x, b.y, b.z)
|
| 460 |
+
c = a.orient_new_axis('c', q0, -a.k)
|
| 461 |
+
assert c._rotation_trans_equations(c._parent_rotation_matrix, c.base_scalars()) == \
|
| 462 |
+
(-sin(q0) * c.y + cos(q0) * c.x, sin(q0) * c.x + cos(q0) * c.y, c.z)
|
| 463 |
+
assert c._rotation_trans_equations(c._inverse_rotation_matrix(), c.base_scalars()) == \
|
| 464 |
+
(sin(q0) * c.y + cos(q0) * c.x, -sin(q0) * c.x + cos(q0) * c.y, c.z)
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/test_field_functions.py
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.function import Derivative
|
| 2 |
+
from sympy.vector.vector import Vector
|
| 3 |
+
from sympy.vector.coordsysrect import CoordSys3D
|
| 4 |
+
from sympy.simplify import simplify
|
| 5 |
+
from sympy.core.symbol import symbols
|
| 6 |
+
from sympy.core import S
|
| 7 |
+
from sympy.functions.elementary.trigonometric import (cos, sin)
|
| 8 |
+
from sympy.vector.vector import Dot
|
| 9 |
+
from sympy.vector.operators import curl, divergence, gradient, Gradient, Divergence, Cross
|
| 10 |
+
from sympy.vector.deloperator import Del
|
| 11 |
+
from sympy.vector.functions import (is_conservative, is_solenoidal,
|
| 12 |
+
scalar_potential, directional_derivative,
|
| 13 |
+
laplacian, scalar_potential_difference)
|
| 14 |
+
from sympy.testing.pytest import raises
|
| 15 |
+
|
| 16 |
+
C = CoordSys3D('C')
|
| 17 |
+
i, j, k = C.base_vectors()
|
| 18 |
+
x, y, z = C.base_scalars()
|
| 19 |
+
delop = Del()
|
| 20 |
+
a, b, c, q = symbols('a b c q')
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def test_del_operator():
|
| 24 |
+
# Tests for curl
|
| 25 |
+
|
| 26 |
+
assert delop ^ Vector.zero == Vector.zero
|
| 27 |
+
assert ((delop ^ Vector.zero).doit() == Vector.zero ==
|
| 28 |
+
curl(Vector.zero))
|
| 29 |
+
assert delop.cross(Vector.zero) == delop ^ Vector.zero
|
| 30 |
+
assert (delop ^ i).doit() == Vector.zero
|
| 31 |
+
assert delop.cross(2*y**2*j, doit=True) == Vector.zero
|
| 32 |
+
assert delop.cross(2*y**2*j) == delop ^ 2*y**2*j
|
| 33 |
+
v = x*y*z * (i + j + k)
|
| 34 |
+
assert ((delop ^ v).doit() ==
|
| 35 |
+
(-x*y + x*z)*i + (x*y - y*z)*j + (-x*z + y*z)*k ==
|
| 36 |
+
curl(v))
|
| 37 |
+
assert delop ^ v == delop.cross(v)
|
| 38 |
+
assert (delop.cross(2*x**2*j) ==
|
| 39 |
+
(Derivative(0, C.y) - Derivative(2*C.x**2, C.z))*C.i +
|
| 40 |
+
(-Derivative(0, C.x) + Derivative(0, C.z))*C.j +
|
| 41 |
+
(-Derivative(0, C.y) + Derivative(2*C.x**2, C.x))*C.k)
|
| 42 |
+
assert (delop.cross(2*x**2*j, doit=True) == 4*x*k ==
|
| 43 |
+
curl(2*x**2*j))
|
| 44 |
+
|
| 45 |
+
#Tests for divergence
|
| 46 |
+
assert delop & Vector.zero is S.Zero == divergence(Vector.zero)
|
| 47 |
+
assert (delop & Vector.zero).doit() is S.Zero
|
| 48 |
+
assert delop.dot(Vector.zero) == delop & Vector.zero
|
| 49 |
+
assert (delop & i).doit() is S.Zero
|
| 50 |
+
assert (delop & x**2*i).doit() == 2*x == divergence(x**2*i)
|
| 51 |
+
assert (delop.dot(v, doit=True) == x*y + y*z + z*x ==
|
| 52 |
+
divergence(v))
|
| 53 |
+
assert delop & v == delop.dot(v)
|
| 54 |
+
assert delop.dot(1/(x*y*z) * (i + j + k), doit=True) == \
|
| 55 |
+
- 1 / (x*y*z**2) - 1 / (x*y**2*z) - 1 / (x**2*y*z)
|
| 56 |
+
v = x*i + y*j + z*k
|
| 57 |
+
assert (delop & v == Derivative(C.x, C.x) +
|
| 58 |
+
Derivative(C.y, C.y) + Derivative(C.z, C.z))
|
| 59 |
+
assert delop.dot(v, doit=True) == 3 == divergence(v)
|
| 60 |
+
assert delop & v == delop.dot(v)
|
| 61 |
+
assert simplify((delop & v).doit()) == 3
|
| 62 |
+
|
| 63 |
+
#Tests for gradient
|
| 64 |
+
assert (delop.gradient(0, doit=True) == Vector.zero ==
|
| 65 |
+
gradient(0))
|
| 66 |
+
assert delop.gradient(0) == delop(0)
|
| 67 |
+
assert (delop(S.Zero)).doit() == Vector.zero
|
| 68 |
+
assert (delop(x) == (Derivative(C.x, C.x))*C.i +
|
| 69 |
+
(Derivative(C.x, C.y))*C.j + (Derivative(C.x, C.z))*C.k)
|
| 70 |
+
assert (delop(x)).doit() == i == gradient(x)
|
| 71 |
+
assert (delop(x*y*z) ==
|
| 72 |
+
(Derivative(C.x*C.y*C.z, C.x))*C.i +
|
| 73 |
+
(Derivative(C.x*C.y*C.z, C.y))*C.j +
|
| 74 |
+
(Derivative(C.x*C.y*C.z, C.z))*C.k)
|
| 75 |
+
assert (delop.gradient(x*y*z, doit=True) ==
|
| 76 |
+
y*z*i + z*x*j + x*y*k ==
|
| 77 |
+
gradient(x*y*z))
|
| 78 |
+
assert delop(x*y*z) == delop.gradient(x*y*z)
|
| 79 |
+
assert (delop(2*x**2)).doit() == 4*x*i
|
| 80 |
+
assert ((delop(a*sin(y) / x)).doit() ==
|
| 81 |
+
-a*sin(y)/x**2 * i + a*cos(y)/x * j)
|
| 82 |
+
|
| 83 |
+
#Tests for directional derivative
|
| 84 |
+
assert (Vector.zero & delop)(a) is S.Zero
|
| 85 |
+
assert ((Vector.zero & delop)(a)).doit() is S.Zero
|
| 86 |
+
assert ((v & delop)(Vector.zero)).doit() == Vector.zero
|
| 87 |
+
assert ((v & delop)(S.Zero)).doit() is S.Zero
|
| 88 |
+
assert ((i & delop)(x)).doit() == 1
|
| 89 |
+
assert ((j & delop)(y)).doit() == 1
|
| 90 |
+
assert ((k & delop)(z)).doit() == 1
|
| 91 |
+
assert ((i & delop)(x*y*z)).doit() == y*z
|
| 92 |
+
assert ((v & delop)(x)).doit() == x
|
| 93 |
+
assert ((v & delop)(x*y*z)).doit() == 3*x*y*z
|
| 94 |
+
assert (v & delop)(x + y + z) == C.x + C.y + C.z
|
| 95 |
+
assert ((v & delop)(x + y + z)).doit() == x + y + z
|
| 96 |
+
assert ((v & delop)(v)).doit() == v
|
| 97 |
+
assert ((i & delop)(v)).doit() == i
|
| 98 |
+
assert ((j & delop)(v)).doit() == j
|
| 99 |
+
assert ((k & delop)(v)).doit() == k
|
| 100 |
+
assert ((v & delop)(Vector.zero)).doit() == Vector.zero
|
| 101 |
+
|
| 102 |
+
# Tests for laplacian on scalar fields
|
| 103 |
+
assert laplacian(x*y*z) is S.Zero
|
| 104 |
+
assert laplacian(x**2) == S(2)
|
| 105 |
+
assert laplacian(x**2*y**2*z**2) == \
|
| 106 |
+
2*y**2*z**2 + 2*x**2*z**2 + 2*x**2*y**2
|
| 107 |
+
A = CoordSys3D('A', transformation="spherical", variable_names=["r", "theta", "phi"])
|
| 108 |
+
B = CoordSys3D('B', transformation='cylindrical', variable_names=["r", "theta", "z"])
|
| 109 |
+
assert laplacian(A.r + A.theta + A.phi) == 2/A.r + cos(A.theta)/(A.r**2*sin(A.theta))
|
| 110 |
+
assert laplacian(B.r + B.theta + B.z) == 1/B.r
|
| 111 |
+
|
| 112 |
+
# Tests for laplacian on vector fields
|
| 113 |
+
assert laplacian(x*y*z*(i + j + k)) == Vector.zero
|
| 114 |
+
assert laplacian(x*y**2*z*(i + j + k)) == \
|
| 115 |
+
2*x*z*i + 2*x*z*j + 2*x*z*k
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def test_product_rules():
|
| 119 |
+
"""
|
| 120 |
+
Tests the six product rules defined with respect to the Del
|
| 121 |
+
operator
|
| 122 |
+
|
| 123 |
+
References
|
| 124 |
+
==========
|
| 125 |
+
|
| 126 |
+
.. [1] https://en.wikipedia.org/wiki/Del
|
| 127 |
+
|
| 128 |
+
"""
|
| 129 |
+
|
| 130 |
+
#Define the scalar and vector functions
|
| 131 |
+
f = 2*x*y*z
|
| 132 |
+
g = x*y + y*z + z*x
|
| 133 |
+
u = x**2*i + 4*j - y**2*z*k
|
| 134 |
+
v = 4*i + x*y*z*k
|
| 135 |
+
|
| 136 |
+
# First product rule
|
| 137 |
+
lhs = delop(f * g, doit=True)
|
| 138 |
+
rhs = (f * delop(g) + g * delop(f)).doit()
|
| 139 |
+
assert simplify(lhs) == simplify(rhs)
|
| 140 |
+
|
| 141 |
+
# Second product rule
|
| 142 |
+
lhs = delop(u & v).doit()
|
| 143 |
+
rhs = ((u ^ (delop ^ v)) + (v ^ (delop ^ u)) + \
|
| 144 |
+
((u & delop)(v)) + ((v & delop)(u))).doit()
|
| 145 |
+
assert simplify(lhs) == simplify(rhs)
|
| 146 |
+
|
| 147 |
+
# Third product rule
|
| 148 |
+
lhs = (delop & (f*v)).doit()
|
| 149 |
+
rhs = ((f * (delop & v)) + (v & (delop(f)))).doit()
|
| 150 |
+
assert simplify(lhs) == simplify(rhs)
|
| 151 |
+
|
| 152 |
+
# Fourth product rule
|
| 153 |
+
lhs = (delop & (u ^ v)).doit()
|
| 154 |
+
rhs = ((v & (delop ^ u)) - (u & (delop ^ v))).doit()
|
| 155 |
+
assert simplify(lhs) == simplify(rhs)
|
| 156 |
+
|
| 157 |
+
# Fifth product rule
|
| 158 |
+
lhs = (delop ^ (f * v)).doit()
|
| 159 |
+
rhs = (((delop(f)) ^ v) + (f * (delop ^ v))).doit()
|
| 160 |
+
assert simplify(lhs) == simplify(rhs)
|
| 161 |
+
|
| 162 |
+
# Sixth product rule
|
| 163 |
+
lhs = (delop ^ (u ^ v)).doit()
|
| 164 |
+
rhs = (u * (delop & v) - v * (delop & u) +
|
| 165 |
+
(v & delop)(u) - (u & delop)(v)).doit()
|
| 166 |
+
assert simplify(lhs) == simplify(rhs)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
P = C.orient_new_axis('P', q, C.k) # type: ignore
|
| 170 |
+
scalar_field = 2*x**2*y*z
|
| 171 |
+
grad_field = gradient(scalar_field)
|
| 172 |
+
vector_field = y**2*i + 3*x*j + 5*y*z*k
|
| 173 |
+
curl_field = curl(vector_field)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def test_conservative():
|
| 177 |
+
assert is_conservative(Vector.zero) is True
|
| 178 |
+
assert is_conservative(i) is True
|
| 179 |
+
assert is_conservative(2 * i + 3 * j + 4 * k) is True
|
| 180 |
+
assert (is_conservative(y*z*i + x*z*j + x*y*k) is
|
| 181 |
+
True)
|
| 182 |
+
assert is_conservative(x * j) is False
|
| 183 |
+
assert is_conservative(grad_field) is True
|
| 184 |
+
assert is_conservative(curl_field) is False
|
| 185 |
+
assert (is_conservative(4*x*y*z*i + 2*x**2*z*j) is
|
| 186 |
+
False)
|
| 187 |
+
assert is_conservative(z*P.i + P.x*k) is True
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def test_solenoidal():
|
| 191 |
+
assert is_solenoidal(Vector.zero) is True
|
| 192 |
+
assert is_solenoidal(i) is True
|
| 193 |
+
assert is_solenoidal(2 * i + 3 * j + 4 * k) is True
|
| 194 |
+
assert (is_solenoidal(y*z*i + x*z*j + x*y*k) is
|
| 195 |
+
True)
|
| 196 |
+
assert is_solenoidal(y * j) is False
|
| 197 |
+
assert is_solenoidal(grad_field) is False
|
| 198 |
+
assert is_solenoidal(curl_field) is True
|
| 199 |
+
assert is_solenoidal((-2*y + 3)*k) is True
|
| 200 |
+
assert is_solenoidal(cos(q)*i + sin(q)*j + cos(q)*P.k) is True
|
| 201 |
+
assert is_solenoidal(z*P.i + P.x*k) is True
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def test_directional_derivative():
|
| 205 |
+
assert directional_derivative(C.x*C.y*C.z, 3*C.i + 4*C.j + C.k) == C.x*C.y + 4*C.x*C.z + 3*C.y*C.z
|
| 206 |
+
assert directional_derivative(5*C.x**2*C.z, 3*C.i + 4*C.j + C.k) == 5*C.x**2 + 30*C.x*C.z
|
| 207 |
+
assert directional_derivative(5*C.x**2*C.z, 4*C.j) is S.Zero
|
| 208 |
+
|
| 209 |
+
D = CoordSys3D("D", "spherical", variable_names=["r", "theta", "phi"],
|
| 210 |
+
vector_names=["e_r", "e_theta", "e_phi"])
|
| 211 |
+
r, theta, phi = D.base_scalars()
|
| 212 |
+
e_r, e_theta, e_phi = D.base_vectors()
|
| 213 |
+
assert directional_derivative(r**2*e_r, e_r) == 2*r*e_r
|
| 214 |
+
assert directional_derivative(5*r**2*phi, 3*e_r + 4*e_theta + e_phi) == 5*r**2 + 30*r*phi
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
def test_scalar_potential():
|
| 218 |
+
assert scalar_potential(Vector.zero, C) == 0
|
| 219 |
+
assert scalar_potential(i, C) == x
|
| 220 |
+
assert scalar_potential(j, C) == y
|
| 221 |
+
assert scalar_potential(k, C) == z
|
| 222 |
+
assert scalar_potential(y*z*i + x*z*j + x*y*k, C) == x*y*z
|
| 223 |
+
assert scalar_potential(grad_field, C) == scalar_field
|
| 224 |
+
assert scalar_potential(z*P.i + P.x*k, C) == x*z*cos(q) + y*z*sin(q)
|
| 225 |
+
assert scalar_potential(z*P.i + P.x*k, P) == P.x*P.z
|
| 226 |
+
raises(ValueError, lambda: scalar_potential(x*j, C))
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def test_scalar_potential_difference():
|
| 230 |
+
point1 = C.origin.locate_new('P1', 1*i + 2*j + 3*k)
|
| 231 |
+
point2 = C.origin.locate_new('P2', 4*i + 5*j + 6*k)
|
| 232 |
+
genericpointC = C.origin.locate_new('RP', x*i + y*j + z*k)
|
| 233 |
+
genericpointP = P.origin.locate_new('PP', P.x*P.i + P.y*P.j + P.z*P.k)
|
| 234 |
+
assert scalar_potential_difference(S.Zero, C, point1, point2) == 0
|
| 235 |
+
assert (scalar_potential_difference(scalar_field, C, C.origin,
|
| 236 |
+
genericpointC) ==
|
| 237 |
+
scalar_field)
|
| 238 |
+
assert (scalar_potential_difference(grad_field, C, C.origin,
|
| 239 |
+
genericpointC) ==
|
| 240 |
+
scalar_field)
|
| 241 |
+
assert scalar_potential_difference(grad_field, C, point1, point2) == 948
|
| 242 |
+
assert (scalar_potential_difference(y*z*i + x*z*j +
|
| 243 |
+
x*y*k, C, point1,
|
| 244 |
+
genericpointC) ==
|
| 245 |
+
x*y*z - 6)
|
| 246 |
+
potential_diff_P = (2*P.z*(P.x*sin(q) + P.y*cos(q))*
|
| 247 |
+
(P.x*cos(q) - P.y*sin(q))**2)
|
| 248 |
+
assert (scalar_potential_difference(grad_field, P, P.origin,
|
| 249 |
+
genericpointP).simplify() ==
|
| 250 |
+
potential_diff_P.simplify())
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def test_differential_operators_curvilinear_system():
|
| 254 |
+
A = CoordSys3D('A', transformation="spherical", variable_names=["r", "theta", "phi"])
|
| 255 |
+
B = CoordSys3D('B', transformation='cylindrical', variable_names=["r", "theta", "z"])
|
| 256 |
+
# Test for spherical coordinate system and gradient
|
| 257 |
+
assert gradient(3*A.r + 4*A.theta) == 3*A.i + 4/A.r*A.j
|
| 258 |
+
assert gradient(3*A.r*A.phi + 4*A.theta) == 3*A.phi*A.i + 4/A.r*A.j + (3/sin(A.theta))*A.k
|
| 259 |
+
assert gradient(0*A.r + 0*A.theta+0*A.phi) == Vector.zero
|
| 260 |
+
assert gradient(A.r*A.theta*A.phi) == A.theta*A.phi*A.i + A.phi*A.j + (A.theta/sin(A.theta))*A.k
|
| 261 |
+
# Test for spherical coordinate system and divergence
|
| 262 |
+
assert divergence(A.r * A.i + A.theta * A.j + A.phi * A.k) == \
|
| 263 |
+
(sin(A.theta)*A.r + cos(A.theta)*A.r*A.theta)/(sin(A.theta)*A.r**2) + 3 + 1/(sin(A.theta)*A.r)
|
| 264 |
+
assert divergence(3*A.r*A.phi*A.i + A.theta*A.j + A.r*A.theta*A.phi*A.k) == \
|
| 265 |
+
(sin(A.theta)*A.r + cos(A.theta)*A.r*A.theta)/(sin(A.theta)*A.r**2) + 9*A.phi + A.theta/sin(A.theta)
|
| 266 |
+
assert divergence(Vector.zero) == 0
|
| 267 |
+
assert divergence(0*A.i + 0*A.j + 0*A.k) == 0
|
| 268 |
+
# Test for spherical coordinate system and curl
|
| 269 |
+
assert curl(A.r*A.i + A.theta*A.j + A.phi*A.k) == \
|
| 270 |
+
(cos(A.theta)*A.phi/(sin(A.theta)*A.r))*A.i + (-A.phi/A.r)*A.j + A.theta/A.r*A.k
|
| 271 |
+
assert curl(A.r*A.j + A.phi*A.k) == (cos(A.theta)*A.phi/(sin(A.theta)*A.r))*A.i + (-A.phi/A.r)*A.j + 2*A.k
|
| 272 |
+
|
| 273 |
+
# Test for cylindrical coordinate system and gradient
|
| 274 |
+
assert gradient(0*B.r + 0*B.theta+0*B.z) == Vector.zero
|
| 275 |
+
assert gradient(B.r*B.theta*B.z) == B.theta*B.z*B.i + B.z*B.j + B.r*B.theta*B.k
|
| 276 |
+
assert gradient(3*B.r) == 3*B.i
|
| 277 |
+
assert gradient(2*B.theta) == 2/B.r * B.j
|
| 278 |
+
assert gradient(4*B.z) == 4*B.k
|
| 279 |
+
# Test for cylindrical coordinate system and divergence
|
| 280 |
+
assert divergence(B.r*B.i + B.theta*B.j + B.z*B.k) == 3 + 1/B.r
|
| 281 |
+
assert divergence(B.r*B.j + B.z*B.k) == 1
|
| 282 |
+
# Test for cylindrical coordinate system and curl
|
| 283 |
+
assert curl(B.r*B.j + B.z*B.k) == 2*B.k
|
| 284 |
+
assert curl(3*B.i + 2/B.r*B.j + 4*B.k) == Vector.zero
|
| 285 |
+
|
| 286 |
+
def test_mixed_coordinates():
|
| 287 |
+
# gradient
|
| 288 |
+
a = CoordSys3D('a')
|
| 289 |
+
b = CoordSys3D('b')
|
| 290 |
+
c = CoordSys3D('c')
|
| 291 |
+
assert gradient(a.x*b.y) == b.y*a.i + a.x*b.j
|
| 292 |
+
assert gradient(3*cos(q)*a.x*b.x+a.y*(a.x+(cos(q)+b.x))) ==\
|
| 293 |
+
(a.y + 3*b.x*cos(q))*a.i + (a.x + b.x + cos(q))*a.j + (3*a.x*cos(q) + a.y)*b.i
|
| 294 |
+
# Some tests need further work:
|
| 295 |
+
# assert gradient(a.x*(cos(a.x+b.x))) == (cos(a.x + b.x))*a.i + a.x*Gradient(cos(a.x + b.x))
|
| 296 |
+
# assert gradient(cos(a.x + b.x)*cos(a.x + b.z)) == Gradient(cos(a.x + b.x)*cos(a.x + b.z))
|
| 297 |
+
assert gradient(a.x**b.y) == Gradient(a.x**b.y)
|
| 298 |
+
# assert gradient(cos(a.x+b.y)*a.z) == None
|
| 299 |
+
assert gradient(cos(a.x*b.y)) == Gradient(cos(a.x*b.y))
|
| 300 |
+
assert gradient(3*cos(q)*a.x*b.x*a.z*a.y+ b.y*b.z + cos(a.x+a.y)*b.z) == \
|
| 301 |
+
(3*a.y*a.z*b.x*cos(q) - b.z*sin(a.x + a.y))*a.i + \
|
| 302 |
+
(3*a.x*a.z*b.x*cos(q) - b.z*sin(a.x + a.y))*a.j + (3*a.x*a.y*b.x*cos(q))*a.k + \
|
| 303 |
+
(3*a.x*a.y*a.z*cos(q))*b.i + b.z*b.j + (b.y + cos(a.x + a.y))*b.k
|
| 304 |
+
# divergence
|
| 305 |
+
assert divergence(a.i*a.x+a.j*a.y+a.z*a.k + b.i*b.x+b.j*b.y+b.z*b.k + c.i*c.x+c.j*c.y+c.z*c.k) == S(9)
|
| 306 |
+
# assert divergence(3*a.i*a.x*cos(a.x+b.z) + a.j*b.x*c.z) == None
|
| 307 |
+
assert divergence(3*a.i*a.x*a.z + b.j*b.x*c.z + 3*a.j*a.z*a.y) == \
|
| 308 |
+
6*a.z + b.x*Dot(b.j, c.k)
|
| 309 |
+
assert divergence(3*cos(q)*a.x*b.x*b.i*c.x) == \
|
| 310 |
+
3*a.x*b.x*cos(q)*Dot(b.i, c.i) + 3*a.x*c.x*cos(q) + 3*b.x*c.x*cos(q)*Dot(b.i, a.i)
|
| 311 |
+
assert divergence(a.x*b.x*c.x*Cross(a.x*a.i, a.y*b.j)) ==\
|
| 312 |
+
a.x*b.x*c.x*Divergence(Cross(a.x*a.i, a.y*b.j)) + \
|
| 313 |
+
b.x*c.x*Dot(Cross(a.x*a.i, a.y*b.j), a.i) + \
|
| 314 |
+
a.x*c.x*Dot(Cross(a.x*a.i, a.y*b.j), b.i) + \
|
| 315 |
+
a.x*b.x*Dot(Cross(a.x*a.i, a.y*b.j), c.i)
|
| 316 |
+
assert divergence(a.x*b.x*c.x*(a.x*a.i + b.x*b.i)) == \
|
| 317 |
+
4*a.x*b.x*c.x +\
|
| 318 |
+
a.x**2*c.x*Dot(a.i, b.i) +\
|
| 319 |
+
a.x**2*b.x*Dot(a.i, c.i) +\
|
| 320 |
+
b.x**2*c.x*Dot(b.i, a.i) +\
|
| 321 |
+
a.x*b.x**2*Dot(b.i, c.i)
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/test_implicitregion.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.relational import Eq
|
| 2 |
+
from sympy.core.singleton import S
|
| 3 |
+
from sympy.abc import x, y, z, s, t
|
| 4 |
+
from sympy.sets import FiniteSet, EmptySet
|
| 5 |
+
from sympy.geometry import Point
|
| 6 |
+
from sympy.vector import ImplicitRegion
|
| 7 |
+
from sympy.testing.pytest import raises
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def test_ImplicitRegion():
|
| 11 |
+
ellipse = ImplicitRegion((x, y), (x**2/4 + y**2/16 - 1))
|
| 12 |
+
assert ellipse.equation == x**2/4 + y**2/16 - 1
|
| 13 |
+
assert ellipse.variables == (x, y)
|
| 14 |
+
assert ellipse.degree == 2
|
| 15 |
+
r = ImplicitRegion((x, y, z), Eq(x**4 + y**2 - x*y, 6))
|
| 16 |
+
assert r.equation == x**4 + y**2 - x*y - 6
|
| 17 |
+
assert r.variables == (x, y, z)
|
| 18 |
+
assert r.degree == 4
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_regular_point():
|
| 22 |
+
r1 = ImplicitRegion((x,), x**2 - 16)
|
| 23 |
+
assert r1.regular_point() == (-4,)
|
| 24 |
+
c1 = ImplicitRegion((x, y), x**2 + y**2 - 4)
|
| 25 |
+
assert c1.regular_point() == (0, -2)
|
| 26 |
+
c2 = ImplicitRegion((x, y), (x - S(5)/2)**2 + y**2 - (S(1)/4)**2)
|
| 27 |
+
assert c2.regular_point() == (S(5)/2, -S(1)/4)
|
| 28 |
+
c3 = ImplicitRegion((x, y), (y - 5)**2 - 16*(x - 5))
|
| 29 |
+
assert c3.regular_point() == (5, 5)
|
| 30 |
+
r2 = ImplicitRegion((x, y), x**2 - 4*x*y - 3*y**2 + 4*x + 8*y - 5)
|
| 31 |
+
assert r2.regular_point() == (S(4)/7, S(9)/7)
|
| 32 |
+
r3 = ImplicitRegion((x, y), x**2 - 2*x*y + 3*y**2 - 2*x - 5*y + 3/2)
|
| 33 |
+
raises(ValueError, lambda: r3.regular_point())
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def test_singular_points_and_multiplicty():
|
| 37 |
+
r1 = ImplicitRegion((x, y, z), Eq(x + y + z, 0))
|
| 38 |
+
assert r1.singular_points() == EmptySet
|
| 39 |
+
r2 = ImplicitRegion((x, y, z), x*y*z + y**4 -x**2*z**2)
|
| 40 |
+
assert r2.singular_points() == FiniteSet((0, 0, z), (x, 0, 0))
|
| 41 |
+
assert r2.multiplicity((0, 0, 0)) == 3
|
| 42 |
+
assert r2.multiplicity((0, 0, 6)) == 2
|
| 43 |
+
r3 = ImplicitRegion((x, y, z), z**2 - x**2 - y**2)
|
| 44 |
+
assert r3.singular_points() == FiniteSet((0, 0, 0))
|
| 45 |
+
assert r3.multiplicity((0, 0, 0)) == 2
|
| 46 |
+
r4 = ImplicitRegion((x, y), x**2 + y**2 - 2*x)
|
| 47 |
+
assert r4.singular_points() == EmptySet
|
| 48 |
+
assert r4.multiplicity(Point(1, 3)) == 0
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def test_rational_parametrization():
|
| 52 |
+
p = ImplicitRegion((x,), x - 2)
|
| 53 |
+
assert p.rational_parametrization() == (x - 2,)
|
| 54 |
+
|
| 55 |
+
line = ImplicitRegion((x, y), Eq(y, 3*x + 2))
|
| 56 |
+
assert line.rational_parametrization() == (x, 3*x + 2)
|
| 57 |
+
|
| 58 |
+
circle1 = ImplicitRegion((x, y), (x-2)**2 + (y+3)**2 - 4)
|
| 59 |
+
assert circle1.rational_parametrization(parameters=t) == (4*t/(t**2 + 1) + 2, 4*t**2/(t**2 + 1) - 5)
|
| 60 |
+
circle2 = ImplicitRegion((x, y), (x - S.Half)**2 + y**2 - (S(1)/2)**2)
|
| 61 |
+
|
| 62 |
+
assert circle2.rational_parametrization(parameters=t) == (t/(t**2 + 1) + S(1)/2, t**2/(t**2 + 1) - S(1)/2)
|
| 63 |
+
circle3 = ImplicitRegion((x, y), Eq(x**2 + y**2, 2*x))
|
| 64 |
+
assert circle3.rational_parametrization(parameters=(t,)) == (2*t/(t**2 + 1) + 1, 2*t**2/(t**2 + 1) - 1)
|
| 65 |
+
|
| 66 |
+
parabola = ImplicitRegion((x, y), (y - 3)**2 - 4*(x + 6))
|
| 67 |
+
assert parabola.rational_parametrization(t) == (-6 + 4/t**2, 3 + 4/t)
|
| 68 |
+
|
| 69 |
+
rect_hyperbola = ImplicitRegion((x, y), x*y - 1)
|
| 70 |
+
assert rect_hyperbola.rational_parametrization(t) == (-1 + (t + 1)/t, t)
|
| 71 |
+
|
| 72 |
+
cubic_curve = ImplicitRegion((x, y), x**3 + x**2 - y**2)
|
| 73 |
+
assert cubic_curve.rational_parametrization(parameters=(t)) == (t**2 - 1, t*(t**2 - 1))
|
| 74 |
+
cuspidal = ImplicitRegion((x, y), (x**3 - y**2))
|
| 75 |
+
assert cuspidal.rational_parametrization(t) == (t**2, t**3)
|
| 76 |
+
|
| 77 |
+
I = ImplicitRegion((x, y), x**3 + x**2 - y**2)
|
| 78 |
+
assert I.rational_parametrization(t) == (t**2 - 1, t*(t**2 - 1))
|
| 79 |
+
|
| 80 |
+
sphere = ImplicitRegion((x, y, z), Eq(x**2 + y**2 + z**2, 2*x))
|
| 81 |
+
assert sphere.rational_parametrization(parameters=(s, t)) == (2/(s**2 + t**2 + 1), 2*t/(s**2 + t**2 + 1), 2*s/(s**2 + t**2 + 1))
|
| 82 |
+
|
| 83 |
+
conic = ImplicitRegion((x, y), Eq(x**2 + 4*x*y + 3*y**2 + x - y + 10, 0))
|
| 84 |
+
assert conic.rational_parametrization(t) == (
|
| 85 |
+
S(17)/2 + 4/(3*t**2 + 4*t + 1), 4*t/(3*t**2 + 4*t + 1) - S(11)/2)
|
| 86 |
+
|
| 87 |
+
r1 = ImplicitRegion((x, y), y**2 - x**3 + x)
|
| 88 |
+
raises(NotImplementedError, lambda: r1.rational_parametrization())
|
| 89 |
+
r2 = ImplicitRegion((x, y), y**2 - x**3 - x**2 + 1)
|
| 90 |
+
raises(NotImplementedError, lambda: r2.rational_parametrization())
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/test_integrals.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.numbers import pi
|
| 2 |
+
from sympy.core.singleton import S
|
| 3 |
+
from sympy.functions.elementary.miscellaneous import sqrt
|
| 4 |
+
from sympy.functions.elementary.trigonometric import (cos, sin)
|
| 5 |
+
from sympy.testing.pytest import raises
|
| 6 |
+
from sympy.vector.coordsysrect import CoordSys3D
|
| 7 |
+
from sympy.vector.integrals import ParametricIntegral, vector_integrate
|
| 8 |
+
from sympy.vector.parametricregion import ParametricRegion
|
| 9 |
+
from sympy.vector.implicitregion import ImplicitRegion
|
| 10 |
+
from sympy.abc import x, y, z, u, v, r, t, theta, phi
|
| 11 |
+
from sympy.geometry import Point, Segment, Curve, Circle, Polygon, Plane
|
| 12 |
+
|
| 13 |
+
C = CoordSys3D('C')
|
| 14 |
+
|
| 15 |
+
def test_parametric_lineintegrals():
|
| 16 |
+
halfcircle = ParametricRegion((4*cos(theta), 4*sin(theta)), (theta, -pi/2, pi/2))
|
| 17 |
+
assert ParametricIntegral(C.x*C.y**4, halfcircle) == S(8192)/5
|
| 18 |
+
|
| 19 |
+
curve = ParametricRegion((t, t**2, t**3), (t, 0, 1))
|
| 20 |
+
field1 = 8*C.x**2*C.y*C.z*C.i + 5*C.z*C.j - 4*C.x*C.y*C.k
|
| 21 |
+
assert ParametricIntegral(field1, curve) == 1
|
| 22 |
+
line = ParametricRegion((4*t - 1, 2 - 2*t, t), (t, 0, 1))
|
| 23 |
+
assert ParametricIntegral(C.x*C.z*C.i - C.y*C.z*C.k, line) == 3
|
| 24 |
+
|
| 25 |
+
assert ParametricIntegral(4*C.x**3, ParametricRegion((1, t), (t, 0, 2))) == 8
|
| 26 |
+
|
| 27 |
+
helix = ParametricRegion((cos(t), sin(t), 3*t), (t, 0, 4*pi))
|
| 28 |
+
assert ParametricIntegral(C.x*C.y*C.z, helix) == -3*sqrt(10)*pi
|
| 29 |
+
|
| 30 |
+
field2 = C.y*C.i + C.z*C.j + C.z*C.k
|
| 31 |
+
assert ParametricIntegral(field2, ParametricRegion((cos(t), sin(t), t**2), (t, 0, pi))) == -5*pi/2 + pi**4/2
|
| 32 |
+
|
| 33 |
+
def test_parametric_surfaceintegrals():
|
| 34 |
+
|
| 35 |
+
semisphere = ParametricRegion((2*sin(phi)*cos(theta), 2*sin(phi)*sin(theta), 2*cos(phi)),\
|
| 36 |
+
(theta, 0, 2*pi), (phi, 0, pi/2))
|
| 37 |
+
assert ParametricIntegral(C.z, semisphere) == 8*pi
|
| 38 |
+
|
| 39 |
+
cylinder = ParametricRegion((sqrt(3)*cos(theta), sqrt(3)*sin(theta), z), (z, 0, 6), (theta, 0, 2*pi))
|
| 40 |
+
assert ParametricIntegral(C.y, cylinder) == 0
|
| 41 |
+
|
| 42 |
+
cone = ParametricRegion((v*cos(u), v*sin(u), v), (u, 0, 2*pi), (v, 0, 1))
|
| 43 |
+
assert ParametricIntegral(C.x*C.i + C.y*C.j + C.z**4*C.k, cone) == pi/3
|
| 44 |
+
|
| 45 |
+
triangle1 = ParametricRegion((x, y), (x, 0, 2), (y, 0, 10 - 5*x))
|
| 46 |
+
triangle2 = ParametricRegion((x, y), (y, 0, 10 - 5*x), (x, 0, 2))
|
| 47 |
+
assert ParametricIntegral(-15.6*C.y*C.k, triangle1) == ParametricIntegral(-15.6*C.y*C.k, triangle2)
|
| 48 |
+
assert ParametricIntegral(C.z, triangle1) == 10*C.z
|
| 49 |
+
|
| 50 |
+
def test_parametric_volumeintegrals():
|
| 51 |
+
|
| 52 |
+
cube = ParametricRegion((x, y, z), (x, 0, 1), (y, 0, 1), (z, 0, 1))
|
| 53 |
+
assert ParametricIntegral(1, cube) == 1
|
| 54 |
+
|
| 55 |
+
solidsphere1 = ParametricRegion((r*sin(phi)*cos(theta), r*sin(phi)*sin(theta), r*cos(phi)),\
|
| 56 |
+
(r, 0, 2), (theta, 0, 2*pi), (phi, 0, pi))
|
| 57 |
+
solidsphere2 = ParametricRegion((r*sin(phi)*cos(theta), r*sin(phi)*sin(theta), r*cos(phi)),\
|
| 58 |
+
(r, 0, 2), (phi, 0, pi), (theta, 0, 2*pi))
|
| 59 |
+
assert ParametricIntegral(C.x**2 + C.y**2, solidsphere1) == -256*pi/15
|
| 60 |
+
assert ParametricIntegral(C.x**2 + C.y**2, solidsphere2) == 256*pi/15
|
| 61 |
+
|
| 62 |
+
region_under_plane1 = ParametricRegion((x, y, z), (x, 0, 3), (y, 0, -2*x/3 + 2),\
|
| 63 |
+
(z, 0, 6 - 2*x - 3*y))
|
| 64 |
+
region_under_plane2 = ParametricRegion((x, y, z), (x, 0, 3), (z, 0, 6 - 2*x - 3*y),\
|
| 65 |
+
(y, 0, -2*x/3 + 2))
|
| 66 |
+
|
| 67 |
+
assert ParametricIntegral(C.x*C.i + C.j - 100*C.k, region_under_plane1) == \
|
| 68 |
+
ParametricIntegral(C.x*C.i + C.j - 100*C.k, region_under_plane2)
|
| 69 |
+
assert ParametricIntegral(2*C.x, region_under_plane2) == -9
|
| 70 |
+
|
| 71 |
+
def test_vector_integrate():
|
| 72 |
+
halfdisc = ParametricRegion((r*cos(theta), r* sin(theta)), (r, -2, 2), (theta, 0, pi))
|
| 73 |
+
assert vector_integrate(C.x**2, halfdisc) == 4*pi
|
| 74 |
+
assert vector_integrate(C.x, ParametricRegion((t, t**2), (t, 2, 3))) == -17*sqrt(17)/12 + 37*sqrt(37)/12
|
| 75 |
+
|
| 76 |
+
assert vector_integrate(C.y**3*C.z, (C.x, 0, 3), (C.y, -1, 4)) == 765*C.z/4
|
| 77 |
+
|
| 78 |
+
s1 = Segment(Point(0, 0), Point(0, 1))
|
| 79 |
+
assert vector_integrate(-15*C.y, s1) == S(-15)/2
|
| 80 |
+
s2 = Segment(Point(4, 3, 9), Point(1, 1, 7))
|
| 81 |
+
assert vector_integrate(C.y*C.i, s2) == -6
|
| 82 |
+
|
| 83 |
+
curve = Curve((sin(t), cos(t)), (t, 0, 2))
|
| 84 |
+
assert vector_integrate(5*C.z, curve) == 10*C.z
|
| 85 |
+
|
| 86 |
+
c1 = Circle(Point(2, 3), 6)
|
| 87 |
+
assert vector_integrate(C.x*C.y, c1) == 72*pi
|
| 88 |
+
c2 = Circle(Point(0, 0), Point(1, 1), Point(1, 0))
|
| 89 |
+
assert vector_integrate(1, c2) == c2.circumference
|
| 90 |
+
|
| 91 |
+
triangle = Polygon((0, 0), (1, 0), (1, 1))
|
| 92 |
+
assert vector_integrate(C.x*C.i - 14*C.y*C.j, triangle) == 0
|
| 93 |
+
p1, p2, p3, p4 = [(0, 0), (1, 0), (5, 1), (0, 1)]
|
| 94 |
+
poly = Polygon(p1, p2, p3, p4)
|
| 95 |
+
assert vector_integrate(-23*C.z, poly) == -161*C.z - 23*sqrt(17)*C.z
|
| 96 |
+
|
| 97 |
+
point = Point(2, 3)
|
| 98 |
+
assert vector_integrate(C.i*C.y - C.z, point) == ParametricIntegral(C.y*C.i, ParametricRegion((2, 3)))
|
| 99 |
+
|
| 100 |
+
c3 = ImplicitRegion((x, y), x**2 + y**2 - 4)
|
| 101 |
+
assert vector_integrate(45, c3) == 180*pi
|
| 102 |
+
c4 = ImplicitRegion((x, y), (x - 3)**2 + (y - 4)**2 - 9)
|
| 103 |
+
assert vector_integrate(1, c4) == 6*pi
|
| 104 |
+
|
| 105 |
+
pl = Plane(Point(1, 1, 1), Point(2, 3, 4), Point(2, 2, 2))
|
| 106 |
+
raises(ValueError, lambda: vector_integrate(C.x*C.z*C.i + C.k, pl))
|
mplug_owl2/lib/python3.10/site-packages/sympy/vector/tests/test_parametricregion.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.numbers import pi
|
| 2 |
+
from sympy.functions.elementary.trigonometric import (cos, sin)
|
| 3 |
+
from sympy.vector.coordsysrect import CoordSys3D
|
| 4 |
+
from sympy.vector.parametricregion import ParametricRegion, parametric_region_list
|
| 5 |
+
from sympy.geometry import Point, Segment, Curve, Ellipse, Line, Parabola, Polygon
|
| 6 |
+
from sympy.testing.pytest import raises
|
| 7 |
+
from sympy.abc import a, b, r, t, x, y, z, theta, phi
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
C = CoordSys3D('C')
|
| 11 |
+
|
| 12 |
+
def test_ParametricRegion():
|
| 13 |
+
|
| 14 |
+
point = ParametricRegion((3, 4))
|
| 15 |
+
assert point.definition == (3, 4)
|
| 16 |
+
assert point.parameters == ()
|
| 17 |
+
assert point.limits == {}
|
| 18 |
+
assert point.dimensions == 0
|
| 19 |
+
|
| 20 |
+
# line x = y
|
| 21 |
+
line_xy = ParametricRegion((y, y), (y, 1, 5))
|
| 22 |
+
assert line_xy .definition == (y, y)
|
| 23 |
+
assert line_xy.parameters == (y,)
|
| 24 |
+
assert line_xy.dimensions == 1
|
| 25 |
+
|
| 26 |
+
# line y = z
|
| 27 |
+
line_yz = ParametricRegion((x,t,t), x, (t, 1, 2))
|
| 28 |
+
assert line_yz.definition == (x,t,t)
|
| 29 |
+
assert line_yz.parameters == (x, t)
|
| 30 |
+
assert line_yz.limits == {t: (1, 2)}
|
| 31 |
+
assert line_yz.dimensions == 1
|
| 32 |
+
|
| 33 |
+
p1 = ParametricRegion((9*a, -16*b), (a, 0, 2), (b, -1, 5))
|
| 34 |
+
assert p1.definition == (9*a, -16*b)
|
| 35 |
+
assert p1.parameters == (a, b)
|
| 36 |
+
assert p1.limits == {a: (0, 2), b: (-1, 5)}
|
| 37 |
+
assert p1.dimensions == 2
|
| 38 |
+
|
| 39 |
+
p2 = ParametricRegion((t, t**3), t)
|
| 40 |
+
assert p2.parameters == (t,)
|
| 41 |
+
assert p2.limits == {}
|
| 42 |
+
assert p2.dimensions == 0
|
| 43 |
+
|
| 44 |
+
circle = ParametricRegion((r*cos(theta), r*sin(theta)), r, (theta, 0, 2*pi))
|
| 45 |
+
assert circle.definition == (r*cos(theta), r*sin(theta))
|
| 46 |
+
assert circle.dimensions == 1
|
| 47 |
+
|
| 48 |
+
halfdisc = ParametricRegion((r*cos(theta), r*sin(theta)), (r, -2, 2), (theta, 0, pi))
|
| 49 |
+
assert halfdisc.definition == (r*cos(theta), r*sin(theta))
|
| 50 |
+
assert halfdisc.parameters == (r, theta)
|
| 51 |
+
assert halfdisc.limits == {r: (-2, 2), theta: (0, pi)}
|
| 52 |
+
assert halfdisc.dimensions == 2
|
| 53 |
+
|
| 54 |
+
ellipse = ParametricRegion((a*cos(t), b*sin(t)), (t, 0, 8))
|
| 55 |
+
assert ellipse.parameters == (t,)
|
| 56 |
+
assert ellipse.limits == {t: (0, 8)}
|
| 57 |
+
assert ellipse.dimensions == 1
|
| 58 |
+
|
| 59 |
+
cylinder = ParametricRegion((r*cos(theta), r*sin(theta), z), (r, 0, 1), (theta, 0, 2*pi), (z, 0, 4))
|
| 60 |
+
assert cylinder.parameters == (r, theta, z)
|
| 61 |
+
assert cylinder.dimensions == 3
|
| 62 |
+
|
| 63 |
+
sphere = ParametricRegion((r*sin(phi)*cos(theta),r*sin(phi)*sin(theta), r*cos(phi)),
|
| 64 |
+
r, (theta, 0, 2*pi), (phi, 0, pi))
|
| 65 |
+
assert sphere.definition == (r*sin(phi)*cos(theta),r*sin(phi)*sin(theta), r*cos(phi))
|
| 66 |
+
assert sphere.parameters == (r, theta, phi)
|
| 67 |
+
assert sphere.dimensions == 2
|
| 68 |
+
|
| 69 |
+
raises(ValueError, lambda: ParametricRegion((a*t**2, 2*a*t), (a, -2)))
|
| 70 |
+
raises(ValueError, lambda: ParametricRegion((a, b), (a**2, sin(b)), (a, 2, 4, 6)))
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def test_parametric_region_list():
|
| 74 |
+
|
| 75 |
+
point = Point(-5, 12)
|
| 76 |
+
assert parametric_region_list(point) == [ParametricRegion((-5, 12))]
|
| 77 |
+
|
| 78 |
+
e = Ellipse(Point(2, 8), 2, 6)
|
| 79 |
+
assert parametric_region_list(e, t) == [ParametricRegion((2*cos(t) + 2, 6*sin(t) + 8), (t, 0, 2*pi))]
|
| 80 |
+
|
| 81 |
+
c = Curve((t, t**3), (t, 5, 3))
|
| 82 |
+
assert parametric_region_list(c) == [ParametricRegion((t, t**3), (t, 5, 3))]
|
| 83 |
+
|
| 84 |
+
s = Segment(Point(2, 11, -6), Point(0, 2, 5))
|
| 85 |
+
assert parametric_region_list(s, t) == [ParametricRegion((2 - 2*t, 11 - 9*t, 11*t - 6), (t, 0, 1))]
|
| 86 |
+
s1 = Segment(Point(0, 0), (1, 0))
|
| 87 |
+
assert parametric_region_list(s1, t) == [ParametricRegion((t, 0), (t, 0, 1))]
|
| 88 |
+
s2 = Segment(Point(1, 2, 3), Point(1, 2, 5))
|
| 89 |
+
assert parametric_region_list(s2, t) == [ParametricRegion((1, 2, 2*t + 3), (t, 0, 1))]
|
| 90 |
+
s3 = Segment(Point(12, 56), Point(12, 56))
|
| 91 |
+
assert parametric_region_list(s3) == [ParametricRegion((12, 56))]
|
| 92 |
+
|
| 93 |
+
poly = Polygon((1,3), (-3, 8), (2, 4))
|
| 94 |
+
assert parametric_region_list(poly, t) == [ParametricRegion((1 - 4*t, 5*t + 3), (t, 0, 1)), ParametricRegion((5*t - 3, 8 - 4*t), (t, 0, 1)), ParametricRegion((2 - t, 4 - t), (t, 0, 1))]
|
| 95 |
+
|
| 96 |
+
p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7,8)))
|
| 97 |
+
raises(ValueError, lambda: parametric_region_list(p1))
|
pllava/share/terminfo/g/guru-44
ADDED
|
Binary file (1.25 kB). View file
|
|
|
pllava/share/terminfo/t/t16
ADDED
|
Binary file (488 Bytes). View file
|
|
|
pllava/share/terminfo/t/tab
ADDED
|
Binary file (1.2 kB). View file
|
|
|
pllava/share/terminfo/t/tab132-15
ADDED
|
Binary file (1.2 kB). View file
|
|
|
pllava/share/terminfo/t/tandem653
ADDED
|
Binary file (467 Bytes). View file
|
|
|
pllava/share/terminfo/t/tek4024
ADDED
|
Binary file (669 Bytes). View file
|
|
|
pllava/share/terminfo/t/tek4105
ADDED
|
Binary file (640 Bytes). View file
|
|
|
pllava/share/terminfo/t/tek4112-nd
ADDED
|
Binary file (489 Bytes). View file
|
|
|
pllava/share/terminfo/t/tek4113-34
ADDED
|
Binary file (498 Bytes). View file
|
|
|
pllava/share/terminfo/t/tek4404
ADDED
|
Binary file (556 Bytes). View file
|
|
|
pllava/share/terminfo/t/teraterm2.3
ADDED
|
Binary file (1.6 kB). View file
|
|
|
pllava/share/terminfo/t/terminator
ADDED
|
Binary file (1.8 kB). View file
|
|
|
pllava/share/terminfo/t/ti707-w
ADDED
|
Binary file (402 Bytes). View file
|
|
|
pllava/share/terminfo/t/ti916-8-132
ADDED
|
Binary file (1.68 kB). View file
|
|
|