Skip to content

Commit

Permalink
Merge pull request #1044 from MetPX/issue1036
Browse files Browse the repository at this point in the history
Issue1036 - Add unit tests for AM code
  • Loading branch information
andreleblanc11 authored May 15, 2024
2 parents ddb228c + 57f1f57 commit 9f61e90
Show file tree
Hide file tree
Showing 4 changed files with 373 additions and 5 deletions.
8 changes: 4 additions & 4 deletions sarracenia/bulletin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _verifyYear(self, bulletin_year):

return True

def verifyHeader(self, header):
def verifyHeader(self, header, charset):
"""Derived from Sundew -> https://github.com/MetPX/Sundew/blob/main/lib/bulletin.py#L601-L671.
Verifies the integrity of the bulletin header. Flag if there is an error in the header.
Called by the buildHeader method.
Expand Down Expand Up @@ -92,13 +92,13 @@ def verifyHeader(self, header):
return header, isProblem

# Verify BBB field(s) -> https://www.weather.gov/tg/headef. Remove it if it's corrupted.
if not tokens[3].isalpha() or len(tokens[3]) != 3 or tokens[3][0] not in ['C','A','R','P']:
if not tokens[3].isalpha() or len(tokens[3]) != 3 or tokens[3].decode(charset)[0] not in ['C','A','R','P']:
logger.info("Header normalized: fourth and later fields removed.")
del tokens[3:]
rebuild = 1

if len(tokens) == 5 and \
(not tokens[4].isalpha() or len(tokens[4]) != 3 or tokens[4][0] not in ['C','A','R','P']):
(not tokens[4].isalpha() or len(tokens[4]) != 3 or tokens[4].decode(charset)[0] not in ['C','A','R','P']):
logger.info("Header normalized: fifth and later fields removed")
del tokens[4:]
rebuild = 1
Expand Down Expand Up @@ -249,7 +249,7 @@ def getStation(self, data):
# Added to SR3
# The station needs to be alphanumeric, between 3 and 5 characters. If not, don't assign a station
if re.search('^[a-zA-Z0-9]{3,5}$', station) == None:
station = ''
station = None

return station

Expand Down
2 changes: 1 addition & 1 deletion sarracenia/flowcb/gather/am.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def correctContents(self, bulletin, bulletin_firstchars, lines, missing_ahl, bul
reconstruct = 1

# Check if the header is okay before proceeding to correcting rest of bulletin.
verified_header , isProblem = self.bulletinHandler.verifyHeader(lines[0])
verified_header , isProblem = self.bulletinHandler.verifyHeader(lines[0], charset)
if verified_header != lines[0]:
lines[0] = verified_header
reconstruct = 1
Expand Down
3 changes: 3 additions & 0 deletions sarracenia/flowcb/rename/raw2bulletin.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ def rename(self,msg,isProblem):

# with open(new_path, 'w') as f: f.write(data)

logger.error(f"New filename (for problem file): {new_file}")
elif stn_id == None:
new_file = header + "_" + BBB + "_" + '' + "_" + seq + "_PROBLEM"
logger.error(f"New filename (for problem file): {new_file}")
elif ddhhmm == '':
new_file = header + "_" + BBB + "_" + stn_id + "_" + seq
Expand Down
Loading

0 comments on commit 9f61e90

Please sign in to comment.