Skip to content

Commit

Permalink
Merge pull request #25468 from dianetc/initial_hypo
Browse files Browse the repository at this point in the history
try/catch conftest.py, documentation changes
  • Loading branch information
asmeurer committed Aug 16, 2023
2 parents 57450fb + 7ba844f commit 691b1ab
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 38 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/runtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
python-version: '3.11'
- run: python -m pip install --upgrade pip

- run: pip install -r requirements-test.txt
- run: pip install flake8 flake8-comprehensions ruff
- run: pip install -r requirements-dev.txt
- run: pip install ruff

- name: Basic code quality tests
run: bin/test quality
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:
with:
python-version: '3.11'
- run: python -m pip install --upgrade pip
- run: pip install -r requirements-test.txt
- run: pip install -r requirements-dev.txt
- run: bin/test --split ${{ matrix.group }}/4

# -------------------- Test Pyodide on node ---------------------- #
Expand Down Expand Up @@ -193,7 +193,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- run: pip install -r requirements-test.txt
- run: pip install -r requirements-dev.txt

# Install the non-Python dependencies
- run: sudo apt-get update
Expand Down Expand Up @@ -236,7 +236,7 @@ jobs:
with:
python-version: '3.11'
- run: python -m pip install --upgrade pip
- run: pip install -r requirements-test.txt
- run: pip install -r requirements-dev.txt
- run: pip install python-flint
# Test the modules that most directly use python-flint
- run: pytest sympy/polys sympy/ntheory sympy/matrices
Expand Down Expand Up @@ -267,7 +267,7 @@ jobs:
with:
python-version: '3.11'
- run: python -m pip install --upgrade pip
- run: pip install -r requirements-test.txt
- run: pip install -r requirements-dev.txt
- run: pip install numpy scipy tensorflow
# Test modules that can use tensorflow
- run: bin/test_tensorflow.py
Expand All @@ -284,7 +284,7 @@ jobs:
with:
python-version: '3.11'
- run: python -m pip install --upgrade pip
- run: pip install -r requirements-test.txt
- run: pip install -r requirements-dev.txt
- run: pip install numpy symengine
# Test modules that can use tensorflow
- run: bin/test_symengine.py
Expand All @@ -307,7 +307,7 @@ jobs:
with:
python-version: '3.11'
- run: python -m pip install --upgrade pip
- run: pip install -r requirements-test.txt
- run: pip install -r requirements-dev.txt
- run: bin/test --slow --timeout 595 --split ${{ matrix.group }}/4

# -------------------- Test older (and newer) Python --------------- #
Expand All @@ -333,7 +333,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- run: python -m pip install --upgrade pip
- run: pip install -r requirements-test.txt
- run: pip install -r requirements-dev.txt
- run: bin/test --split ${{ matrix.group }}/4

# -------------------- Doctests older (and newer) Python --------------------- #
Expand Down
4 changes: 2 additions & 2 deletions doc/src/contributing/new-contributors-guide/dev-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ You may want to take advantage of using virtual environments to isolate your dev
If you use `conda`, you can use it to create a virtual environment:

```bash
$ conda create -n sympy-dev python=3 mpmath flake8
$ conda create -n sympy-dev -c conda-forge --file requirements-dev.txt
```

If you prefer to use `pip` and `venv`, you can use something like
Expand All @@ -184,7 +184,7 @@ If you prefer to use `pip` and `venv`, you can use something like
cd sympy
python -m venv .venv
source .venv/bin/activate
pip install -e .
pip install -r requirements-dev.txt
```

You can add any other packages to this command that you might find useful for
Expand Down
2 changes: 1 addition & 1 deletion release/compare_tar_against_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main(tarname, gitroot):
'CODEOWNERS',
'asv.conf.actions.json',
'codecov.yml',
'requirements-test.txt',
'requirements-dev.txt',
'MANIFEST.in',
'banner.svg',
# Code of conduct
Expand Down
2 changes: 2 additions & 0 deletions requirements-test.txt → requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ pytest-timeout
pytest-split
pytest-doctestplus
hypothesis
flake8
flake8-comprehensions
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,5 +362,8 @@ def run(self):
install_requires=[
'mpmath>=%s' % min_mpmath_version,
],
extras_require={
"dev": ["pytest>=7.1.0", "hypothesis>=6.70.0"],
},
**extra_kwargs
)
63 changes: 37 additions & 26 deletions sympy/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

sys._running_pytest = True # type: ignore
from sympy.external.importtools import version_tuple

Expand All @@ -7,14 +8,20 @@
from sympy.external.gmpy import GROUND_TYPES
from sympy.utilities.misc import ARCH
import re
from hypothesis import settings

try:
import hypothesis

sp = re.compile(r'([0-9]+)/([1-9][0-9]*)')
hypothesis.settings.register_profile("sympy_hypothesis_profile", deadline=None)
hypothesis.settings.load_profile("sympy_hypothesis_profile")
except ImportError:
raise ImportError(
"hypothesis is a required dependency to run the SymPy test suite. "
"Install it with 'pip install hypothesis' or 'conda install -c conda-forge hypothesis'"
)


settings.register_profile("sympy_hypothesis_profile", deadline=None)
settings.load_profile("sympy_hypothesis_profile")
sp = re.compile(r"([0-9]+)/([1-9][0-9]*)")


def process_split(config, items):
Expand All @@ -23,10 +30,11 @@ def process_split(config, items):
return
m = sp.match(split)
if not m:
raise ValueError("split must be a string of the form a/b "
"where a and b are ints.")
raise ValueError(
"split must be a string of the form a/b " "where a and b are ints."
)
i, t = map(int, m.groups())
start, end = (i-1)*len(items)//t, i*len(items)//t
start, end = (i - 1) * len(items) // t, i * len(items) // t

if i < t:
# remove elements from end of list first
Expand All @@ -37,47 +45,50 @@ def process_split(config, items):
def pytest_report_header(config):
s = "architecture: %s\n" % ARCH
s += "cache: %s\n" % USE_CACHE
version = ''
if GROUND_TYPES =='gmpy':
version = ""
if GROUND_TYPES == "gmpy":
import gmpy2

version = gmpy2.version()
elif GROUND_TYPES == 'flint':
elif GROUND_TYPES == "flint":
# XXX: flint does not have a version() function
#import flint
#version = flint.version()
version = 'unknown'
# import flint
# version = flint.version()
version = "unknown"
s += "ground types: %s %s\n" % (GROUND_TYPES, version)
return s


def pytest_terminal_summary(terminalreporter):
if (terminalreporter.stats.get('error', None) or
terminalreporter.stats.get('failed', None)):
terminalreporter.write_sep(
' ', 'DO *NOT* COMMIT!', red=True, bold=True)
if terminalreporter.stats.get("error", None) or terminalreporter.stats.get(
"failed", None
):
terminalreporter.write_sep(" ", "DO *NOT* COMMIT!", red=True, bold=True)


def pytest_addoption(parser):
parser.addoption("--split", action="store", default="",
help="split tests")
parser.addoption("--split", action="store", default="", help="split tests")


def pytest_collection_modifyitems(config, items):
""" pytest hook. """
"""pytest hook."""
# handle splits
process_split(config, items)


@pytest.fixture(autouse=True, scope='module')
@pytest.fixture(autouse=True, scope="module")
def file_clear_cache():
clear_cache()

@pytest.fixture(autouse=True, scope='module')

@pytest.fixture(autouse=True, scope="module")
def check_disabled(request):
if getattr(request.module, 'disabled', False):
if getattr(request.module, "disabled", False):
pytest.skip("test requirements not met.")
elif getattr(request.module, 'ipython', False):
elif getattr(request.module, "ipython", False):
# need to check version and options for ipython tests
if (version_tuple(pytest.__version__) < version_tuple('2.6.3') and
pytest.config.getvalue('-s') != 'no'):
if (
version_tuple(pytest.__version__) < version_tuple("2.6.3")
and pytest.config.getvalue("-s") != "no"
):
pytest.skip("run py.test with -s or upgrade to newer version.")

0 comments on commit 691b1ab

Please sign in to comment.