Skip to content

Commit

Permalink
TST: test against minimal env
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Dec 17, 2023
1 parent b508e33 commit 019f65c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 11 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
- '3.10'
- '3.11'
- '3.12'
include:
- os: ubuntu-20.04
python-version: '3.9'
fail-fast: false

steps:
Expand All @@ -28,15 +31,26 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- if: ${{ matrix.os == 'ubuntu-20.04' }}
name: Install minimal env
run: |
python -m pip install --upgrade pip
python -m pip install tomli tomli_w
python scripts/pin_requirements.py
python -m pip uninstall --yes tomli tomli_w
python -m pip install -e . --only-binary ':all:'
python -m pip install pytest pytest-mpl pytest-cov
- if: ${{ matrix.os != 'ubuntu-20.04' }}
name: Install full test env
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements_dev.txt
- name: Test deployment
run: |
check-manifest
pipx run check-manifest
pipx run build --sdist
twine check dist/*
pipx run twine check dist/*
- run: python -m pip freeze
- name: Test package
run: |
pytest --color=yes
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ recursive-include cmasher data/*
recursive-exclude cmasher/colormaps *
recursive-include cmasher/colormaps cm_*

exclude docs joss_paper .git*
exclude docs joss_paper .git* scripts/*
recursive-exclude docs *
recursive-exclude joss_paper *
recursive-exclude .github *
Expand Down
36 changes: 32 additions & 4 deletions cmasher/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# %% IMPORTS
# Built-in imports
import os
from importlib.util import module_from_spec, spec_from_file_location
from importlib.util import find_spec, module_from_spec, spec_from_file_location
from os import path

# Package imports
import cmocean as cmo
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -28,6 +27,26 @@
view_cmap,
)

HAS_VISCM = find_spec("viscm") is not None


def _MPL38_colormap_eq(cmap, other) -> bool:
# equality check for two colormaps
# this is adapted from Colormap.__eq__ (mpl 3.8)
# in previous versions, colormaps compared as != unless they
# had the exact same name, which is not what we care about here
from matplotlib.colors import Colormap

if not isinstance(other, Colormap) or cmap.colorbar_extend != other.colorbar_extend:
return False

Check warning on line 41 in cmasher/tests/test_utils.py

View check run for this annotation

Codecov / codecov/patch

cmasher/tests/test_utils.py#L41

Added line #L41 was not covered by tests
# To compare lookup tables the Colormaps have to be initialized
if not cmap._isinit:
cmap._init()

Check warning on line 44 in cmasher/tests/test_utils.py

View check run for this annotation

Codecov / codecov/patch

cmasher/tests/test_utils.py#L44

Added line #L44 was not covered by tests
if not other._isinit:
other._init()

Check warning on line 46 in cmasher/tests/test_utils.py

View check run for this annotation

Codecov / codecov/patch

cmasher/tests/test_utils.py#L46

Added line #L46 was not covered by tests
return np.array_equal(cmap._lut, other._lut)


# Save the path to this directory
dirpath = path.dirname(__file__)

Expand Down Expand Up @@ -70,7 +89,11 @@ def test_standalone_rainforest(self):
# identity equality isn't achievable since mpl.colormaps.__getitem__
# may return a copy
assert cmap_new == mod.cmap
assert cmap_old == cmap_new

if mpl.__version_info__ >= (3, 8):
assert cmap_old == cmap_new
else:
assert _MPL38_colormap_eq(cmap_old, cmap_new)

# Check if the values in both colormaps are the same
assert np.allclose(cmap_old.colors, cmap_new.colors)
Expand All @@ -90,7 +113,11 @@ def test_standalone_infinity(self):

# Check if the colormap in MPL has been updated
cmap_new = mpl.colormaps["cmr.infinity"]
assert cmap_new == mod.cmap
if mpl.__version_info__ >= (3, 8):
assert cmap_old == cmap_new
else:
assert _MPL38_colormap_eq(cmap_old, cmap_new)

assert cmap_old == cmap_new

# Check if the values in both colormaps are the same
Expand Down Expand Up @@ -247,6 +274,7 @@ def test_cmap_file_HEX(self):
import_cmaps(path.join(dirpath, "data/cm_hex.txt"))

# Test if providing a cmap .jscm-file works
@pytest.mark.skipif(not HAS_VISCM, reason="viscm is required")
def test_cmap_file_jscm(self):
cmap_path = path.join(dirpath, "data/cm_rainforest_jscm.jscm")
import_cmaps(cmap_path)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ addopts = "--mpl -v --cov --cov-config=pyproject.toml --cov-report=term-missing"
filterwarnings = [
"error",
"ignore:FigureCanvasAgg is non-interactive:UserWarning",
"ignore:Matplotlib is currently using agg, which is a non-GUI backend:UserWarning",
# this future warning is internal to viscm
"ignore: Deprecated. CatmulClark builds nicer splines.:FutureWarning",
# internal to colorspacious
Expand Down
3 changes: 0 additions & 3 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
-e .
check-manifest
cmocean>=2.0
pyqt5>=5.12
pytest>=4.6.0
pytest-cov
Expand All @@ -9,6 +7,5 @@ pytest-mpl
readme_renderer[md]
scipy>=1.0.0
setuptools>=38.6.0
twine>=1.13.0
viscm>=0.10
wheel>=0.31.0
19 changes: 19 additions & 0 deletions scripts/pin_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys

import tomli_w

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib


with open("pyproject.toml", "rb") as fr:
conf = tomllib.load(fr)

conf["project"]["dependencies"] = [
req.replace(">=", "==") for req in conf["project"]["dependencies"]
]

with open("pyproject.toml", "wb") as fw:
tomli_w.dump(conf, fw)

0 comments on commit 019f65c

Please sign in to comment.