From 47eaa18d6e541c2af6735eebc0d2e3f8dd0ef220 Mon Sep 17 00:00:00 2001 From: akrherz Date: Fri, 27 Sep 2024 10:05:48 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Update=20ruff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .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 4ee3c209..f99ea94c 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.6.7" + rev: "v0.6.8" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 4fca51e769408fa928a00e38b45ee2ee865876ad Mon Sep 17 00:00:00 2001 From: akrherz Date: Fri, 27 Sep 2024 10:41:46 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9D=20Ensure=20WMOProduct=20text?= =?UTF-8?q?=20ends=20with=20line=20return?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + data/product_examples/LSR/LSRFWD.txt | 16 ++++++++++++++++ src/pyiem/nws/product.py | 3 ++- src/pyiem/nws/products/dsm.py | 2 -- src/pyiem/wmo.py | 3 +++ tests/nws/products/test_dsm.py | 5 +---- tests/nws/products/test_lsr.py | 7 +++++++ 7 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 data/product_examples/LSR/LSRFWD.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 690d171d..b8cb9602 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this library are documented in this file. ### API Changes - Discontinue raw SPS product text within the database. +- Ensure raw text products into `WMOProduct` end with a line feed. ### New Features diff --git a/data/product_examples/LSR/LSRFWD.txt b/data/product_examples/LSR/LSRFWD.txt new file mode 100644 index 00000000..91552339 --- /dev/null +++ b/data/product_examples/LSR/LSRFWD.txt @@ -0,0 +1,16 @@ +513 +NWUS54 KFWD 242201 +LSRFWD + +PRELIMINARY LOCAL STORM REPORT +NATIONAL WEATHER SERVICE FORT WORTH TX +401 PM CST TUE JAN 24 2012 + +..TIME.. ...EVENT... ...CITY LOCATION... ...LAT.LON... +..DATE.. ....MAG.... ..COUNTY LOCATION..ST.. ...SOURCE.... + ..REMARKS.. + +0309 PM HAIL EUREKA 32.02N 96.30W +01/24/2012 E0.75 INCH NAVARRO TX PUBLIC + +$$ \ No newline at end of file diff --git a/src/pyiem/nws/product.py b/src/pyiem/nws/product.py index 3665f493..a9ac3e66 100644 --- a/src/pyiem/nws/product.py +++ b/src/pyiem/nws/product.py @@ -658,6 +658,7 @@ def __init__( @param parse_segments should the segments be parsed as well? True """ super().__init__(text, utcnow=utcnow) + # NB: Don't use text as it could have been munged by this point self.afos = None if ugc_provider is None: ugc_provider = {} @@ -665,7 +666,7 @@ def __init__( nwsli_provider = {} self.ugc_provider = ugc_provider self.nwsli_provider = nwsli_provider - self.unixtext = text.replace("\r", "") + self.unixtext = self.text.replace("\r", "") self.sections = self.unixtext.split("\n\n") # The "truth" timestamp self.valid = None diff --git a/src/pyiem/nws/products/dsm.py b/src/pyiem/nws/products/dsm.py index 04a42ca9..d73fb225 100644 --- a/src/pyiem/nws/products/dsm.py +++ b/src/pyiem/nws/products/dsm.py @@ -196,8 +196,6 @@ def __init__( # hold our parsing results self.data = [] lines = self.text.replace("\r", "").split("\n") - if len(lines) < 4: - raise ValueError("Impossibly small DSM Text Product?") if len(lines[3]) < 10: meat = ("".join(lines[4:])).split("=") else: diff --git a/src/pyiem/wmo.py b/src/pyiem/wmo.py index a66b7ba3..d7057c41 100644 --- a/src/pyiem/wmo.py +++ b/src/pyiem/wmo.py @@ -22,6 +22,9 @@ class WMOProduct: def __init__(self, text, utcnow=None): """Constructor.""" self.warnings = [] + # For better or worse, ensure the text string ends with a newline + if not text.endswith("\n"): + text = text + "\n" self.text = text self.source = None self.wmo = None diff --git a/tests/nws/products/test_dsm.py b/tests/nws/products/test_dsm.py index cb74b32a..64977d9e 100644 --- a/tests/nws/products/test_dsm.py +++ b/tests/nws/products/test_dsm.py @@ -53,10 +53,7 @@ def test_jan1(): def test_junk(): """Test that we gracefully handle GIGO.""" - text = "000 \nCDUS27 KISU 020200\nBLAH BLAH=" - with pytest.raises(ValueError): - parser(text) - text += "\nBLAH BLAH BLAH=\n" + text = "000 \nCDUS27 KISU 020200\nBLAH BLAH=\nBLAH BLAH BLAH=\n" prod = parser(text) assert prod.warnings diff --git a/tests/nws/products/test_lsr.py b/tests/nws/products/test_lsr.py index 92773f52..426d621c 100644 --- a/tests/nws/products/test_lsr.py +++ b/tests/nws/products/test_lsr.py @@ -7,6 +7,13 @@ from pyiem.util import get_test_file +def test_240926_nolsrs(): + """Test that this processes a LSR!""" + prod = parser(get_test_file("LSR/LSRFWD.txt")) + assert not prod.warnings + assert len(prod.lsrs) == 1 + + def test_240508_summary_link(): """Test that the summary line is in UTC!""" prod = parser(get_test_file("LSR/LSRPIH_summary.txt"))