Skip to content

Commit

Permalink
Merge pull request #710 from akrherz/gh709_ap_cmap
Browse files Browse the repository at this point in the history
validate type=cmap for get_autoplot_context
  • Loading branch information
akrherz authored Mar 3, 2023
2 parents b7fe936 + e504ffe commit 9a82cac
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
. .ci_tooling/postgres.sh
. .ci_tooling/miniconda.sh
. .ci_tooling/memcached.sh
pip install codecov requests-mock
python -m pip install . --upgrade
pip install requests-mock
python -m pip install . --upgrade --no-deps
export PATH="/usr/lib/postgresql/14/bin:$PATH"
cd database; sh bootstrap.sh
python schema_manager.py
Expand All @@ -35,15 +35,20 @@ jobs:
cd ..
python util/insert_testing_data.py
coverage run --source=pyiem setup.py test --addopts "--mpl --mpl-results-path=mplresults"
if [[ ${{ matrix.PYTHON_VERSION }} == '3.8' ]]; then
codecov
fi
coverage xml
conda install sphinx
cd docs
make html
touch build/html/.nojekyll
cd ..
- name: Code coverage
if: ${{ matrix.PYTHON_VERSION == '3.8' }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml

- name: Build and Deploy
if: ${{ matrix.PYTHON_VERSION == '3.8' }}
uses: JamesIves/github-pages-deploy-action@releases/v3
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ All notable changes to this library are documented in this file.

### New Features

- Validate `type=cmap` for `util.get_autoplot_context` (#709).

### Bug Fixes

- Correct VTEC `is_emergency` false positive spotted by Kyle Noël.
Expand Down
2 changes: 2 additions & 0 deletions conda_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# installing these
affine
cartopy_offlinedata
coverage
cython
defusedxml
fiona
Expand Down Expand Up @@ -33,6 +34,7 @@ pydantic
pymemcache
pyproj
pytest
pytest-cov
pytest-mpl
pytest-runner
rasterstats
Expand Down
8 changes: 6 additions & 2 deletions src/pyiem/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ def html_escape(val):

def get_test_filepath(name: str) -> str:
"""Helper to get a testing filename, full path."""
basedir = os.path.dirname(__file__)
return f"{basedir}/../../data/product_examples/{name}"
return f"{os.getcwd()}/data/product_examples/{name}"


def get_test_file(name):
Expand Down Expand Up @@ -424,7 +423,12 @@ def get_autoplot_context(fdict, cfg, enforce_optional=False, **kwargs):
"name"
]
ctx[f"_sname{_n}"] = f"[{value}] {sname}"
elif typ == "cmap":
# pylint: disable=import-outside-toplevel
from pyiem.plot.use_agg import plt

if value not in plt.colormaps:
value = default
elif typ in ["int", "month", "zhour", "hour", "day", "year"]:
if value is not None:
value = int(value)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ def test_utc():
assert answer.year == util.utc().year


def test_gh709_get_autoplot_context_cmap():
"""Test that we handle invalid cmaps."""
form = {"c": "bah"}
cfg = {"arguments": [{"type": "cmap", "name": "c", "default": "jet"}]}
ctx = util.get_autoplot_context(form, cfg)
assert ctx["c"] == "jet"


def test_gh709_get_autoplot_context_cmap_valid():
"""Test that we handle invalid cmaps."""
form = {"c": "viridis_r"}
cfg = {"arguments": [{"type": "cmap", "name": "c", "default": "jet"}]}
ctx = util.get_autoplot_context(form, cfg)
assert ctx["c"] == form["c"]


def test_get_autoplot_context_e_set():
"""Ensure that _e gets set."""
form = {"_e": "apdiv"}
Expand Down

0 comments on commit 9a82cac

Please sign in to comment.