From: Michael Orlitzky Date: Wed, 24 Sep 2014 02:25:36 +0000 (-0400) Subject: Make and elements optional in TSN.XML.Weather. X-Git-Tag: 0.1.1~2 X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhtsn-import.git;a=commitdiff_plain;h=f49a8902b023ca0fb055fb6b90e0020a942c56b3 Make and elements optional in TSN.XML.Weather. Add a test case for the newly-optional elements and update a shelltest. Update the weatherxml dbschema diagram. --- diff --git a/doc/dbschema/weatherxml.png b/doc/dbschema/weatherxml.png index 9382d12..42c25b2 100644 Binary files a/doc/dbschema/weatherxml.png and b/doc/dbschema/weatherxml.png differ diff --git a/src/TSN/XML/Weather.hs b/src/TSN/XML/Weather.hs index c1ec2ef..e7c0e3c 100644 --- a/src/TSN/XML/Weather.hs +++ b/src/TSN/XML/Weather.hs @@ -101,7 +101,7 @@ dtd = "weatherxml.dtd" data WeatherForecastListingXml = WeatherForecastListingXml { xml_teams :: String, - xml_weather :: String } + xml_weather :: Maybe String } deriving (Eq, Show) @@ -114,7 +114,7 @@ data WeatherForecastListing = db_weather_forecasts_id :: DefaultKey WeatherForecast, db_league_name :: Maybe String, db_teams :: String, - db_weather :: String } + db_weather :: Maybe String } -- | We don't make 'WeatherForecastListingXml' an instance of @@ -247,7 +247,7 @@ data WeatherDetailedWeatherListingItem = db_away_team :: String, db_home_team :: String, db_weather_type :: Int, - db_description :: String, + db_description :: Maybe String, db_temp_adjust :: Maybe String, db_temperature :: Int } @@ -263,7 +263,7 @@ data WeatherDetailedWeatherListingItemXml = xml_away_team :: String, xml_home_team :: String, xml_weather_type :: Int, - xml_description :: String, + xml_description :: Maybe String, xml_temp_adjust :: Maybe String, xml_temperature :: Int } deriving (Eq, Show) @@ -506,8 +506,9 @@ pickle_listing = xpWrap (from_pair, to_pair) $ xpPair (xpElem "teams" xpText) - (xpElem "weather" xpText) + (xpElem "weather" (xpOption xpText)) where +-- from_pair (ts, Nothing) = WeatherForecastListingXml ts (Just "") from_pair = uncurry WeatherForecastListingXml to_pair WeatherForecastListingXml{..} = (xml_teams, xml_weather) @@ -554,7 +555,7 @@ pickle_item = (xpElem "AwayTeam" xpText) (xpElem "HomeTeam" xpText) (xpElem "WeatherType" xpInt) - (xpElem "Description" xpText) + (xpElem "Description" (xpOption xpText)) (xpElem "TempAdjust" (xpOption xpText)) (xpElem "Temperature" xpInt) where @@ -660,7 +661,9 @@ test_unpickle_succeeds = testGroup "unpickle tests" [ check "unpickling succeeds" "test/xml/weatherxml.xml", check "unpickling succeeds (detailed)" - "test/xml/weatherxml-detailed.xml" ] + "test/xml/weatherxml-detailed.xml", + check "unpickling succeeds (empty weather)" + "test/xml/weatherxml-empty-weather.xml"] where check desc path = testCase desc $ do actual <- unpickleable path pickle_message @@ -676,7 +679,9 @@ test_on_delete_cascade = testGroup "cascading delete tests" [ check "deleting weather deletes its children" "test/xml/weatherxml.xml", check "deleting weather deletes its children (detailed)" - "test/xml/weatherxml-detailed.xml" ] + "test/xml/weatherxml-detailed.xml", + check "deleting weather deletes its children (empty weather)" + "test/xml/weatherxml-empty-weather.xml"] where check desc path = testCase desc $ do weather <- unsafe_unpickle path pickle_message @@ -713,6 +718,9 @@ test_types_detected_correctly = check "test/xml/weatherxml-detailed.xml" "first type detected correctly (detailed)" True, + check "test/xml/weatherxml-empty-weather.xml" + "first type detected correctly (empty weather)" + True, check "test/xml/weatherxml-type2.xml" "second type detected correctly" False ] diff --git a/test/shell/import-duplicates.test b/test/shell/import-duplicates.test index 53ab0bd..10a4650 100644 --- a/test/shell/import-duplicates.test +++ b/test/shell/import-duplicates.test @@ -16,15 +16,15 @@ rm -f shelltest.sqlite3 # and a newsxml that aren't really supposed to import. find ./test/xml -maxdepth 1 -name '*.xml' | wc -l >>> -31 +32 >>>= 0 # Run the imports again; we should get complaints about the duplicate -# xml_file_ids. There are 2 errors for each violation, so we expect 2*27 +# xml_file_ids. There are 2 errors for each violation, so we expect 2*28 # occurrences of the string 'ERROR'. ./dist/build/htsn-import/htsn-import -c 'shelltest.sqlite3' test/xml/*.xml 2>&1 | grep ERROR | wc -l >>> -54 +56 >>>= 0 # Finally, clean up after ourselves. diff --git a/test/xml/weatherxml-empty-weather.xml b/test/xml/weatherxml-empty-weather.xml new file mode 100644 index 0000000..b42bb0f --- /dev/null +++ b/test/xml/weatherxml-empty-weather.xml @@ -0,0 +1 @@ + 21812233 AAW%BBWEATHER Weather MLB Major League Baseball Weather from The Sports Network Washington Nationals at Miami Marlins, 7:10 p.m. Partly cloudy with a 60-percent chance of rain. Winds blowing in from right field at 5-10 m.p.h. Game-time temperature: Around 80. Los Angeles Dodgers at Chicago Cubs, 8:05 p.m. Clear. Winds blowing in from center field at 5-10 m.p.h. Game-time temperature: Around 60. Milwaukee Brewers at St. Louis Cardinals, 8:15 p.m. Clear. Winds blowing in from center field at 5-10 m.p.h. Game-time temperature: Around 70. Arizona Diamondbacks at Colorado Rockies, 8:40 p.m. Clear. Winds blowing out to left field at 10-15 m.p.h. Game-time temperature: Around 85. Philadelphia Phillies at San Diego Padres, 9:10 p.m. Partly cloudy. Winds blowing in from left field at 10-15 m.p.h. Game-time temperature: Around 75. Boston Red Sox at Pittsburgh Pirates, 7:05 p.m. Partly cloudy. Winds blowing out to right field at 5-10 m.p.h. Game-time temperature: Around 65. Texas Rangers at Oakland Athletics, 3:35 p.m. Cloudy with a 40-percent chance of rain. Winds blowing out to center field at 5-10 m.p.h. Game-time temperature: Around 70. Toronto Blue Jays at New York Yankees, 7:05 p.m. Partly cloudy. Winds blowing out to right field at 5-10 m.p.h. Game-time temperature: Around 70. Cleveland Indians at Houston Astros, 8:10 p.m. Partly cloudy with a 70-percent chance of rain. Winds blowing out to left field at 5-10 m.p.h. Game-time temperature: Around 80. Seattle Mariners at LA Angels of Anaheim, 10:05 p.m. Clear. Winds blowing out to left field at 5-10 m.p.h. Game-time temperature: Around 80. Cleveland Indians at Kansas City Royals, 6:05 p.m. AA 41428 9/18/2014 7:10:00 PM Washington Nationals Miami Marlins 2 Partly cloudy with a 60-percent chance of rain. Winds blowing in from right field at 5-10 m.p.h. Around 80 AA 41430 9/18/2014 8:05:00 PM Los Angeles Dodgers Chicago Cubs 10 Clear. Winds blowing in from center field at 5-10 m.p.h. Around 60 AA 41431 9/18/2014 8:15:00 PM Milwaukee Brewers St. Louis Cardinals 10 Clear. Winds blowing in from center field at 5-10 m.p.h. Around 70 AA 41433 9/18/2014 8:40:00 PM Arizona Diamondbacks Colorado Rockies 10 Clear. Winds blowing out to left field at 10-15 m.p.h. Around 85 AA 41432 9/18/2014 9:10:00 PM Philadelphia Phillies San Diego Padres 2 Partly cloudy. Winds blowing in from left field at 10-15 m.p.h. Around 75 AA 41429 9/18/2014 7:05:00 PM Boston Red Sox Pittsburgh Pirates 2 Partly cloudy. Winds blowing out to right field at 5-10 m.p.h. Around 65 AA 41426 9/18/2014 3:35:00 PM Texas Rangers Oakland Athletics 3 Cloudy with a 40-percent chance of rain. Winds blowing out to center field at 5-10 m.p.h. Around 70 AA 41424 9/18/2014 7:05:00 PM Toronto Blue Jays New York Yankees 2 Partly cloudy. Winds blowing out to right field at 5-10 m.p.h. Around 70 AA 41425 9/18/2014 8:10:00 PM Cleveland Indians Houston Astros 2 Partly cloudy with a 70-percent chance of rain. Winds blowing out to left field at 5-10 m.p.h. Around 80 AA 41427 9/18/2014 10:05:00 PM Seattle Mariners LA Angels of Anaheim 10 Clear. Winds blowing out to left field at 5-10 m.p.h. Around 80 AA 41180 9/22/2014 6:05:00 PM Cleveland Indians Kansas City Royals 11 0 AB 4631 9/18/2014 8:25:00 PM Tampa Bay Buccaneers Atlanta Falcons 11 Game is being played inside a dome. 0 AJ 1247 9/19/2014 10:00:00 PM Toronto Argonauts British Columbia Lions 2 Partly cloudy. Winds southeast at 5-10 m.p.h. Near 65 AF 42695 9/18/2014 7:30:00 PM Auburn Kansas State 2 Partly cloudy. Winds southeast at 10-15 m.p.h. Around 75 AF 44032 9/19/2014 8:00:00 PM Connecticut So Florida 2 Partly cloudy with a 50-percent chance of rain. Winds northeast at 5-10 m.p.h. Around 80 September 18, 2014, at 09:19 AM ET \ No newline at end of file