Skip to content

Commit

Permalink
Updated pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
RoryPTB committed Sep 12, 2023
1 parent 3251cd6 commit b3c9aa3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ RUN echo "Acquire::Check-Valid-Until \"false\";\nAcquire::Check-Date \"false\";"
&& apt-get update -y \
&& apt-get install -y ${DEBIAN_PACKAGES} \
&& apt-get install -y python3 python3-pip libeccodes-tools \
&& pip3 install --no-cache-dir https://github.com/wmo-im/csv2bufr/archive/refs/tags/v0.6.3.zip \
&& pip3 install --no-cache-dir https://github.com/wmo-im/pymetdecoder/archive/refs/tags/v0.1.9.zip
&& pip3 install --no-cache-dir https://github.com/wmo-im/csv2bufr/archive/refs/tags/v0.7.1.zip \
&& pip3 install --no-cache-dir https://github.com/wmo-im/pymetdecoder/archive/refs/tags/v0.1.10.zip

ENV LOG_LEVEL=INFO

Expand Down
24 changes: 12 additions & 12 deletions synop2bufr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
from pymetdecoder import synop
from csv2bufr import BUFRMessage

__version__ = '0.5.1'
__version__ = '0.5.dev2'

LOGGER = logging.getLogger(__name__)

# Global array to store warnings
# Global arrays to store warnings and errors
warning_msgs = []
error_msgs = []

# ! Configure the pymetdecoder/csv2bufr loggers to append warnings to the array

Expand Down Expand Up @@ -1195,9 +1196,6 @@ def extract_individual_synop(data: str) -> list:

# Start position is -1 if AAXX is not present in the message
if start_position == -1:
# LOGGER.error(
# "Invalid SYNOP message: AAXX could not be found."
# )
raise ValueError(
"Invalid SYNOP message: AAXX could not be found."
)
Expand Down Expand Up @@ -1255,11 +1253,9 @@ def transform(data: str, metadata: str, year: int,
:returns: iterator
"""
# Array to store error messages
error_msgs = []

# Make warning messages array global
# Make warning and error messages array global
global warning_msgs
global error_msgs

# ===================
# First parse metadata file
Expand All @@ -1286,7 +1282,7 @@ def transform(data: str, metadata: str, year: int,
tsi_mapping[tsi] = wsi
except Exception as e:
LOGGER.error(e)
error_msgs.append(e)
error_msgs.append(str(e))

fh.close()
# metadata = metadata_dict[wsi]
Expand Down Expand Up @@ -1468,7 +1464,7 @@ def transform(data: str, metadata: str, year: int,
mapping.update(s4_mappings[i] for i in range(4))
except Exception:
LOGGER.error(f"Missing station height for station {tsi}")
warning_msgs.append(
error_msgs.append(
f"Missing station height for station {tsi}")

# At this point we have a dictionary for the data, a
Expand All @@ -1492,6 +1488,7 @@ def transform(data: str, metadata: str, year: int,
except Exception as e:
LOGGER.error(e)
LOGGER.error("Error creating BUFRMessage")
error_msgs.append(str(e))
error_msgs.append("Error creating BUFRMessage")
conversion_success[tsi] = False

Expand All @@ -1503,6 +1500,7 @@ def transform(data: str, metadata: str, year: int,
except Exception as e:
LOGGER.error(e)
LOGGER.error("Error parsing message")
error_msgs.append(str(e))
error_msgs.append("Error parsing message")
conversion_success[tsi] = False

Expand Down Expand Up @@ -1538,6 +1536,7 @@ def transform(data: str, metadata: str, year: int,
LOGGER.error("Error encoding BUFR, null returned")
error_msgs.append("Error encoding BUFR, null returned")
LOGGER.error(e)
error_msgs.append(str(e))
result["bufr4"] = None
status = {
"code": FAILED,
Expand Down Expand Up @@ -1576,8 +1575,9 @@ def transform(data: str, metadata: str, year: int,
# now yield result back to caller
yield result

# Reset warning messages array for next iteration
# Reset warning and error messages array for next iteration
warning_msgs = []
error_msgs = []

# Output conversion status to user
if conversion_success[tsi]:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_synop2bufr.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ def test_bufr_307080(multiple_reports_307080, metadata_string):
for item in result:
msgs[item['_meta']['id']] = item
# Test the md5 keys
assert msgs['WIGOS_0-20000-0-15015_20220321T120000']['_meta']['properties']['md5'] == '603e1c2c25591a8d4213f339a1ce3b52' # noqa
assert msgs['WIGOS_0-20000-0-15020_20220321T120000']['_meta']['properties']['md5'] == '320ad7f1c3f7940a3059ca04dbb6d74a' # noqa
assert msgs['WIGOS_0-20000-0-15090_20220321T120000']['_meta']['properties']['md5'] == '3215ebdc66707c46458d2bbacb49427e' # noqa
assert msgs['WIGOS_0-20000-0-15015_20220321T120000']['_meta']['properties']['md5'] == 'f1595e9f82880b650de227fa007eb770' # noqa
assert msgs['WIGOS_0-20000-0-15020_20220321T120000']['_meta']['properties']['md5'] == '21cd8741f8615cc7b0df70060c3a98ff' # noqa
assert msgs['WIGOS_0-20000-0-15090_20220321T120000']['_meta']['properties']['md5'] == 'f0b736dba245b34985f757b0597e3d54' # noqa

# Test the bufr template used for all the reports
# (they should be the same for every report)
Expand Down

0 comments on commit b3c9aa3

Please sign in to comment.