Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ci: Re-add tests with optimization enabled #29549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ jobs:
pygobject-ver: '<3.52.0'
- os: ubuntu-22.04
python-version: '3.11'
CFLAGS: "-fno-lto" # Ensure that disabling LTO works.
lto: "--config-settings=setup-args=-Db_lto=false" # Ensure that disabling LTO works.
extra-requirements: '-r requirements/testing/extra.txt'
# https://github.com/matplotlib/matplotlib/issues/29844
pygobject-ver: '<3.52.0'
python-optimize: 'true'
- os: ubuntu-22.04-arm
python-version: '3.12'
# https://github.com/matplotlib/matplotlib/issues/29844
Expand Down Expand Up @@ -317,7 +318,7 @@ jobs:
fi

python -m pip install --no-deps --no-build-isolation --verbose \
--config-settings=setup-args="-DrcParams-backend=Agg" \
--config-settings=setup-args="-DrcParams-backend=Agg" ${{ matrix.lto }} \
--editable .[dev]

if [[ "${{ runner.os }}" != 'macOS' ]]; then
Expand All @@ -334,7 +335,10 @@ jobs:
if [[ "${{ matrix.python-version }}" == '3.13t' ]]; then
export PYTHON_GIL=0
fi
pytest -rfEsXR -n auto \
if [[ "${{ matrix.python-optimize }}" == 'true' ]]; then
export PYTHONOPTIMIZE=2
fi
pytest -rfEsXR -n auto -sv \
--maxfail=50 --timeout=300 --durations=25 \
--cov-report=xml --cov=lib --log-level=DEBUG --color=yes

Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def subprocess_run_helper(func, *args, timeout, extra_env=None):
[
sys.executable,
"-c",
f"import pytest;"
f"pytest.register_assert_rewrite({module!r});"
f"import importlib.util;"
f"_spec = importlib.util.spec_from_file_location({module!r}, {file!r});"
f"_module = importlib.util.module_from_spec(_spec);"
Expand Down
7 changes: 6 additions & 1 deletion lib/matplotlib/tests/test_artist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
from itertools import chain
import sys

import numpy as np

Expand Down Expand Up @@ -256,7 +257,9 @@ def test_setp():
# Check *file* argument
sio = io.StringIO()
plt.setp(lines1, 'zorder', file=sio)
assert sio.getvalue() == ' zorder: float\n'
# With optimization, docstrings are stripped so the automated types don't work.
expected = 'unknown' if sys.flags.optimize >= 2 else 'float'
assert sio.getvalue() == f' zorder: {expected}\n'


def test_None_zorder():
Expand Down Expand Up @@ -361,6 +364,8 @@ def set_myparam2(self, val):
assert 'myparam2' in MyArtist2.set.__doc__


@pytest.mark.skipif(sys.flags.optimize >= 2,
reason='Python optimization is enabled and docstrings are stripped')
def test_set_is_overwritten():
"""set() defined in Artist subclasses should not be overwritten."""
class MyArtist3(martist.Artist):
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/tests/test_backends_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@
reason="$DISPLAY and $WAYLAND_DISPLAY are unset")
@pytest.mark.parametrize('host, mpl', [*qt5_and_qt6_pairs()])
def test_cross_Qt_imports(host, mpl):
if sys.flags.optimize > 0 and 'PySide2' in {host, mpl}:
pytest.xfail('PySide2 does not work optimized')

Check warning on line 464 in lib/matplotlib/tests/test_backends_interactive.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/tests/test_backends_interactive.py#L464

Added line #L464 was not covered by tests
try:
proc = _run_helper(_impl_test_cross_Qt_imports, host, mpl,
timeout=_test_timeout)
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/tests/test_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def test_importable_with_no_home(tmp_path):
env={**os.environ, "MPLCONFIGDIR": str(tmp_path)}, check=True)


@pytest.mark.skipif(sys.flags.optimize >= 2,
reason='Python optimization is enabled and docstrings are stripped')
def test_use_doc_standard_backends():
"""
Test that the standard backends mentioned in the docstring of
Expand Down
24 changes: 14 additions & 10 deletions lib/matplotlib/tests/test_preprocess_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,25 @@ def func_no_ax_args(*args, **kwargs): pass
# this has "enough" information to do all the replaces
_preprocess_data(replace_names=["x", "y"])(func_args)

# no positional_parameter_names but needed due to replaces
with pytest.raises(AssertionError):
# z is unknown
_preprocess_data(replace_names=["x", "y", "z"])(func_args)

# no replacements at all -> all ok...
_preprocess_data(replace_names=[], label_namer=None)(func)
_preprocess_data(replace_names=[], label_namer=None)(func_args)
_preprocess_data(replace_names=[], label_namer=None)(func_kwargs)
_preprocess_data(replace_names=[], label_namer=None)(func_no_ax_args)

# label namer is unknown
with pytest.raises(AssertionError):
_preprocess_data(label_namer="z")(func)
# No asserts with optimizations.
if sys.flags.optimize < 1:
# no positional_parameter_names but needed due to replaces
with pytest.raises(AssertionError):
# z is unknown
_preprocess_data(replace_names=["x", "y", "z"])(func_args)

# label namer is unknown
with pytest.raises(AssertionError):
_preprocess_data(label_namer="z")(func)

with pytest.raises(AssertionError):
_preprocess_data(label_namer="z")(func_args)
with pytest.raises(AssertionError):
_preprocess_data(label_namer="z")(func_args)


@pytest.mark.parametrize('func', all_funcs, ids=all_func_ids)
Expand Down Expand Up @@ -193,6 +195,8 @@ def func(ax, x, y, z=1):
func(None, "a", "b", "z", "z", data=data)


@pytest.mark.skipif(sys.flags.optimize >= 2,
reason='Python optimization is enabled and docstrings are stripped')
def test_docstring_addition():
@_preprocess_data()
def funcy(ax, *args, **kwargs):
Expand Down
Loading