Skip to content

Commit bcc2016

Browse files
committed
💚 Improve coverage
1 parent 614787a commit bcc2016

File tree

9 files changed

+31
-22
lines changed

9 files changed

+31
-22
lines changed

src/pywwa/common.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,14 @@ def email_error(exp, message="", trimstr=100):
205205
msg["subject"] = (
206206
f"[pyWWA] {sys.argv[0].rsplit('/', maxsplit=1)[-1]} Traceback -- {hn}"
207207
)
208-
msg["From"] = SETTINGS.get("pywwa_errors_from", "ldm@localhost")
209-
msg["To"] = SETTINGS.get("pywwa_errors_to", "ldm@localhost")
208+
msg["From"] = SETTINGS.get("pywwa_errors_from", "root@localhost")
209+
msg["To"] = SETTINGS.get("pywwa_errors_to", "root@localhost")
210210
if not CTX["disable_email"]:
211211
df = smtp.sendmail(
212-
SETTINGS.get("pywwa_smtp", "smtp"), msg["From"], msg["To"], msg
212+
SETTINGS.get("pywwa_smtp", "localhost"),
213+
msg["From"],
214+
msg["To"],
215+
msg,
213216
)
214217
df.addErrback(LOG.error)
215218
else:

src/pywwa/workflows/nexrad3_attr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ def load_station_table(txn):
3333
LOG.info("Station Table size %s", len(ST.keys()))
3434

3535

36-
def process_data(data):
36+
def process_data(data: bytes) -> dict:
3737
"""I am called when data is ahoy"""
3838
bio = BytesIO()
3939
bio.write(data)
4040
bio.seek(0)
41-
process(bio)
41+
return process(bio)
4242

4343

44-
def process(bio):
44+
def process(bio: BytesIO) -> dict:
4545
"""Process our data, please"""
4646
l3 = Level3File(bio)
4747
ctx = {
@@ -57,7 +57,7 @@ def process(bio):
5757
if "text" in line:
5858
ctx["lines"].append(line["text"])
5959
df = PGCONN.runInteraction(really_process, ctx)
60-
df.addErrback(common.email_error, ctx)
60+
df.addErrback(common.email_error, str(ctx))
6161
return ctx
6262

6363

src/pywwa/workflows/sps.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
from functools import partial
44

5-
# 3rd Party
65
import click
76
from pyiem.database import get_sqlalchemy_conn
87
from pyiem.nws.products.sps import parser
98
from pyiem.nws.ugc import UGCProvider
109

11-
# Local
1210
from pywwa import LOG, common
1311
from pywwa.database import get_database, load_nwsli
1412
from pywwa.ldm import bridge

src/pywwa/workflows/vtec.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313

1414
from functools import partial
1515

16-
# 3rd Party
1716
import click
1817
from pyiem.database import get_sqlalchemy_conn
1918
from pyiem.nws.products.vtec import parser as vtecparser
2019
from pyiem.nws.ugc import UGCProvider
2120
from twisted.mail.smtp import SMTPSenderFactory
2221

23-
# Local
2422
from pywwa import LOG, common
2523
from pywwa.database import get_database, load_nwsli
2624
from pywwa.ldm import bridge

src/pywwa/workflows/xteus.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
"""XTEUS Product Parser!"""
22

3-
# 3rd Party
43
import click
54
from pyiem.nws.products.xteus import parser
65

7-
# Local
86
from pywwa import common
97
from pywwa.database import get_database
108
from pywwa.ldm import bridge
119

1210

13-
def process_data(txn, data):
11+
def process_data(txn, data: str):
1412
"""Process the product"""
1513
prod = parser(data, utcnow=common.utcnow())
1614
if prod.warnings:

tests/test_common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Test pywwa.common"""
22

3+
import pytest_twisted
34
from pyiem.util import utc
45

56
from pywwa import CTX, common
@@ -31,9 +32,10 @@ def test_should_email():
3132
assert not common.email_error(None, None)
3233

3334

35+
@pytest_twisted.inlineCallbacks
3436
def test_email_error():
3537
"""Test that we can email an error."""
3638
common.EMAIL_TIMESTAMPS = []
37-
common.email_error(None, None)
39+
yield common.email_error(None, None)
3840
CTX["disable_email"] = True
39-
common.email_error(None, None)
41+
yield common.email_error(None, None)

tests/workflows/test_dsm_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def test_load_stations(cursor):
1515
"""Test station loading."""
1616
# Need to set one station to a bad tzname to exercise an exception
1717
cursor.execute(
18-
"UPDATE stations SET tzname = 'BoG0S' where id = 'MSP' and "
19-
"network = 'MN_ASOS'"
18+
"UPDATE stations SET tzname = 'BoG0S' where id = 'DSM' and "
19+
"network = 'IA_ASOS'"
2020
)
2121
assert cursor.rowcount == 1
2222
dsm.load_stations(cursor)

tests/workflows/test_nexrad3_attr.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
"""Test nexrad3_attr."""
22

3-
# 3rd Party
43
import pytest
54

65
from pywwa.testing import get_example_filepath
7-
8-
# Local
96
from pywwa.workflows import nexrad3_attr
107

118

@@ -29,7 +26,7 @@ def test_process(cursor):
2926
def test_210910_badvil(cursor):
3027
"""Test that a missing VIL does not cause issues."""
3128
with open(get_example_filepath("NCR_20210911_0023"), "rb") as fh:
32-
ctx = nexrad3_attr.process(fh)
29+
ctx = nexrad3_attr.process_data(fh.read())
3330
assert ctx["nexrad"] == "LAS"
3431
processed = nexrad3_attr.really_process(cursor, ctx)
3532
assert processed == 2

tests/workflows/test_sps.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Exercise the sps workflow."""
2+
3+
import pytest
4+
5+
from pywwa.testing import get_example_file
6+
from pywwa.workflows import sps
7+
8+
9+
@pytest.mark.parametrize("database", ["postgis"])
10+
def test_real_process(cursor):
11+
"""Can we process a real SPS product?"""
12+
data = get_example_file("SPS.txt")
13+
sps.real_process({}, cursor, data)

0 commit comments

Comments
 (0)