From 68392c1be165273da6541847f41f417b1b6509b5 Mon Sep 17 00:00:00 2001 From: akrherz Date: Thu, 15 Aug 2024 10:40:24 -0500 Subject: [PATCH 1/4] chore: bump ruff --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f4ef42d..f2376193 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ ci: autoupdate_schedule: quarterly repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.5.7" + rev: "v0.6.0" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 9f404c473dc2f0b0f8eea0b992aad06d4f3d3f1d Mon Sep 17 00:00:00 2001 From: akrherz Date: Thu, 15 Aug 2024 11:00:22 -0500 Subject: [PATCH 2/4] feat: raise IncompleteWebRequest on bad dates --- CHANGELOG.md | 1 + src/pyiem/util.py | 67 +++++++++++++++++++++++--------------------- src/pyiem/webutil.py | 10 +++---- tests/test_util.py | 9 +++--- 4 files changed, 46 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2f59a9c..053a2e82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this library are documented in this file. - Discontinue persisting text product into {mcd,mpd} table storage. - Discontinue storage of text product into sigmets, use `product_id` instead. +- Raise `IncompleteWebRequest` exception when autoplot datetime parsing fails. ### New Features diff --git a/src/pyiem/util.py b/src/pyiem/util.py index b9cd6413..6d73ba51 100644 --- a/src/pyiem/util.py +++ b/src/pyiem/util.py @@ -53,6 +53,18 @@ def format(self, record): ) +def _strptime(ins: str, fmt: str, rectify: bool = False) -> datetime: + """Wrapper around strptime.""" + try: + return datetime.strptime(ins, fmt) + except ValueError as exp: + if rectify: + return handle_date_err(exp, ins, fmt) + raise IncompleteWebRequest( + f"String provided: `{ins}` does not match format: `{fmt}`" + ) from exp + + def web2ldm(url, ldm_product_name, md5_from_name=False, pqinsert="pqinsert"): """Download a URL and insert into LDM. @@ -321,7 +333,8 @@ def handle_date_err(exp, value, fmt): res = lastday.strftime("%Y-%m-%d") if len(tokens) > 1: res += " " + tokens[1] - return datetime.strptime(res, fmt) + # Careful here, we don't want a recursive loop + return _strptime(res, fmt, rectify=False) def get_autoplot_context(fdict, cfg, enforce_optional=False, **kwargs): @@ -442,11 +455,11 @@ def _float(val): elif typ == "datetime": # tricky here, php has YYYY/mm/dd and CGI has YYYY-mm-dd if default is not None: - default = datetime.strptime(default, "%Y/%m/%d %H%M") + default = _strptime(default, "%Y/%m/%d %H%M") if minval is not None: - minval = datetime.strptime(minval, "%Y/%m/%d %H%M") + minval = _strptime(minval, "%Y/%m/%d %H%M") if maxval is not None: - maxval = datetime.strptime(maxval, "%Y/%m/%d %H%M") + maxval = _strptime(maxval, "%Y/%m/%d %H%M") if value is not None: # A common problem is for the space to be missing if value.find(" ") == -1: @@ -455,50 +468,40 @@ def _float(val): else: value += " 0000" _dtfmt = "%Y-%m-%d %H%M" - try: - value = datetime.strptime( - value[:15].replace("/", "-"), "%Y-%m-%d %H%M" - ) - except ValueError as exp: - if kwargs.get("rectify_dates", False): - value = handle_date_err(exp, value, _dtfmt) - else: - # If we are not rectifying dates, we just raise the - # exception - raise + value = _strptime( + value[:15].replace("/", "-"), + "%Y-%m-%d %H%M", + rectify=kwargs.get("rectify_dates", False), + ) elif typ == "sday": # supports legacy uris with yyyy-mm-dd, before migration to sday if default is not None: - default = datetime.strptime(f"2000{default}", "%Y%m%d").date() + default = _strptime(f"2000{default}", "%Y%m%d").date() if minval is not None: - minval = datetime.strptime(f"2000{minval}", "%Y%m%d").date() + minval = _strptime(f"2000{minval}", "%Y%m%d").date() if maxval is not None: - maxval = datetime.strptime(f"2000{maxval}", "%Y%m%d").date() + maxval = _strptime(f"2000{maxval}", "%Y%m%d").date() if value is not None: if value.find("-") > -1: - value = datetime.strptime(value, "%Y-%m-%d").date() + value = _strptime(value, "%Y-%m-%d").date() else: - value = datetime.strptime(f"2000{value}", "%Y%m%d").date() + value = _strptime(f"2000{value}", "%Y%m%d").date() elif typ == "date": # tricky here, php has YYYY/mm/dd and CGI has YYYY-mm-dd if default is not None: - default = datetime.strptime(default, "%Y/%m/%d").date() + default = _strptime(default, "%Y/%m/%d").date() if minval is not None: - minval = datetime.strptime(minval, "%Y/%m/%d").date() + minval = _strptime(minval, "%Y/%m/%d").date() if maxval is not None: - maxval = datetime.strptime(maxval, "%Y/%m/%d").date() + maxval = _strptime(maxval, "%Y/%m/%d").date() if value is not None: - try: - value = datetime.strptime(value, "%Y-%m-%d").date() - except ValueError as exp: - if kwargs.get("rectify_dates", False): - value = handle_date_err(exp, value, "%Y-%m-%d").date() - else: - # If we are not rectifying dates, we just raise the - # exception - raise + value = _strptime( + value, + "%Y-%m-%d", + rectify=kwargs.get("rectify_dates", False), + ).date() elif typ == "vtec_ps": # VTEC phenomena and significance defaults = {} diff --git a/src/pyiem/webutil.py b/src/pyiem/webutil.py index 53647ba8..364161aa 100644 --- a/src/pyiem/webutil.py +++ b/src/pyiem/webutil.py @@ -1,6 +1,5 @@ """Utility functions for iemwebfarm applications.""" -import datetime import random import re import string @@ -8,6 +7,7 @@ import traceback import warnings from collections import namedtuple +from datetime import datetime from http import HTTPStatus from zoneinfo import ZoneInfo, ZoneInfoNotFoundError @@ -237,7 +237,7 @@ def compute_ts_from_string(form, key): fmt += ".%f" if len(tstr.split(":")) == 2: fmt = "%Y-%m-%d %H:%M" - return datetime.datetime.strptime(tstr, fmt).replace(tzinfo=tz) + return datetime.strptime(tstr, fmt).replace(tzinfo=tz) def compute_ts(form, suffix): @@ -260,7 +260,7 @@ def compute_ts(form, suffix): else: day = 28 - return datetime.datetime( + return datetime( int(yearval), month, day, @@ -447,7 +447,7 @@ def _handle_exp(errormsg, routine=False, code=500): ) return [msg.encode("ascii")] - start_time = datetime.datetime.utcnow() + start_time = datetime.utcnow() status_code = 500 try: # mixed convers this to a regular dict @@ -489,7 +489,7 @@ def _handle_exp(errormsg, routine=False, code=500): ) except Exception: res = _handle_exp(traceback.format_exc()) - end_time = datetime.datetime.utcnow() + end_time = datetime.utcnow() if kwargs.get("enable_telemetry", True): write_telemetry( TELEMETRY( diff --git a/tests/test_util.py b/tests/test_util.py index 4a6a6cd9..38e41c55 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -14,6 +14,7 @@ # third party import pytest + from pyiem import util from pyiem.exceptions import IncompleteWebRequest, UnknownStationException from pyiem.reference import ISO8601 @@ -346,21 +347,21 @@ def test_get_autoplot_context_dates(): assert ctx["d2"] == datetime(2016, 9, 30, 13, 14) assert ctx["d3"] == datetime(2016, 9, 30, 13, 14) form["d"] = "2016-06-30" - with pytest.raises(ValueError): + with pytest.raises(IncompleteWebRequest): util.get_autoplot_context(form, opts, rectify_dates=False) form["d"] = "2016-06-XX" - with pytest.raises(ValueError): + with pytest.raises(IncompleteWebRequest): util.get_autoplot_context(form, opts, rectify_dates=False) form["d"] = "2016-06-31" form["d2"] = "2016-09-30" # triggers appending 0000 - with pytest.raises(ValueError): + with pytest.raises(IncompleteWebRequest): util.get_autoplot_context(form, opts, rectify_dates=False) form["d"] = "2016-06-30" form["d2"] = "2016-09-30 2414" - with pytest.raises(ValueError): + with pytest.raises(IncompleteWebRequest): util.get_autoplot_context(form, opts, rectify_dates=False) From 6456539079f82e78f323779cacf314272f185d65 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 16:01:22 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/grid/test_zs.py | 3 ++- tests/models/test_models_shef.py | 1 + tests/ncei/test_ds3505.py | 1 + tests/nws/products/test_cf6.py | 1 + tests/nws/products/test_cli.py | 1 + tests/nws/products/test_cwa.py | 2 +- tests/nws/products/test_dsm.py | 1 + tests/nws/products/test_fd.py | 1 + tests/nws/products/test_ffg.py | 1 + tests/nws/products/test_hml.py | 1 + tests/nws/products/test_lsr.py | 1 + tests/nws/products/test_mcd.py | 1 + tests/nws/products/test_metarcollect.py | 1 + tests/nws/products/test_mos.py | 1 + tests/nws/products/test_nldn.py | 1 + tests/nws/products/test_pirep.py | 1 + tests/nws/products/test_products_vtec.py | 1 + tests/nws/products/test_saw.py | 1 + tests/nws/products/test_scp.py | 1 + tests/nws/products/test_shef.py | 1 + tests/nws/products/test_spcpts.py | 1 + tests/nws/products/test_sps.py | 1 + tests/nws/products/test_taf.py | 1 + tests/nws/test_bufkit.py | 1 + tests/nws/test_lsrclass.py | 1 + tests/nws/test_product.py | 1 + tests/nws/test_products.py | 1 + tests/nws/test_ugc.py | 1 + tests/plot/test_calendarplot.py | 1 + tests/plot/test_geoplot.py | 2 +- tests/plot/test_layouts.py | 1 + tests/plot/test_plot_utils.py | 1 + tests/plot/test_windrose.py | 1 + tests/test_database.py | 1 + tests/test_datatypes.py | 1 + tests/test_dep.py | 1 + tests/test_geom_util.py | 3 ++- tests/test_iemre.py | 1 + tests/test_meteorology.py | 1 + tests/test_mrms.py | 1 + tests/test_network.py | 1 + tests/test_observation.py | 1 + tests/test_tracker.py | 1 + tests/test_webutil.py | 1 + tests/test_wellknowntext.py | 3 ++- tests/test_windrose_utils.py | 1 + util/create_transformed_parquet.py | 1 + util/make_bounds.py | 5 +++-- util/make_cities.py | 1 + util/make_ramps.py | 1 + util/make_shapes.py | 1 + 51 files changed, 56 insertions(+), 7 deletions(-) diff --git a/tests/grid/test_zs.py b/tests/grid/test_zs.py index e04577d8..5d98c6c2 100644 --- a/tests/grid/test_zs.py +++ b/tests/grid/test_zs.py @@ -3,9 +3,10 @@ import numpy as np from affine import Affine from geopandas import GeoSeries -from pyiem.grid import zs from shapely.geometry import Polygon +from pyiem.grid import zs + def test_polygon_to_left(): """Test that we don't get an artifact in the first column.""" diff --git a/tests/models/test_models_shef.py b/tests/models/test_models_shef.py index 1d73d343..7a8c03ac 100644 --- a/tests/models/test_models_shef.py +++ b/tests/models/test_models_shef.py @@ -2,6 +2,7 @@ # pylint: disable=redefined-outer-name import pytest + from pyiem.models.shef import SHEFElement from pyiem.util import utc diff --git a/tests/ncei/test_ds3505.py b/tests/ncei/test_ds3505.py index fbaa68e3..c666538c 100644 --- a/tests/ncei/test_ds3505.py +++ b/tests/ncei/test_ds3505.py @@ -2,6 +2,7 @@ # pylint: disable=redefined-outer-name import numpy as np + from pyiem.ncei import ds3505 from pyiem.util import get_test_filepath, utc diff --git a/tests/nws/products/test_cf6.py b/tests/nws/products/test_cf6.py index 2018b4da..98e64420 100644 --- a/tests/nws/products/test_cf6.py +++ b/tests/nws/products/test_cf6.py @@ -3,6 +3,7 @@ import datetime import pytest + from pyiem.nws.products.cf6 import parser from pyiem.reference import TRACE_VALUE from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_cli.py b/tests/nws/products/test_cli.py index 73b769de..d698a415 100644 --- a/tests/nws/products/test_cli.py +++ b/tests/nws/products/test_cli.py @@ -3,6 +3,7 @@ import datetime import pytest + from pyiem.nws.products import cli from pyiem.nws.products import parser as cliparser from pyiem.nws.products.cli import CLIException, get_number diff --git a/tests/nws/products/test_cwa.py b/tests/nws/products/test_cwa.py index d72a4e83..919de1e0 100644 --- a/tests/nws/products/test_cwa.py +++ b/tests/nws/products/test_cwa.py @@ -2,11 +2,11 @@ # third party import pytest +from shapely.geometry import Polygon # this from pyiem.nws.products.cwa import parser from pyiem.util import get_test_file, utc -from shapely.geometry import Polygon LOCS = { "AMG": {"lon": -82.51, "lat": 31.54}, diff --git a/tests/nws/products/test_dsm.py b/tests/nws/products/test_dsm.py index 418c392e..cb74b32a 100644 --- a/tests/nws/products/test_dsm.py +++ b/tests/nws/products/test_dsm.py @@ -4,6 +4,7 @@ from zoneinfo import ZoneInfo import pytest + from pyiem.nws.products.dsm import compute_time, parser, process from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_fd.py b/tests/nws/products/test_fd.py index 0e78a1bb..c64d0004 100644 --- a/tests/nws/products/test_fd.py +++ b/tests/nws/products/test_fd.py @@ -1,6 +1,7 @@ """Test FD.""" import pytest + from pyiem.nws.products.fd import parse_encoding, parser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_ffg.py b/tests/nws/products/test_ffg.py index 51667729..9db39389 100644 --- a/tests/nws/products/test_ffg.py +++ b/tests/nws/products/test_ffg.py @@ -1,6 +1,7 @@ """Testing FFG parsing.""" import pytest + from pyiem.nws.products.ffg import parser as ffgparser from pyiem.util import get_test_file diff --git a/tests/nws/products/test_hml.py b/tests/nws/products/test_hml.py index 8fdf85d7..14b200a7 100644 --- a/tests/nws/products/test_hml.py +++ b/tests/nws/products/test_hml.py @@ -3,6 +3,7 @@ import datetime import pytest + from pyiem.nws.products.hml import parser as hmlparser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_lsr.py b/tests/nws/products/test_lsr.py index 31200f14..92773f52 100644 --- a/tests/nws/products/test_lsr.py +++ b/tests/nws/products/test_lsr.py @@ -1,6 +1,7 @@ """Test Local Storm Report parsing.""" import pytest + from pyiem.nws.products.lsr import parse_lsr, parser from pyiem.reference import TRACE_VALUE from pyiem.util import get_test_file diff --git a/tests/nws/products/test_mcd.py b/tests/nws/products/test_mcd.py index 4bf53c0f..68206ed7 100644 --- a/tests/nws/products/test_mcd.py +++ b/tests/nws/products/test_mcd.py @@ -1,6 +1,7 @@ """MCD/MPD tests.""" import pytest + from pyiem.exceptions import MCDException from pyiem.nws.products import parser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_metarcollect.py b/tests/nws/products/test_metarcollect.py index a3f02626..7237f477 100644 --- a/tests/nws/products/test_metarcollect.py +++ b/tests/nws/products/test_metarcollect.py @@ -3,6 +3,7 @@ from unittest import mock import pytest + from pyiem.nws.products import metarcollect from pyiem.reference import TRACE_VALUE from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_mos.py b/tests/nws/products/test_mos.py index 5e24cd8b..d9915ced 100644 --- a/tests/nws/products/test_mos.py +++ b/tests/nws/products/test_mos.py @@ -1,6 +1,7 @@ """Test MOS Parsing.""" import pytest + from pyiem.nws.products.mos import parser as mosparser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_nldn.py b/tests/nws/products/test_nldn.py index 36d9ad1a..207d3da5 100644 --- a/tests/nws/products/test_nldn.py +++ b/tests/nws/products/test_nldn.py @@ -1,6 +1,7 @@ """Test NLDN.""" import pytest + from pyiem.nws.products.nldn import parser from pyiem.util import get_test_filepath diff --git a/tests/nws/products/test_pirep.py b/tests/nws/products/test_pirep.py index b64f6406..5342e269 100644 --- a/tests/nws/products/test_pirep.py +++ b/tests/nws/products/test_pirep.py @@ -1,6 +1,7 @@ """PIREP.""" import pytest + from pyiem.nws.products.pirep import parser as pirepparser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_products_vtec.py b/tests/nws/products/test_products_vtec.py index d56bfe95..45ca1f73 100644 --- a/tests/nws/products/test_products_vtec.py +++ b/tests/nws/products/test_products_vtec.py @@ -5,6 +5,7 @@ import pandas as pd import pytest + from pyiem.nws.nwsli import NWSLI from pyiem.nws.products.vtec import check_dup_ps from pyiem.nws.products.vtec import parser as _vtecparser diff --git a/tests/nws/products/test_saw.py b/tests/nws/products/test_saw.py index aaaea1c9..6d019143 100644 --- a/tests/nws/products/test_saw.py +++ b/tests/nws/products/test_saw.py @@ -1,6 +1,7 @@ """Can we process the SAW""" import pytest + from pyiem.nws.products import parser from pyiem.nws.products.saw import parser as sawparser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_scp.py b/tests/nws/products/test_scp.py index f0c630ba..71f58e20 100644 --- a/tests/nws/products/test_scp.py +++ b/tests/nws/products/test_scp.py @@ -1,6 +1,7 @@ """Can we process the SCP""" import pytest + from pyiem.nws.products.scp import parser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_shef.py b/tests/nws/products/test_shef.py index 8b7efdd8..b79ada3a 100644 --- a/tests/nws/products/test_shef.py +++ b/tests/nws/products/test_shef.py @@ -6,6 +6,7 @@ import mock import pytest + from pyiem.exceptions import InvalidSHEFEncoding, InvalidSHEFValue from pyiem.nws.products.shef import ( make_date, diff --git a/tests/nws/products/test_spcpts.py b/tests/nws/products/test_spcpts.py index 01e2bedb..ee4ff528 100644 --- a/tests/nws/products/test_spcpts.py +++ b/tests/nws/products/test_spcpts.py @@ -1,6 +1,7 @@ """Unit Tests""" import pytest + from pyiem.nws.products import parser from pyiem.nws.products._outlook_util import debug_draw from pyiem.nws.products.spcpts import ( diff --git a/tests/nws/products/test_sps.py b/tests/nws/products/test_sps.py index 8d1983f9..f7a3cc3f 100644 --- a/tests/nws/products/test_sps.py +++ b/tests/nws/products/test_sps.py @@ -1,6 +1,7 @@ """SPS Parsing""" import pytest + from pyiem.nws.products import parser as spsparser from pyiem.nws.ugc import UGC from pyiem.reference import TWEET_CHARS diff --git a/tests/nws/products/test_taf.py b/tests/nws/products/test_taf.py index 8d508cb2..e174d8fa 100644 --- a/tests/nws/products/test_taf.py +++ b/tests/nws/products/test_taf.py @@ -2,6 +2,7 @@ # Third Party import pytest + from pyiem.nws.products import parser as tafparser from pyiem.nws.products.taf import parser as real_tafparser from pyiem.reference import TAF_VIS_OVER_6SM diff --git a/tests/nws/test_bufkit.py b/tests/nws/test_bufkit.py index b6f474a3..b7b58905 100644 --- a/tests/nws/test_bufkit.py +++ b/tests/nws/test_bufkit.py @@ -5,6 +5,7 @@ # third party import pytest + from pyiem.nws.bufkit import read_bufkit # Local diff --git a/tests/nws/test_lsrclass.py b/tests/nws/test_lsrclass.py index 5e8bd52b..ed2b391c 100644 --- a/tests/nws/test_lsrclass.py +++ b/tests/nws/test_lsrclass.py @@ -1,6 +1,7 @@ """test lsr.""" import pytest + from pyiem.nws.lsr import _icestorm_remark as ir from pyiem.nws.products import lsr from pyiem.nws.products.lsr import _mylowercase diff --git a/tests/nws/test_product.py b/tests/nws/test_product.py index faed85c5..4a6a5807 100644 --- a/tests/nws/test_product.py +++ b/tests/nws/test_product.py @@ -1,6 +1,7 @@ """Testing!""" import pytest + from pyiem.nws import product, ugc from pyiem.nws.product import ( TextProduct, diff --git a/tests/nws/test_products.py b/tests/nws/test_products.py index a416008f..c274fe55 100644 --- a/tests/nws/test_products.py +++ b/tests/nws/test_products.py @@ -1,6 +1,7 @@ """Massive omnibus of testing for pyiem.nws.products.""" import pytest + from pyiem.exceptions import HWOException, TextProductException from pyiem.nws.products import parser from pyiem.util import get_test_file, utc diff --git a/tests/nws/test_ugc.py b/tests/nws/test_ugc.py index e858a03b..fc80d7b6 100644 --- a/tests/nws/test_ugc.py +++ b/tests/nws/test_ugc.py @@ -1,6 +1,7 @@ """Can we parse UGC strings""" import pytest + from pyiem.exceptions import UGCParseException from pyiem.nws import ugc from pyiem.util import utc diff --git a/tests/plot/test_calendarplot.py b/tests/plot/test_calendarplot.py index 4be68248..615fb9f1 100644 --- a/tests/plot/test_calendarplot.py +++ b/tests/plot/test_calendarplot.py @@ -3,6 +3,7 @@ import datetime import pytest + from pyiem.plot.calendarplot import calendar_plot PAIN = 0.02 # how much do we care, sigh. diff --git a/tests/plot/test_geoplot.py b/tests/plot/test_geoplot.py index 0eeb5d42..d4eb6f6c 100644 --- a/tests/plot/test_geoplot.py +++ b/tests/plot/test_geoplot.py @@ -10,6 +10,7 @@ import mock import numpy as np import pytest +from shapely.geometry import Polygon # Local from pyiem.dep import RAMPS @@ -25,7 +26,6 @@ from pyiem.plot.util import mask_outside_geom from pyiem.reference import LATLON, TWITTER_RESOLUTION_INCH from pyiem.util import load_geodf, utc -from shapely.geometry import Polygon # Increased threshold with matplotlib 3.6 tweaks PAIN = 4.1 diff --git a/tests/plot/test_layouts.py b/tests/plot/test_layouts.py index b9e04eae..36e5088b 100644 --- a/tests/plot/test_layouts.py +++ b/tests/plot/test_layouts.py @@ -2,6 +2,7 @@ # third party import pytest + from pyiem.plot.layouts import figure, figure_axes # local diff --git a/tests/plot/test_plot_utils.py b/tests/plot/test_plot_utils.py index 68512c41..6aac9fe9 100644 --- a/tests/plot/test_plot_utils.py +++ b/tests/plot/test_plot_utils.py @@ -1,6 +1,7 @@ """Test pyiem.plot.utils.""" import pytest + from pyiem.plot.util import centered_bins, draw_logo, fitbox, pretty_bins diff --git a/tests/plot/test_windrose.py b/tests/plot/test_windrose.py index a7ea9e52..44e796cb 100644 --- a/tests/plot/test_windrose.py +++ b/tests/plot/test_windrose.py @@ -3,6 +3,7 @@ import numpy as np import pytest from metpy.units import units + from pyiem.plot.colormaps import get_cmap from pyiem.plot.windrose import ( PLOT_CONVENTION_TO, diff --git a/tests/test_database.py b/tests/test_database.py index efdf73f9..cc4ad7f7 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -3,6 +3,7 @@ # third party import numpy as np import pytest + from pyiem import database from pyiem.exceptions import NewDatabaseConnectionFailure diff --git a/tests/test_datatypes.py b/tests/test_datatypes.py index 5f7f72f2..d66b13c2 100644 --- a/tests/test_datatypes.py +++ b/tests/test_datatypes.py @@ -1,6 +1,7 @@ """Test our pyiem.datatypes hack.""" import pytest + from pyiem import datatypes diff --git a/tests/test_dep.py b/tests/test_dep.py index 047349e2..c8416334 100644 --- a/tests/test_dep.py +++ b/tests/test_dep.py @@ -4,6 +4,7 @@ import os import pytest + from pyiem import dep diff --git a/tests/test_geom_util.py b/tests/test_geom_util.py index 1c4d4db6..629563e2 100644 --- a/tests/test_geom_util.py +++ b/tests/test_geom_util.py @@ -2,9 +2,10 @@ # Third Party # Local -from pyiem import geom_util from shapely.geometry import LineString, Polygon +from pyiem import geom_util + SQUARE = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]) diff --git a/tests/test_iemre.py b/tests/test_iemre.py index d61376a1..7ac8a3c4 100644 --- a/tests/test_iemre.py +++ b/tests/test_iemre.py @@ -6,6 +6,7 @@ import numpy as np import pygrib from affine import Affine + from pyiem import database, iemre from pyiem.util import get_test_filepath, utc diff --git a/tests/test_meteorology.py b/tests/test_meteorology.py index 5a760484..31d0e003 100644 --- a/tests/test_meteorology.py +++ b/tests/test_meteorology.py @@ -5,6 +5,7 @@ import numpy as np import pytest from metpy.units import masked_array, units + from pyiem import datatypes, meteorology from pyiem.exceptions import InvalidArguments diff --git a/tests/test_mrms.py b/tests/test_mrms.py index c1b858bd..34023eb9 100644 --- a/tests/test_mrms.py +++ b/tests/test_mrms.py @@ -4,6 +4,7 @@ import os import requests + from pyiem import mrms from pyiem.util import utc diff --git a/tests/test_network.py b/tests/test_network.py index 83a05cb2..c49616df 100644 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -4,6 +4,7 @@ from datetime import date import pytest + from pyiem import network diff --git a/tests/test_observation.py b/tests/test_observation.py index 1c3b2416..9b24cb68 100644 --- a/tests/test_observation.py +++ b/tests/test_observation.py @@ -9,6 +9,7 @@ import numpy as np import pandas as pd import pytest + from pyiem import observation from pyiem.database import get_dbconnc from pyiem.util import utc diff --git a/tests/test_tracker.py b/tests/test_tracker.py index b0da356e..8e0d4882 100644 --- a/tests/test_tracker.py +++ b/tests/test_tracker.py @@ -4,6 +4,7 @@ from datetime import date, datetime, timedelta, timezone import pytest + from pyiem.database import get_dbconnc from pyiem.network import Table as NetworkTable from pyiem.tracker import TrackerEngine, loadqc diff --git a/tests/test_webutil.py b/tests/test_webutil.py index 53f2d479..2493d0f5 100644 --- a/tests/test_webutil.py +++ b/tests/test_webutil.py @@ -8,6 +8,7 @@ import mock import pytest from pydantic import AwareDatetime, Field + from pyiem.database import get_dbconn from pyiem.exceptions import ( BadWebRequest, diff --git a/tests/test_wellknowntext.py b/tests/test_wellknowntext.py index 695f47d2..a3a23443 100644 --- a/tests/test_wellknowntext.py +++ b/tests/test_wellknowntext.py @@ -1,9 +1,10 @@ """tests""" import pytest -from pyiem import wellknowntext from shapely.geometry import LineString, Point, Polygon +from pyiem import wellknowntext + def test_bad_well_known_text(): """This should fail!""" diff --git a/tests/test_windrose_utils.py b/tests/test_windrose_utils.py index a1d61354..c55fe20c 100644 --- a/tests/test_windrose_utils.py +++ b/tests/test_windrose_utils.py @@ -6,6 +6,7 @@ import pytest from metpy.units import units from pandas import read_csv + from pyiem.plot.windrose import PLOT_CONVENTION_TO from pyiem.util import utc from pyiem.windrose_utils import windrose diff --git a/util/create_transformed_parquet.py b/util/create_transformed_parquet.py index 696bf7dc..2e3a5b51 100644 --- a/util/create_transformed_parquet.py +++ b/util/create_transformed_parquet.py @@ -8,6 +8,7 @@ import click import geopandas as gpd + from pyiem.reference import EPSG from pyiem.util import logger diff --git a/util/make_bounds.py b/util/make_bounds.py index 8a9608d5..c2e6d59d 100644 --- a/util/make_bounds.py +++ b/util/make_bounds.py @@ -1,11 +1,12 @@ """Generate the _ccw files used in pyIEM.""" import numpy as np -from pyiem.database import get_dbconn -from pyiem.plot.geoplot import MapPlot from shapely.geometry import MultiPolygon from shapely.wkb import loads +from pyiem.database import get_dbconn +from pyiem.plot.geoplot import MapPlot + def main(): """Go Main Go.""" diff --git a/util/make_cities.py b/util/make_cities.py index b92c69f0..7e8ab421 100644 --- a/util/make_cities.py +++ b/util/make_cities.py @@ -3,6 +3,7 @@ """ from geopandas import read_parquet, read_postgis + from pyiem.database import get_dbconn FILENAME = "../src/pyiem/data/geodf/cities.parquet" diff --git a/util/make_ramps.py b/util/make_ramps.py index a8cd5a06..a172e653 100644 --- a/util/make_ramps.py +++ b/util/make_ramps.py @@ -4,6 +4,7 @@ """ import pandas as pd + from pyiem.database import get_dbconnstr from pyiem.util import logger diff --git a/util/make_shapes.py b/util/make_shapes.py index 93a330b8..50f5d321 100644 --- a/util/make_shapes.py +++ b/util/make_shapes.py @@ -5,6 +5,7 @@ import warnings import geopandas as gpd + from pyiem.database import get_sqlalchemy_conn from pyiem.reference import state_bounds from pyiem.util import logger From f51e21f4cfef421bacc9ce7dc49ae904585e966e Mon Sep 17 00:00:00 2001 From: akrherz Date: Thu, 15 Aug 2024 11:17:04 -0500 Subject: [PATCH 4/4] fix: address coverage hit --- tests/test_util.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_util.py b/tests/test_util.py index 38e41c55..1dd2bb89 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -332,12 +332,13 @@ def test_get_autoplot_context_dates(): } opts = dict( arguments=[ - dict( - type="date", - name="d", - default="2011/11/12", - maxval="2022/01/01", - ), + { + "type": "date", + "name": "d", + "default": "2011/11/12", + "max": "2022/01/01", + "min": "2011/01/01", + }, dict(type="datetime", name="d2", default="2011/11/12 1213"), {"type": "datetime", "name": "d3", "default": "2011/11/12 1213"}, ]