Skip to content

Commit 73bca9d

Browse files
authored
CI: unify and test all os (#115)
* CI: unify and test all os * fix package name * fix location of environment file * remove another mesmer artifact * min-deps-check: fix filename * remove all flag * fix macosx backend check * remove unused pytest-env * add colors try not verbose * not unbuffered * remove pytest.ini * get config * move config to pyproject.toml * undo show options * try no options * set options again * cannot remove env var :-( * fix tests * fix expected_size * next_try * set dpi * fix last test * Apply suggestions from code review
1 parent 1e341b2 commit 73bca9d

File tree

8 files changed

+107
-113
lines changed

8 files changed

+107
-113
lines changed

.github/workflows/ci-additional.yaml

+1-54
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,6 @@ concurrency:
1313
cancel-in-progress: true
1414

1515
jobs:
16-
test:
17-
name: py${{ matrix.python-version }}-${{ matrix.env }}
18-
runs-on: "ubuntu-latest"
19-
defaults:
20-
run:
21-
shell: bash -l {0}
22-
strategy:
23-
fail-fast: false
24-
matrix:
25-
include:
26-
- env: "min-all-deps"
27-
python-version: "3.9"
28-
steps:
29-
- uses: actions/checkout@v4
30-
with:
31-
fetch-depth: 0 # Fetch all history for all branches and tags.
32-
33-
- name: Set environment variables
34-
run: |
35-
PY=${{ matrix.python-version }}
36-
# replace "." in matrix.python-version
37-
PY=${PY//./}
38-
echo "CONDA_ENV_FILE=ci/requirements/py${PY}-${{ matrix.env }}.yml" >> $GITHUB_ENV
39-
- name: Create conda environment
40-
uses: mamba-org/setup-micromamba@v1
41-
with:
42-
environment-file: ${{ env.CONDA_ENV_FILE }}
43-
cache-downloads: true
44-
cache-downloads-key: "${{runner.os}}-${{runner.arch}}-py${{matrix.python-version}}"
45-
create-args: >-
46-
python=${{ matrix.python-version }}
47-
- name: Install mplotutils
48-
run: |
49-
python -m pip install --no-deps -e .
50-
- name: Import mplotutils
51-
run: |
52-
python -c "import mplotutils"
53-
- name: Run tests
54-
timeout-minutes: 15
55-
run: python -u -m pytest
56-
--cov=mplotutils
57-
--cov-report=xml
58-
$PYTEST_EXTRA_FLAGS
59-
60-
- name: Upload code coverage to Codecov
61-
uses: codecov/codecov-action@v4
62-
with:
63-
file: ./coverage.xml
64-
flags: unittests,${{ matrix.env }}
65-
env_vars: RUNNER_OS
66-
name: codecov-umbrella
67-
fail_ci_if_error: false
68-
6916
min-version-policy:
7017
name: Minimum Version Policy
7118
runs-on: "ubuntu-latest"
@@ -94,4 +41,4 @@ jobs:
9441
9542
- name: minimum versions policy
9643
run: |
97-
python ci/min_deps_check.py ci/requirements/py39-min-all-deps.yml
44+
python ci/min_deps_check.py ci/requirements/min-all-deps.yml

.github/workflows/ci.yaml

+51-35
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,67 @@ concurrency:
1111
group: ${{ github.workflow }}-${{ github.ref }}
1212
cancel-in-progress: true
1313

14+
env:
15+
FORCE_COLOR: 3
16+
1417
jobs:
1518
test:
16-
name: py${{ matrix.python-version }}
19+
name: py${{ matrix.python-version }} ${{ matrix.os }} ${{ matrix.env }}
1720
runs-on: ${{ matrix.os }}
18-
defaults:
19-
run:
20-
shell: bash -l {0}
2121
strategy:
2222
fail-fast: false
2323
matrix:
2424
os: ["ubuntu-latest"]
25-
# Bookend python versions
2625
python-version: ["3.9", "3.11", "3.12"]
26+
env: [""]
27+
include:
28+
- env: "min-all-deps"
29+
python-version: "3.9"
30+
os: "ubuntu-latest"
31+
- env: ""
32+
python-version: "3.12"
33+
os: "macos-latest"
34+
defaults:
35+
run:
36+
shell: bash -l {0}
37+
2738
steps:
28-
- uses: actions/checkout@v4
29-
with:
30-
fetch-depth: 0 # Fetch all history for all branches and tags.
31-
- name: Set environment variables
32-
run: |
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
42+
- name: Set environment variables
43+
run: |
44+
45+
if [[ "${{ matrix.env }}" == "" ]]; then
3346
echo "CONDA_ENV_FILE=ci/requirements/environment.yml" >> $GITHUB_ENV
34-
echo "PYTHON_VERSION=${{ matrix.python-version }}" >> $GITHUB_ENV
35-
- name: Create conda environment
36-
uses: mamba-org/setup-micromamba@v1
37-
with:
38-
environment-file: ci/requirements/environment.yml
39-
cache-downloads: true
40-
cache-downloads-key: "${{runner.os}}-${{runner.arch}}-py${{matrix.python-version}}"
41-
create-args: >-
42-
python=${{ matrix.python-version }}
43-
- name: Install mplotutils
44-
run: |
45-
python -m pip install --no-deps -e .
46-
- name: Import mplotutils
47-
run: |
48-
python -c "import mplotutils"
49-
- name: Run tests
50-
timeout-minutes: 5
51-
run: python -u -m pytest
52-
--cov=mplotutils
53-
--cov-report=xml
54-
--junitxml=test-results/${{ runner.os }}-${{ matrix.python-version }}.xml
47+
else
48+
echo "CONDA_ENV_FILE=ci/requirements/${{ matrix.env }}.yml" >> $GITHUB_ENV
49+
fi
50+
51+
- name: Create conda environment
52+
uses: mamba-org/setup-micromamba@v1
53+
with:
54+
environment-name: mplotutils-tests
55+
cache-downloads: true
56+
cache-downloads-key: "${{runner.os}}-${{runner.arch}}-py${{matrix.python-version}}-${{ env.CONDA_ENV_FILE }}"
57+
micromamba-version: 'latest'
58+
environment-file: ${{ env.CONDA_ENV_FILE }}
59+
create-args: >-
60+
python=${{ matrix.python-version }}
5561
56-
- name: Upload code coverage to Codecov
57-
uses: codecov/codecov-action@v4
58-
with:
62+
- name: Install mplotutils
63+
run: |
64+
python -m pip install --no-deps -e .
65+
66+
- name: Run tests
67+
run: python -m pytest
68+
-ra -v
69+
--cov=mplotutils
70+
--cov-report=xml
71+
72+
- name: Upload code coverage to Codecov
73+
uses: codecov/codecov-action@v4
74+
with:
5975
file: ./coverage.xml
6076
flags: unittests
6177
env_vars: RUNNER_OS,PYTHON_VERSION
@@ -67,7 +83,7 @@ jobs:
6783
strategy:
6884
fail-fast: false
6985
matrix:
70-
python-version: ["3.11"]
86+
python-version: ["3.12"]
7187

7288
steps:
7389
- uses: actions/checkout@v4

ci/requirements/environment.yml

-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ dependencies:
1515
# for testing
1616
- pytest
1717
- pytest-cov
18-
- pytest-env

ci/requirements/py39-min-all-deps.yml ci/requirements/min-all-deps.yml

-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ dependencies:
1212
# for testing
1313
- pytest
1414
- pytest-cov
15-
- pytest-env

mplotutils/tests/test_set_map_layout.py

+47-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1+
import matplotlib.pyplot as plt
12
import numpy as np
23
import pytest
34

45
from mplotutils import set_map_layout
56

6-
from . import subplots_context
7+
from . import figure_context, subplots_context
8+
9+
10+
def get_rtol(f):
11+
# macosx is only exact up to 1 / dpi
12+
13+
if plt.get_backend().lower() != "macosx":
14+
rtol = 1e-07
15+
else:
16+
rtol = 1 / f.get_dpi()
17+
return rtol
718

819

920
def test_set_map_layout_default_width():
1021
with subplots_context() as (f, ax):
1122
set_map_layout(ax)
1223

13-
assert f.get_size_inches()[0] * 2.54 == 17.0
24+
width = f.get_size_inches()[0] * 2.54
25+
np.testing.assert_allclose(width, 17.0, rtol=get_rtol(f))
1426

1527

1628
@pytest.mark.parametrize(
@@ -25,7 +37,7 @@ def test_set_map_layout_no_borders(nrow_ncol):
2537
set_map_layout(ax, 10, **nrow_ncol)
2638

2739
width, height = f.get_size_inches() * 2.54
28-
assert np.allclose((width, height), (10, 10))
40+
np.testing.assert_allclose((width, height), (10, 10), rtol=get_rtol(f))
2941

3042
# width:height = 2:1
3143
with subplots_context() as (f, ax):
@@ -35,7 +47,7 @@ def test_set_map_layout_no_borders(nrow_ncol):
3547
set_map_layout(ax, 10, **nrow_ncol)
3648

3749
width, height = f.get_size_inches() * 2.54
38-
assert np.allclose((width, height), (10, 5))
50+
np.testing.assert_allclose((width, height), (10, 5), rtol=get_rtol(f))
3951

4052
# width:height = 1:2
4153
with subplots_context() as (f, ax):
@@ -45,7 +57,7 @@ def test_set_map_layout_no_borders(nrow_ncol):
4557
set_map_layout(ax, 10, **nrow_ncol)
4658

4759
width, height = f.get_size_inches() * 2.54
48-
assert np.allclose((width, height), (10, 20))
60+
np.testing.assert_allclose((width, height), (10, 20), rtol=get_rtol(f))
4961

5062

5163
@pytest.mark.parametrize("ax_to_arr", (lambda ax: [ax], lambda ax: np.array(ax)))
@@ -58,7 +70,7 @@ def test_set_map_layout_ax_arr(ax_to_arr):
5870
set_map_layout(ax_to_arr(ax), 10)
5971

6072
width, height = f.get_size_inches() * 2.54
61-
assert np.allclose((width, height), (10, 10))
73+
np.testing.assert_allclose((width, height), (10, 10), rtol=get_rtol(f))
6274

6375

6476
def test_set_map_layout_vert_borders():
@@ -72,7 +84,7 @@ def test_set_map_layout_vert_borders():
7284
set_map_layout(ax, 10)
7385

7486
width, height = f.get_size_inches() * 2.54
75-
assert np.allclose((width, height), (10, 20))
87+
np.testing.assert_allclose((width, height), (10, 20), rtol=get_rtol(f))
7688

7789
# width:height = 1:1
7890
with subplots_context() as (f, ax):
@@ -84,7 +96,7 @@ def test_set_map_layout_vert_borders():
8496
set_map_layout(ax, 10)
8597

8698
width, height = f.get_size_inches() * 2.54
87-
assert np.allclose((width, height), (10, 12.5))
99+
np.testing.assert_allclose((width, height), (10, 12.5), rtol=get_rtol(f))
88100

89101
# width:height = 1:1
90102
with subplots_context() as (f, ax):
@@ -96,7 +108,7 @@ def test_set_map_layout_vert_borders():
96108
set_map_layout(ax, 10)
97109

98110
width, height = f.get_size_inches() * 2.54
99-
assert np.allclose((width, height), (10, 40))
111+
np.testing.assert_allclose((width, height), (10, 40), rtol=get_rtol(f))
100112

101113

102114
def test_set_map_layout_horz_borders():
@@ -110,7 +122,7 @@ def test_set_map_layout_horz_borders():
110122
set_map_layout(ax, 10)
111123

112124
width, height = f.get_size_inches() * 2.54
113-
assert np.allclose((width, height), (10, 5))
125+
np.testing.assert_allclose((width, height), (10, 5), rtol=get_rtol(f))
114126

115127
# width:height = 1:1
116128
with subplots_context() as (f, ax):
@@ -122,7 +134,7 @@ def test_set_map_layout_horz_borders():
122134
set_map_layout(ax, 10)
123135

124136
width, height = f.get_size_inches() * 2.54
125-
assert np.allclose((width, height), (10, 5))
137+
np.testing.assert_allclose((width, height), (10, 5), rtol=get_rtol(f))
126138

127139

128140
def test_set_map_layout_two_axes_vert():
@@ -137,7 +149,7 @@ def test_set_map_layout_two_axes_vert():
137149
set_map_layout(ax, 10)
138150

139151
width, height = f.get_size_inches() * 2.54
140-
assert np.allclose((width, height), (10, 20))
152+
np.testing.assert_allclose((width, height), (10, 20), rtol=get_rtol(f))
141153

142154
# width:height = 1:1
143155
with subplots_context(2, 1) as (f, axs):
@@ -150,7 +162,7 @@ def test_set_map_layout_two_axes_vert():
150162
set_map_layout(ax, 10)
151163

152164
width, height = f.get_size_inches() * 2.54
153-
assert np.allclose((width, height), (10, 30))
165+
np.testing.assert_allclose((width, height), (10, 30), rtol=get_rtol(f))
154166

155167

156168
def test_set_map_layout_two_axes_horz():
@@ -165,7 +177,7 @@ def test_set_map_layout_two_axes_horz():
165177
set_map_layout(ax, 10)
166178

167179
width, height = f.get_size_inches() * 2.54
168-
assert np.allclose((width, height), (10, 5))
180+
np.testing.assert_allclose((width, height), (10, 5), rtol=get_rtol(f))
169181

170182
# width:height = 1:1
171183
with subplots_context(1, 2) as (f, axs):
@@ -178,7 +190,7 @@ def test_set_map_layout_two_axes_horz():
178190
set_map_layout(ax, 10)
179191

180192
width, height = f.get_size_inches() * 2.54
181-
assert np.allclose((width, height), (10, 10 / 3))
193+
np.testing.assert_allclose((width, height), (10, 10 / 3), rtol=get_rtol(f))
182194

183195

184196
def test_set_map_layout_nrow_ncol_only_one_raises():
@@ -201,4 +213,23 @@ def test_set_map_layout_cartopy_2_2():
201213
result = f.get_size_inches() * 2.54
202214
expected = (17, 8.5)
203215

204-
np.testing.assert_allclose(result, expected)
216+
np.testing.assert_allclose(result, expected, rtol=get_rtol(f))
217+
218+
219+
@pytest.mark.skipif(plt.get_backend().lower() != "macosx", reason="only for macosx")
220+
@pytest.mark.parametrize("dpi", (100, 1000))
221+
@pytest.mark.parametrize("size", ([17, 6], [10, 5]))
222+
def test_set_size_inches_macosx(dpi, size):
223+
224+
with figure_context() as f:
225+
226+
f.set_dpi(dpi)
227+
228+
size = np.array(size)
229+
230+
f.set_size_inches(size / 2.54)
231+
232+
result = f.get_size_inches() * 2.54
233+
234+
expected_size = np.floor(size / 2.54 * dpi) / dpi * 2.54
235+
np.testing.assert_allclose(result, expected_size)

pyproject.toml

+8
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ build-backend = "setuptools.build_meta"
88
[tool.setuptools_scm]
99
fallback_version = "999"
1010
version_scheme = "no-guess-dev"
11+
12+
[tool.pytest.ini_options]
13+
14+
log_cli_level = "INFO"
15+
16+
filterwarnings = [
17+
"ignore:numpy.ufunc size changed, may indicate binary incompatibility.:RuntimeWarning"
18+
]

pytest.ini

-2
This file was deleted.

setup.cfg

-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ install_requires =
3030
numpy >=1.22
3131
xarray >=2022.12
3232

33-
[tool:pytest]
34-
filterwarnings =
35-
ignore:numpy.ufunc size changed, may indicate binary incompatibility.:RuntimeWarning
36-
3733
[flake8]
3834
ignore=
3935
# E203: whitespace before ':' - doesn't work well with black

0 commit comments

Comments
 (0)