def test_ugc_error130214(self): """ Check parsing of SPSJAX """ tp = product.TextProduct(get_file('SPSJAX.txt')) self.assertEqual(tp.segments[0].ugcs, [ugc.UGC("FL", "Z", 23), ugc.UGC("FL", "Z", 25), ugc.UGC("FL", "Z", 30), ugc.UGC("FL", "Z", 31), ugc.UGC("FL", "Z", 32) ])
def test_ugc_error130214(): """ Check parsing of SPSJAX """ tp = product.TextProduct(get_test_file("SPSJAX.txt")) assert tp.segments[0].ugcs, [ ugc.UGC("FL", "Z", 23), ugc.UGC("FL", "Z", 25), ugc.UGC("FL", "Z", 30), ugc.UGC("FL", "Z", 31), ugc.UGC("FL", "Z", 32), ]
def test_totextstr(): """ See if we can generate a proper string from a UGCS """ ugcs = [ ugc.UGC("DC", "Z", "001"), ugc.UGC("IA", "C", "001"), ugc.UGC("IA", "C", "002"), ] assert ( ugc.ugcs_to_text(ugcs) == "((DCZ001)) [DC] and ((IAC001)), ((IAC002)) [IA]" )
def load_ugc(txn): """ load ugc""" # Careful here not to load things from the future txn.execute(""" SELECT name, ugc, wfo from ugcs WHERE name IS NOT Null and begin_ts < now() and (end_ts is null or end_ts > now()) """) for row in txn.fetchall(): nm = (row["name"]).replace("\x92", " ").replace("\xc2", " ") wfos = re.findall(r"([A-Z][A-Z][A-Z])", row["wfo"]) ugc_dict[row["ugc"]] = ugc.UGC(row["ugc"][:2], row["ugc"][2], row["ugc"][3:], name=nm, wfos=wfos) log.msg("ugc_dict loaded %s entries" % (len(ugc_dict), )) sql = """ SELECT nwsli, river_name || ' ' || proximity || ' ' || name || ' ['||state||']' as rname from hvtec_nwsli """ txn.execute(sql) for row in txn.fetchall(): nm = row["rname"].replace("&", " and ") nwsli_dict[row["nwsli"]] = nwsli.NWSLI(row["nwsli"], name=nm) log.msg("nwsli_dict loaded %s entries" % (len(nwsli_dict), )) return None
def test_missed_ugc(): """Invalid encoded county string, check that NMC006 was not included""" text = ("NMC001-005>007-011-019-027-028-031-033-039-041-043-045-" "047-049-053-055-057-061-040300-") valid = utc(2018, 6, 4, 3, 0) (ugcs, expire) = ugc.parse(text, valid) assert expire == valid assert ugcs[3] != ugc.UGC("NM", "C", "006")
def test_str1(): """ check ugc.parse of STR1 parsing """ valid = utc(2008, 12, 17, 3, 0) (ugcs, expire) = ugc.parse(STR1, valid) expire_answer = valid.replace(hour=2) ugcs_answer = [ugc.UGC("DC", "Z", "001")] assert ugcs == ugcs_answer assert expire == expire_answer
def test_ugc_in_hwo(self): """ Parse UGC codes in a HWO """ tp = product.TextProduct(get_file('HWO.txt')) self.assertEqual(tp.segments[1].ugcs, [ugc.UGC("LM", "Z", 740), ugc.UGC("LM", "Z", 741), ugc.UGC("LM", "Z", 742), ugc.UGC("LM", "Z", 743), ugc.UGC("LM", "Z", 744), ugc.UGC("LM", "Z", 745) ])
def test_ugc_in_hwo(): """ Parse UGC codes in a HWO """ tp = product.TextProduct(get_test_file("HWO.txt")) assert tp.segments[1].ugcs == [ ugc.UGC("LM", "Z", 740), ugc.UGC("LM", "Z", 741), ugc.UGC("LM", "Z", 742), ugc.UGC("LM", "Z", 743), ugc.UGC("LM", "Z", 744), ugc.UGC("LM", "Z", 745), ]
def test_str2(): """ check ugc.parse of STR2 parsing """ valid = utc(2008, 12, 17, 3, 0) (ugcs, expire) = ugc.parse(STR2, valid) expire_answer = valid.replace(hour=2) ugcs_answer = [ ugc.UGC("DC", "Z", "001"), ugc.UGC("MD", "Z", "004"), ugc.UGC("MD", "Z", "005"), ugc.UGC("MD", "Z", "006"), ugc.UGC("MD", "Z", "007"), ugc.UGC("MD", "Z", "009"), ugc.UGC("MD", "Z", "010"), ugc.UGC("MD", "Z", "011"), ugc.UGC("MD", "Z", "013"), ugc.UGC("MD", "Z", "014"), ugc.UGC("MD", "Z", "016"), ugc.UGC("MD", "Z", "017"), ugc.UGC("MD", "Z", "018"), ugc.UGC("VA", "Z", "036"), ugc.UGC("VA", "Z", "037"), ugc.UGC("VA", "Z", "038"), ugc.UGC("VA", "Z", "039"), ugc.UGC("VA", "Z", "040"), ugc.UGC("VA", "Z", "041"), ugc.UGC("VA", "Z", "042"), ugc.UGC("VA", "Z", "050"), ugc.UGC("VA", "Z", "051"), ugc.UGC("VA", "Z", "052"), ugc.UGC("VA", "Z", "053"), ugc.UGC("VA", "Z", "054"), ugc.UGC("VA", "Z", "055"), ugc.UGC("VA", "Z", "056"), ugc.UGC("VA", "Z", "057"), ] assert ugcs == ugcs_answer assert expire == expire_answer
def test_louisana(): """Test that some specific logic works.""" ugcs = [ugc.UGC("LA", "C", i) for i in range(100)] res = ugc.ugcs_to_text(ugcs) ans = "100 parishes in [LA]" assert res == ans