def test_mcdparser(dbcursor): """ Test Parsing of MCD Product """ prod = parser(get_test_file("MCD_MPD/SWOMCD.txt")) assert abs(prod.geometry.area - 4.302) < 0.001 assert prod.discussion_num == 1525 assert prod.attn_wfo[2] == "DLH" ans = "PORTIONS OF NRN WI AND THE UPPER PENINSULA OF MI" assert prod.areas_affected == ans # With probability this time prod = parser(get_test_file("MCD_MPD/SWOMCDprob.txt")) assert abs(prod.geometry.area - 2.444) < 0.001 assert prod.watch_prob == 20 jmsg = prod.get_jabbers("http://localhost") ans = ("<p>Storm Prediction Center issues " '<a href="https://www.spc.noaa.gov/' 'products/md/2013/md1678.html">Mesoscale Discussion #1678</a> ' "concerning SEVERE POTENTIAL [watch probability: 20%] " '(<a href="http://localhost' '?pid=201308091725-KWNS-ACUS11-SWOMCD">View text</a>)</p>') assert jmsg[0][1] == ans ans = ("Storm Prediction Center issues Mesoscale Discussion #1678 " "concerning SEVERE POTENTIAL [watch probability: 20%] " "https://www.spc.noaa.gov/products/md/2013/md1678.html") assert jmsg[0][0] == ans ans = utc(2013, 8, 9, 17, 25) assert prod.sts == ans ans = utc(2013, 8, 9, 19, 30) assert prod.ets == ans prod.database_save(dbcursor)
def test_140820_badtimestamp(self): """ Check our invalid timestamp exception and how it is written """ try: parser(get_file('RWSGTF_badtime.txt')) except Exception, msg: # Note to self, unsure how this even works :) self.assertEquals(msg[1], ( "Invalid timestamp " "[130 PM MDT WED TUE 19 2014] found in product " "[NZUS01 KTFX RWSGTF] header"))
def test_01(self): """LSR.txt process a valid LSR without blemish """ utcnow = utc(2013, 7, 23, 23, 54) prod = parser(get_file("LSR.txt"), utcnow=utcnow) self.assertEqual(len(prod.lsrs), 58) self.assertAlmostEqual(prod.lsrs[57].magnitude_f, 73, 0) self.assertEqual(prod.lsrs[57].county, "MARION") self.assertEqual(prod.lsrs[57].state, "IA") self.assertAlmostEqual(prod.lsrs[57].get_lon(), -93.11, 2) self.assertAlmostEqual(prod.lsrs[57].get_lat(), 41.3, 1) self.assertEqual(prod.is_summary(), True) self.assertEqual(prod.lsrs[57].wfo, 'DMX') answer = utc(2013, 7, 23, 3, 55) self.assertEqual(prod.lsrs[57].valid, answer) j = prod.get_jabbers('http://iem.local/') self.assertEqual(j[57][0], ( "Knoxville Airport [Marion Co, IA] AWOS reports NON-TSTM WND " "GST of M73 MPH at 22 Jul, 10:55 PM CDT -- HEAT BURST. " "TEMPERATURE ROSE FROM 70 TO 84 IN 15 MINUTES AND DEW POINT " "DROPPED FROM 63 TO 48 IN 10 MINUTES. " "http://iem.local/#DMX/201307230355/201307230355")) self.assertEqual(prod.lsrs[5].tweet(), ("At 4:45 PM, Dows " "[Wright Co, IA] LAW ENFORCEMENT " "reports TSTM WND DMG #DMX"))
def test_170324_badformat(): """Look into exceptions""" utcnow = utc(2017, 3, 22, 2, 35) prod = parser(get_test_file("LSR/LSRPIH.txt"), utcnow=utcnow) prod.get_jabbers("http://iem.local/") assert len(prod.warnings) == 2 assert not prod.lsrs
def test_01(): """LSR.txt process a valid LSR without blemish """ utcnow = utc(2013, 7, 23, 23, 54) prod = parser(get_test_file("LSR/LSR.txt"), utcnow=utcnow) assert prod.lsrs[0].remark is None assert len(prod.lsrs) == 58 assert abs(prod.lsrs[57].magnitude_f - 73) < 0.01 assert prod.lsrs[57].county == "MARION" assert prod.lsrs[57].state == "IA" assert abs(prod.lsrs[57].get_lon() - -93.11) < 0.01 assert abs(prod.lsrs[57].get_lat() - 41.3) < 0.01 assert prod.is_summary() assert prod.lsrs[57].wfo == "DMX" answer = utc(2013, 7, 23, 3, 55) assert prod.lsrs[57].valid == answer j = prod.get_jabbers("http://iem.local/") assert j[57][0], ( "Knoxville Airport [Marion Co, IA] AWOS reports NON-TSTM WND " "GST of M73 MPH at 22 Jul, 10:55 PM CDT -- HEAT BURST. " "TEMPERATURE ROSE FROM 70 TO 84 IN 15 MINUTES AND DEW POINT " "DROPPED FROM 63 TO 48 IN 10 MINUTES. " "http://iem.local/#DMX/201307230355/201307230355") with pytest.deprecated_call(): prod.lsrs[5].tweet()
def test_01(): """LSR.txt process a valid LSR without blemish """ utcnow = utc(2013, 7, 23, 23, 54) prod = parser(get_test_file("LSR.txt"), utcnow=utcnow) assert len(prod.lsrs) == 58 assert abs(prod.lsrs[57].magnitude_f - 73) < 0.01 assert prod.lsrs[57].county == "MARION" assert prod.lsrs[57].state == "IA" assert abs(prod.lsrs[57].get_lon() - -93.11) < 0.01 assert abs(prod.lsrs[57].get_lat() - 41.3) < 0.01 assert prod.is_summary() assert prod.lsrs[57].wfo == 'DMX' answer = utc(2013, 7, 23, 3, 55) assert prod.lsrs[57].valid == answer j = prod.get_jabbers('http://iem.local/') assert j[57][0], ( "Knoxville Airport [Marion Co, IA] AWOS reports NON-TSTM WND " "GST of M73 MPH at 22 Jul, 10:55 PM CDT -- HEAT BURST. " "TEMPERATURE ROSE FROM 70 TO 84 IN 15 MINUTES AND DEW POINT " "DROPPED FROM 63 TO 48 IN 10 MINUTES. " "http://iem.local/#DMX/201307230355/201307230355") ans = ( "At 4:45 PM CDT, Dows [Wright Co, IA] LAW ENFORCEMENT " "reports TSTM WND DMG. DELAYED REPORT. LARGE TREE " "BRANCH DOWN IN TOWN THAT TOOK OUT A POWER LINE " "AND BLOCKING PART OF A ROAD." ) assert prod.lsrs[5].tweet() == ans
def test_170324_badformat(): """Look into exceptions""" utcnow = utc(2017, 3, 22, 2, 35) prod = parser(get_test_file('LSRPIH.txt'), utcnow=utcnow) prod.get_jabbers('http://iem.local/') assert len(prod.warnings) == 2 assert not prod.lsrs
def preprocessor(txn, text): """ Protect the realprocessor """ prod = parser(text) if len(prod.data) == 0: return for data in prod.data: realprocessor(txn, prod, data) send_tweet(prod)
def test_160904_resent(): """Is this product a correction?""" prod = parser(get_test_file("TCVAKQ.txt")) jmsgs = prod.get_jabbers("http://localhost") ans = ("AKQ issues Tropical Watch/Warning Local Statement (TCV) " "at Sep 2, 11:55 AM EDT ...TROPICAL STORM WARNING IN EFFECT... " "http://localhost?pid=201609021555-KAKQ-WTUS81-TCVAKQ") assert jmsgs[0][2]["twitter"] == ans
def test_171026_mixedlsr(): """LSRBYZ has mixed case, see what we can do""" utcnow = utc(2017, 10, 29, 19, 18) prod = parser(get_test_file("mIxEd_CaSe/LSRBYZ.txt"), utcnow=utcnow) j = prod.get_jabbers("http://iem.local/") assert j[0][2]["twitter"] == ( "[Delayed Report] On Oct 26, at 1:00 AM MDT, 3 SSW Luther " "[Carbon Co, MT] Mesonet reports Snow of 1.00 inch " "http://iem.local/#BYZ/201710260700/201710260700")
def test_160418_hwospn(self): """Make sure a spanish HWO does not trip us up...""" utcnow = utc(2016, 4, 18, 10, 10) prod = parser(get_file('HWOSPN.txt'), utcnow=utcnow) j = prod.get_jabbers('http://localhost', 'http://localhost') self.assertEquals(j[0][0], ("JSJ issues Hazardous Weather Outlook (HWO) " "http://localhost?" "pid=201604181018-TJSJ-FLCA42-HWOSPN"))
def test_exceptions(): """Test that various things lead to exceptions.""" orig = get_test_file("MCD_MPD/SWOMCD.txt") with pytest.raises(MCDException): parser(orig.replace("LAT...LON", "BLAH")) # See if -40 logic works parser(orig.replace("44738786", "44733786")) prod = parser(orig.replace("CONCERNING", "BLAH")) assert prod.concerning is None prod = parser(orig.replace("VALID", "BLAH")) assert prod.warnings with pytest.raises(MCDException): parser(orig.replace("DISCUSSION", "BLAH")) with pytest.raises(MCDException): parser(orig.replace("ATTN...WFO", "BLAH"))
def test_170116_mixedlsr(): """LSRBOU has mixed case, see what we can do""" utcnow = utc(2016, 11, 29, 22, 00) prod = parser(get_test_file("mIxEd_CaSe/LSRBOU.txt"), utcnow=utcnow) j = prod.get_jabbers("http://iem.local/") assert j[0][2]["twitter"] == ( "At 11:00 AM MST, Akron [Washington Co, CO] ASOS reports " "High Wind of M63 MPH " "http://iem.local/#BOU/201611291800/201611291800")
def test_160418_hwospn(): """Make sure a spanish HWO does not trip us up...""" utcnow = utc(2016, 4, 18, 10, 10) prod = parser(get_test_file("HWOSPN.txt"), utcnow=utcnow) j = prod.get_jabbers("http://localhost", "http://localhost") ans = ("JSJ issues Hazardous Weather Outlook (HWO) " "at Apr 18, 10:18 UTC http://localhost?" "pid=201604181018-TJSJ-FLCA42-HWOSPN") assert j[0][0] == ans
def test_spacewx(): """See if we can parse a space weather product """ utcnow = utc(2014, 5, 10) prod = parser(get_test_file("SPACEWX.txt"), utcnow=utcnow) j = prod.get_jabbers("http://localhost/") ans = ("Space Weather Prediction Center issues " "CANCEL WATCH: Geomagnetic Storm Category G3 Predicted " "http://localhost/?pid=201405101416-KWNP-WOXX22-WATA50") assert j[0][0] == ans
def test_171026_mixedlsr(): """LSRBYZ has mixed case, see what we can do""" utcnow = utc(2017, 10, 29, 19, 18) prod = parser(get_test_file('mIxEd_CaSe/LSRBYZ.txt'), utcnow=utcnow) j = prod.get_jabbers('http://iem.local/') assert j[0][2]['twitter'] == ( "At 1:00 AM MDT, 3 SSW Luther [Carbon Co, MT] Mesonet " "reports Snow of 1.00 inch " "http://iem.local/#BYZ/201710260700/201710260700")
def test_170324_ampersand(): """LSRs with ampersands may cause trouble""" utcnow = utc(2015, 12, 29, 18, 23) prod = parser(get_test_file("LSR/LSRBOXamp.txt"), utcnow=utcnow) j = prod.get_jabbers("http://iem.local/") ans = ("Lunenberg [Worcester Co, MA] HAM RADIO reports SNOW of 2.00 INCH " "at 11:36 AM EST -- HAM RADIO AND THIS DARYL ADDED & and < " "and > http://iem.local/#BOX/201512291636/201512291636") assert j[0][0] == ans
def test_170116_mixedlsr(): """LSRBOU has mixed case, see what we can do""" utcnow = utc(2016, 11, 29, 22, 00) prod = parser(get_test_file('mIxEd_CaSe/LSRBOU.txt'), utcnow=utcnow) j = prod.get_jabbers('http://iem.local/') assert j[0][2]['twitter'] == ( "At 11:00 AM MST, Akron [Washington Co, CO] ASOS reports " "High Wind of M63 MPH " "http://iem.local/#BOU/201611291800/201611291800")
def test_160904_resent(): """Is this product a correction?""" prod = parser(get_test_file("TCVAKQ.txt")) jmsgs = prod.get_jabbers('http://localhost') ans = ( 'AKQ issues TCV (TCV) at Sep 2, 11:55 AM EDT ' '...TROPICAL STORM WARNING IN EFFECT... ' 'http://localhost?pid=201609021555-KAKQ-WTUS81-TCVAKQ' ) assert jmsgs[0][2]['twitter'] == ans
def test_jabber_lsrtime(): """Make sure delayed LSRs have proper dates associated with them""" utcnow = utc(2014, 6, 6, 16) prod = parser(get_test_file("LSR/LSRFSD.txt"), utcnow=utcnow) j = prod.get_jabbers("http://iem.local") ans = ("<p>[Delayed Report] 2 SSE Harrisburg [Lincoln Co, SD] " 'TRAINED SPOTTER <a href="http://iem.local#FSD/201406052040/' '201406052040">reports TORNADO</a> at 5 Jun, 3:40 PM CDT -- ' "ON GROUND ALONG HIGHWAY 11 NORTH OF 275TH ST</p>") assert j[0][1] == ans
def test_spacewx(self): ''' See if we can parse a space weather product ''' utcnow = datetime.datetime(2014, 5, 10) utcnow = utcnow.replace(tzinfo=pytz.timezone("UTC")) prod = parser(get_file('SPACEWX.txt'), utcnow=utcnow) j = prod.get_jabbers('http://localhost/') self.assertEqual(j[0][0], ( 'Space Weather Prediction Center issues ' 'CANCEL WATCH: Geomagnetic Storm Category G3 Predicted ' 'http://localhost/?pid=201405101416-KWNP-WOXX22-WATA50'))
def test_160418_hwospn(): """Make sure a spanish HWO does not trip us up...""" utcnow = utc(2016, 4, 18, 10, 10) prod = parser(get_test_file('HWOSPN.txt'), utcnow=utcnow) j = prod.get_jabbers('http://localhost', 'http://localhost') ans = ( "JSJ issues Hazardous Weather Outlook (HWO) " "at Apr 18, 10:18 UTC http://localhost?" "pid=201604181018-TJSJ-FLCA42-HWOSPN" ) assert j[0][0] == ans
def test_spacewx(): """See if we can parse a space weather product """ utcnow = utc(2014, 5, 10) prod = parser(get_test_file('SPACEWX.txt'), utcnow=utcnow) j = prod.get_jabbers('http://localhost/') ans = ( 'Space Weather Prediction Center issues ' 'CANCEL WATCH: Geomagnetic Storm Category G3 Predicted ' 'http://localhost/?pid=201405101416-KWNP-WOXX22-WATA50' ) assert j[0][0] == ans
def test_tcp(self): """ See what we can do with TCP """ prod = parser(get_file('TCPAT1.txt')) j = prod.get_jabbers('http://localhost', 'http://localhost') self.assertEquals(j[0][0], ( 'National Hurricance Center issues ' 'ADVISORY 19 for POST-TROPICAL CYCLONE ARTHUR ' 'http://localhost?pid=201407051500-KNHC-WTNT31-TCPAT1')) self.assertEquals(j[0][2]['twitter'], ( 'Post-Tropical Cyclone ' '#Arthur ADVISORY 19 issued. http://go.usa.gov/W3H'))
def test_mcdparser(self): ''' Test Parsing of MCD Product ''' prod = parser(get_file('SWOMCD.txt')) self.assertAlmostEqual(prod.geometry.area, 4.302, 3) self.assertEqual(prod.discussion_num, 1525) self.assertEqual(prod.attn_wfo[2], 'DLH') self.assertEqual(prod.areas_affected, ("PORTIONS OF NRN WI AND " "THE UPPER PENINSULA OF MI")) # With probability this time prod = parser(get_file('SWOMCDprob.txt')) self.assertAlmostEqual(prod.geometry.area, 2.444, 3) self.assertEqual(prod.watch_prob, 20) self.assertEqual(prod.get_jabbers('http://localhost')[0][1], ( '<p>Storm Prediction Center issues ' '<a href="http://www.spc.noaa.gov/' 'products/md/2013/md1678.html">Mesoscale Discussion #1678</a> ' '[watch probability: 20%] (<a href="http://localhost' '?pid=201308091725-KWNS-ACUS11-SWOMCD">View text</a>)</p>'))
def test_180917_issue63_tweet_length(): """Make sure this tweet text is not too long!""" utcnow = utc(2018, 9, 15, 11, 56) prod = parser(get_test_file("LSR/LSRCRP.txt"), utcnow=utcnow) j = prod.get_jabbers("http://iem.local/") assert j[0][2]["twitter"] == ( "At 6:45 AM CDT, 2 NNE Odem [San Patricio Co, TX] DEPT OF HIGHWAYS " "reports FLOOD. ROAD CLOSURE FM 1944 BETWEEN U.S. HIGHWAY 77 AND " "SODVILLE ROAD (TEXAS DEPARTMENT OF TRANSPORATION. DRIVETEXAS.ORG.) " "LATITUDE/LONGITUDE MARKS APPROXIMATE POSITION OF FM 194... " "http://iem.local/#CRP/201809151145/201809151145")
def test_180705_iembot_issue9(): """LSRBOU has mixed case, see what we can do""" utcnow = utc(2018, 7, 4, 22, 11) prod = parser(get_test_file('LSRDMX.txt'), utcnow=utcnow) j = prod.get_jabbers('http://iem.local/') assert j[0][2]['twitter'] == ( 'At 1:30 PM CDT, 1 WNW Lake Mills [Winnebago Co, IA] TRAINED SPOTTER ' 'reports TSTM WND GST of E61 MPH. SPOTTER MEASURED 61 MPH WIND GUST. ' 'HIS CAR DOOR WAS ALSO CAUGHT BY THE WIND WHEN HE WAS OPENING ' 'THE DOOR, PUSHING THE DOOR INTO HIS FACE. THIS CONTACT' '... http://iem.local/#DMX/201807041830/201807041830')
def test_180917_issue63_tweet_length(): """Make sure this tweet text is not too long!""" utcnow = utc(2018, 9, 15, 11, 56) prod = parser(get_test_file('LSRCRP.txt'), utcnow=utcnow) j = prod.get_jabbers('http://iem.local/') assert j[0][2]['twitter'] == ( "At 6:45 AM CDT, 2 NNE Odem [San Patricio Co, TX] DEPT OF HIGHWAYS " "reports FLOOD. ROAD CLOSURE FM 1944 BETWEEN U.S. HIGHWAY 77 AND " "SODVILLE ROAD (TEXAS DEPARTMENT OF TRANSPORATION. DRIVETEXAS.ORG.) " "LATITUDE/LONGITUDE MARKS APPROXIMATE POSITION OF FM 194... " "http://iem.local/#CRP/201809151145/201809151145")
def test_180705_iembot_issue9(): """LSRBOU has mixed case, see what we can do""" utcnow = utc(2018, 7, 4, 22, 11) prod = parser(get_test_file("LSR/LSRDMX.txt"), utcnow=utcnow) j = prod.get_jabbers("http://iem.local/") assert j[0][2]["twitter"] == ( "At 1:30 PM CDT, 1 WNW Lake Mills [Winnebago Co, IA] TRAINED SPOTTER " "reports TSTM WND GST of E61 MPH. SPOTTER MEASURED 61 MPH WIND GUST. " "HIS CAR DOOR WAS ALSO CAUGHT BY THE WIND WHEN HE WAS OPENING " "THE DOOR, PUSHING THE DOOR INTO HIS FACE. THIS CONTACT" "... http://iem.local/#DMX/201807041830/201807041830")
def test_jabber_lsrtime(self): ''' Make sure delayed LSRs have proper dates associated with them''' utcnow = datetime.datetime(2014, 6, 6, 16) utcnow = utcnow.replace(tzinfo=pytz.timezone("UTC")) prod = parser(get_file('LSRFSD.txt'), utcnow=utcnow) j = prod.get_jabbers('http://iem.local') self.assertEqual(j[0][1], ( '<p>2 SSE Harrisburg [Lincoln Co, SD] ' 'TRAINED SPOTTER <a href="http://iem.local#FSD/201406052040/' '201406052040">reports TORNADO</a> at 5 Jun, 3:40 PM CDT -- ' 'ON GROUND ALONG HIGHWAY 11 NORTH OF 275TH ST</p>'))
def test_170926_nodbinsert(dbcursor): """This product never hit the database for some reason?""" prod = parser(get_test_file("MCD_MPD/SWOMCD_2010.txt")) prod.database_save(dbcursor) dbcursor.execute( """ SELECT * from mcd where product_id = %s """, (prod.get_product_id(), ), ) assert dbcursor.rowcount == 1
def test_170324_ampersand(): """LSRs with ampersands may cause trouble""" utcnow = utc(2015, 12, 29, 18, 23) prod = parser(get_test_file('LSRBOXamp.txt'), utcnow=utcnow) j = prod.get_jabbers('http://iem.local/') ans = ( "Lunenberg [Worcester Co, MA] HAM RADIO reports SNOW of 2.00 INCH " "at 11:36 AM EST -- HAM RADIO AND THIS DARYL ADDED & and < " "and > http://iem.local/#BOX/201512291636/201512291636" ) assert j[0][0] == ans
def test_jabber_lsrtime(): """Make sure delayed LSRs have proper dates associated with them""" utcnow = utc(2014, 6, 6, 16) prod = parser(get_test_file('LSRFSD.txt'), utcnow=utcnow) j = prod.get_jabbers('http://iem.local') ans = ( '<p>2 SSE Harrisburg [Lincoln Co, SD] ' 'TRAINED SPOTTER <a href="http://iem.local#FSD/201406052040/' '201406052040">reports TORNADO</a> at 5 Jun, 3:40 PM CDT -- ' 'ON GROUND ALONG HIGHWAY 11 NORTH OF 275TH ST</p>' ) assert j[0][1] == ans
def test_tcp(): """ See what we can do with TCP """ prod = parser(get_test_file("TCPAT1.txt")) j = prod.get_jabbers("http://localhost", "http://localhost") ans = ("National Hurricane Center issues " "ADVISORY 19 for POST-TROPICAL CYCLONE ARTHUR " "http://localhost?pid=201407051500-KNHC-WTNT31-TCPAT1") assert j[0][0] == ans ans = ("Post-Tropical Cyclone " "#Arthur ADVISORY 19 issued. Strong winds and heavy rains to " "continue over portions of southeastern canada through tonight " "http://go.usa.gov/W3H") assert j[0][2]["twitter"] == ans
def test_180710_issue58(): """Crazy MST during MDT""" utcnow = utc(2018, 7, 9, 22, 59) prod = parser(get_test_file('LSRPSR.txt'), utcnow=utcnow) j = prod.get_jabbers('http://iem.local/') ans = ('At 3:57 PM MST, 5 WNW Florence [Pinal Co, AZ] TRAINED SPOTTER ' 'reports FLASH FLOOD. STREET FLOODING WITH WATER OVER THE CURBS ' 'IN THE MERRILL RANCH DEVELOPMENT OF FLORENCE. ' 'http://iem.local/#PSR/201807092257/201807092257') assert j[0][2]['twitter'] == ans ans = ('5 WNW Florence [Pinal Co, AZ] TRAINED SPOTTER reports FLASH FLOOD ' 'at 3:57 PM MST -- STREET FLOODING WITH WATER OVER THE CURBS IN ' 'THE MERRILL RANCH DEVELOPMENT OF FLORENCE. ' 'http://iem.local/#PSR/201807092257/201807092257') assert j[0][0] == ans
def test_180710_issue58(): """Crazy MST during MDT""" utcnow = utc(2018, 7, 9, 22, 59) prod = parser(get_test_file("LSR/LSRPSR.txt"), utcnow=utcnow) j = prod.get_jabbers("http://iem.local/") ans = ("At 3:57 PM MST, 5 WNW Florence [Pinal Co, AZ] TRAINED SPOTTER " "reports FLASH FLOOD. STREET FLOODING WITH WATER OVER THE CURBS " "IN THE MERRILL RANCH DEVELOPMENT OF FLORENCE. " "http://iem.local/#PSR/201807092257/201807092257") assert j[0][2]["twitter"] == ans ans = ("5 WNW Florence [Pinal Co, AZ] TRAINED SPOTTER reports FLASH FLOOD " "at 3:57 PM MST -- STREET FLOODING WITH WATER OVER THE CURBS IN " "THE MERRILL RANCH DEVELOPMENT OF FLORENCE. " "http://iem.local/#PSR/201807092257/201807092257") assert j[0][0] == ans
def test_issue163(dbcursor): """Test parsing of the concerning tag.""" prod = parser(get_test_file("MCD_MPD/SWOMCDconcerning.txt")) prod.database_save(dbcursor) dbcursor.execute( "SELECT concerning from mcd where product_id = %s", (prod.get_product_id(), ), ) ans = "Severe Thunderstorm Watch 60" assert dbcursor.fetchone()[0] == ans # Exercise that the remove worked. prod.database_save(dbcursor) dbcursor.execute( "SELECT count(*) from mcd where product_id = %s", (prod.get_product_id(), ), ) assert dbcursor.fetchone()[0] == 1
def test_mpd_mcdparser(self): ''' The mcdparser can do WPC's MPD as well, test it ''' prod = parser(get_file('MPD.txt')) self.assertAlmostEqual(prod.geometry.area, 4.657, 3) self.assertEqual(prod.attn_wfo, ['PHI', 'AKQ', 'CTP', 'LWX']) self.assertEqual(prod.attn_rfc, ['MARFC']) self.assertEqual(prod.tweet(), ( '#WPC issues MPD 98: NRN VA...D.C' '....CENTRAL MD INTO SERN PA ' 'http://www.wpc.ncep.noaa.gov/metwatch/metwatch_mpd_multi.php' '?md=98&yr=2013')) # self.assertEqual(prod.find_cwsus(self.txn), ['ZDC', 'ZNY']) self.assertEqual(prod.get_jabbers('http://localhost')[0][0], ( 'Weather Prediction Center issues ' 'Mesoscale Precipitation Discussion #98' ' http://www.wpc.ncep.noaa.gov/metwatch/metwatch_mpd_multi.php' '?md=98&yr=2013'))
def test_mpd_mcdparser(dbcursor): """ The mcdparser can do WPC's MPD as well, test it """ prod = parser(get_test_file("MCD_MPD/MPD.txt")) assert abs(prod.geometry.area - 4.657) < 0.001 assert prod.attn_wfo == ["PHI", "AKQ", "CTP", "LWX"] assert prod.attn_rfc == ["MARFC"] ans = ("#WPC issues MPD 98 concerning HEAVY RAINFALL: NRN VA...D.C" "....CENTRAL MD INTO SERN PA " "https://www.wpc.ncep.noaa.gov/metwatch/metwatch_mpd_multi.php" "?md=98&yr=2013") assert prod.tweet() == ans ans = ("Weather Prediction Center issues " "Mesoscale Precipitation Discussion #98 concerning HEAVY RAINFALL" " https://www.wpc.ncep.noaa.gov/metwatch/metwatch_mpd_multi.php" "?md=98&yr=2013") assert prod.get_jabbers("http://localhost")[0][0] == ans prod.database_save(dbcursor)
def test_150422_tornadomag(self): """LSRTAE see what we do with tornado magitnudes""" utcnow = utc(2015, 4, 22, 15, 20) prod = parser(get_file('LSRTAE.txt'), utcnow=utcnow) j = prod.get_jabbers('http://iem.local/') self.assertEqual(j[0][1], ( '<p>4 W Bruce [Walton Co, FL] NWS EMPLOYEE ' '<a href="http://iem.local/#TAE/201504191322/201504191322">' 'reports TORNADO of EF0</a> at 19 Apr, 9:22 AM EDT -- ' 'SHORT EF0 TORNADO PATH CONFIRMED BY NWS DUAL POL RADAR DEBRIS ' 'SIGNATURE IN A RURAL AREA WEST OF BRUCE. DAMAGE LIKELY CONFINED ' 'TO TREES. ESTIMATED DURATION 3 MINUTES. PATH LENGTH ' 'APPROXIMATELY 1 MILE.</p>')) self.assertEqual(j[0][2]['twitter'], ( 'At 9:22 AM, 4 W Bruce [Walton Co, FL] NWS EMPLOYEE reports ' 'TORNADO of EF0 #TAE ' 'http://iem.local/#TAE/201504191322/201504191322'))
def test_150422_tornadomag(): """LSRTAE see what we do with tornado magitnudes""" utcnow = utc(2015, 4, 22, 15, 20) prod = parser(get_test_file("LSR/LSRTAE.txt"), utcnow=utcnow) j = prod.get_jabbers("http://iem.local/") assert j[0][1] == ( "<p>[Delayed Report] 4 W Bruce [Walton Co, FL] NWS EMPLOYEE " '<a href="http://iem.local/#TAE/201504191322/201504191322">' "reports TORNADO of EF0</a> at 19 Apr, 9:22 AM EDT -- " "SHORT EF0 TORNADO PATH CONFIRMED BY NWS DUAL POL RADAR DEBRIS " "SIGNATURE IN A RURAL AREA WEST OF BRUCE. DAMAGE LIKELY CONFINED " "TO TREES. ESTIMATED DURATION 3 MINUTES. PATH LENGTH " "APPROXIMATELY 1 MILE.</p>") assert j[0][2]["twitter"] == ( "[Delayed Report] On Apr 19, at 9:22 AM EDT, " "4 W Bruce [Walton Co, FL] NWS EMPLOYEE reports " "TORNADO of EF0. SHORT EF0 TORNADO PATH CONFIRMED BY NWS DUAL " "POL RADAR DEBRIS SIGNATURE IN A RURAL AREA WEST OF BRUCE. " "DAMAGE LIKELY CONFINED TO TREES. ESTIMATED... " "http://iem.local/#TAE/201504191322/201504191322")
def test_151229_badgeo_lsr(): """Make sure we reject a bad Geometry LSR""" utcnow = utc(2015, 12, 29, 18, 23) prod = parser(get_test_file('LSRBOX.txt'), utcnow=utcnow) assert len(prod.warnings) == 1 assert not prod.lsrs
def test_140522_blowingdust(): """Make sure we can deal with invalid LSR type """ prod = parser(get_test_file("LSR/LSRTWC.txt")) assert not prod.lsrs
def test_201124_tab_in_afos(): """Test that we can deal with a tab in the AFOS ID.""" data = get_test_file("FFW/FFWGUM.txt").replace("FFWGUM", "FFWGUM\t") prod = parser(data) assert prod.afos == "FFWGUM"
def test_140522_blowingdust(self): ''' Make sure we can deal with invalid LSR type ''' prod = parser(get_file('LSRTWC.txt')) self.assertEqual(len(prod.lsrs), 1) self.assertEqual(prod.lsrs[0].get_dbtype(), None)
def test_160618_chst_tz(self): """Product has timezone of ChST, do we support it?""" prod = parser(get_file('AFDPQ.txt')) self.assertEquals(prod.valid, utc(2016, 6, 18, 20, 27))
def test_150202_hwo(): """HWORNK emitted a poorly worded error message""" prod = parser(get_test_file('HWORNK.txt')) with pytest.raises(Exception): prod.get_jabbers('http://localhost', 'http://localhost')
def test_170403_badtime(): """Handle when a colon is added to a timestamp""" prod = parser(get_test_file("FLWBOI.txt")) prod.get_jabbers("http://localhost", "http://localhost") ans = utc(2017, 4, 2, 2, 30) assert prod.valid == ans
def test_181207_issue74_guam(): """Guam's longitudes are east, not west like code assumes.""" prod = parser(get_test_file("FFW/FFWGUM.txt")) ans = "SRID=4326;MULTIPOLYGON (((145.800000 15.160000, 145.740000" assert prod.segments[0].giswkt.startswith(ans)
def test_150202_hwo(): """HWORNK emitted a poorly worded error message""" prod = parser(get_test_file("HWORNK.txt")) with pytest.raises(Exception): prod.get_jabbers("http://localhost", "http://localhost")
def test_151229_badgeo_lsr(): """Make sure we reject a bad Geometry LSR""" utcnow = utc(2015, 12, 29, 18, 23) prod = parser(get_test_file("LSR/LSRBOX.txt"), utcnow=utcnow) assert len(prod.warnings) == 1 assert not prod.lsrs
def test_160618_chst_tz(): """Product has timezone of ChST, do we support it?""" prod = parser(get_test_file("AFDPQ.txt")) assert prod.valid == utc(2016, 6, 18, 19, 27)
def test_170207_mixedhwo(): """Check our parsing of mixed case HWO""" prod = parser(get_test_file("mIxEd_CaSe/HWOLOT.txt")) j = prod.get_jabbers("http://iem.local/") assert not prod.warnings assert len(j[0]) == 3
def test_181207_issue74_guam(): """Guam's longitudes are east, not west like code assumes.""" prod = parser(get_test_file('FFW/FFWGUM.txt')) ans = "SRID=4326;MULTIPOLYGON (((145.800000 15.160000, 145.740000" assert prod.segments[0].giswkt.startswith(ans)
def test_150202_hwo(self): """HWORNK emitted a poorly worded error message""" prod = parser(get_file('HWORNK.txt')) self.assertRaises(Exception, prod.get_jabbers, 'http://localhost', 'http://localhost')
def test_140820_badtimestamp(): """ Check our invalid timestamp exception and how it is written """ with pytest.raises(Exception): parser(get_test_file("RWSGTF_badtime.txt"))
def test_140820_badtimestamp(): """ Check our invalid timestamp exception and how it is written """ with pytest.raises(Exception): parser(get_test_file('RWSGTF_badtime.txt'))
def test_170419_tcp_mixedcase(): """Mixed case TCP1""" prod = parser(get_test_file("TCPAT1_mixedcase.txt")) j = prod.get_jabbers("") assert j
def test_datetime_coverage(): """Test products that cross the first of the month.""" assert parser(get_test_file("MCD_MPD/SWOMCD_sep1.txt")) is not None
def test_140522_blowingdust(): """Make sure we can deal with invalid LSR type """ prod = parser(get_test_file('LSRTWC.txt')) assert not prod.lsrs