Add a test case for the newly-optional elements and update a shelltest.
Update the weatherxml dbschema diagram.
data WeatherForecastListingXml =
WeatherForecastListingXml {
xml_teams :: String,
data WeatherForecastListingXml =
WeatherForecastListingXml {
xml_teams :: String,
- xml_weather :: String }
+ xml_weather :: Maybe String }
db_weather_forecasts_id :: DefaultKey WeatherForecast,
db_league_name :: Maybe String,
db_teams :: String,
db_weather_forecasts_id :: DefaultKey WeatherForecast,
db_league_name :: Maybe String,
db_teams :: String,
+ db_weather :: Maybe String }
-- | We don't make 'WeatherForecastListingXml' an instance of
-- | We don't make 'WeatherForecastListingXml' an instance of
db_away_team :: String,
db_home_team :: String,
db_weather_type :: Int,
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 }
db_temp_adjust :: Maybe String,
db_temperature :: Int }
xml_away_team :: String,
xml_home_team :: String,
xml_weather_type :: Int,
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)
xml_temp_adjust :: Maybe String,
xml_temperature :: Int }
deriving (Eq, Show)
xpWrap (from_pair, to_pair) $
xpPair
(xpElem "teams" xpText)
xpWrap (from_pair, to_pair) $
xpPair
(xpElem "teams" xpText)
- (xpElem "weather" xpText)
+ (xpElem "weather" (xpOption xpText))
+-- from_pair (ts, Nothing) = WeatherForecastListingXml ts (Just "")
from_pair = uncurry WeatherForecastListingXml
to_pair WeatherForecastListingXml{..} = (xml_teams, xml_weather)
from_pair = uncurry WeatherForecastListingXml
to_pair WeatherForecastListingXml{..} = (xml_teams, xml_weather)
(xpElem "AwayTeam" xpText)
(xpElem "HomeTeam" xpText)
(xpElem "WeatherType" xpInt)
(xpElem "AwayTeam" xpText)
(xpElem "HomeTeam" xpText)
(xpElem "WeatherType" xpInt)
- (xpElem "Description" xpText)
+ (xpElem "Description" (xpOption xpText))
(xpElem "TempAdjust" (xpOption xpText))
(xpElem "Temperature" xpInt)
where
(xpElem "TempAdjust" (xpOption xpText))
(xpElem "Temperature" xpInt)
where
[ check "unpickling succeeds"
"test/xml/weatherxml.xml",
check "unpickling succeeds (detailed)"
[ 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
where
check desc path = testCase desc $ do
actual <- unpickleable path pickle_message
[ check "deleting weather deletes its children"
"test/xml/weatherxml.xml",
check "deleting weather deletes its children (detailed)"
[ 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
where
check desc path = testCase desc $ do
weather <- unsafe_unpickle path pickle_message
check "test/xml/weatherxml-detailed.xml"
"first type detected correctly (detailed)"
True,
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 ]
check "test/xml/weatherxml-type2.xml"
"second type detected correctly"
False ]
# and a newsxml that aren't really supposed to import.
find ./test/xml -maxdepth 1 -name '*.xml' | wc -l
>>>
# and a newsxml that aren't really supposed to import.
find ./test/xml -maxdepth 1 -name '*.xml' | wc -l
>>>
>>>= 0
# Run the imports again; we should get complaints about the duplicate
>>>= 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
>>>
# occurrences of the string 'ERROR'.
./dist/build/htsn-import/htsn-import -c 'shelltest.sqlite3' test/xml/*.xml 2>&1 | grep ERROR | wc -l
>>>
>>>= 0
# Finally, clean up after ourselves.
>>>= 0
# Finally, clean up after ourselves.
--- /dev/null
+<?xml version="1.0" standalone="no" ?>\r<!DOCTYPE message PUBLIC "-//TSN//DTD Weather 1.0/EN" "weatherxml.dtd">\r<message>\r<XML_File_ID>21812233</XML_File_ID>\r<heading>AAW%BBWEATHER</heading>\r<category>Weather</category>\r<sport>MLB</sport>\r<title>Major League Baseball Weather from The Sports Network</title>\r<forecast gamedate="Thursday, September 18th">\r<league name="National League">\r<listing>\r<teams>Washington Nationals at Miami Marlins, 7:10 p.m.</teams>\r<weather>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.</weather>\r</listing>\r<listing>\r<teams>Los Angeles Dodgers at Chicago Cubs, 8:05 p.m.</teams>\r<weather>Clear. Winds blowing in from center field at 5-10 m.p.h. Game-time temperature: Around 60.</weather>\r</listing>\r<listing>\r<teams>Milwaukee Brewers at St. Louis Cardinals, 8:15 p.m.</teams>\r<weather>Clear. Winds blowing in from center field at 5-10 m.p.h. Game-time temperature: Around 70.</weather>\r</listing>\r<listing>\r<teams>Arizona Diamondbacks at Colorado Rockies, 8:40 p.m.</teams>\r<weather>Clear. Winds blowing out to left field at 10-15 m.p.h. Game-time temperature: Around 85.</weather>\r</listing>\r<listing>\r<teams>Philadelphia Phillies at San Diego Padres, 9:10 p.m.</teams>\r<weather>Partly cloudy. Winds blowing in from left field at 10-15 m.p.h. Game-time temperature: Around 75.</weather>\r</listing>\r</league>\r<league name="Interleague">\r<listing>\r<teams>Boston Red Sox at Pittsburgh Pirates, 7:05 p.m.</teams>\r<weather>Partly cloudy. Winds blowing out to right field at 5-10 m.p.h. Game-time temperature: Around 65.</weather>\r</listing>\r</league>\r<league name="American League">\r<listing>\r<teams>Texas Rangers at Oakland Athletics, 3:35 p.m.</teams>\r<weather>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.</weather>\r</listing>\r<listing>\r<teams>Toronto Blue Jays at New York Yankees, 7:05 p.m.</teams>\r<weather>Partly cloudy. Winds blowing out to right field at 5-10 m.p.h. Game-time temperature: Around 70.</weather>\r</listing>\r<listing>\r<teams>Cleveland Indians at Houston Astros, 8:10 p.m.</teams>\r<weather>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.</weather>\r</listing>\r<listing>\r<teams>Seattle Mariners at LA Angels of Anaheim, 10:05 p.m.</teams>\r<weather>Clear. Winds blowing out to left field at 5-10 m.p.h. Game-time temperature: Around 80.</weather>\r</listing>\r</league>\r</forecast>\r<forecast gamedate="Monday, September 22nd">\r<league name="">\r<listing>\r<teams>Cleveland Indians at Kansas City Royals, 6:05 p.m.</teams>\r<weather></weather>\r</listing>\r</league>\r</forecast>\r<Detailed_Weather>\r<DW_Listing SportCode="AA" Sport="MLB">\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41428</GameID>\r<Gamedate>9/18/2014 7:10:00 PM</Gamedate>\r<AwayTeam>Washington Nationals</AwayTeam>\r<HomeTeam>Miami Marlins</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy with a 60-percent chance of rain. Winds blowing in from right field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>80</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41430</GameID>\r<Gamedate>9/18/2014 8:05:00 PM</Gamedate>\r<AwayTeam>Los Angeles Dodgers</AwayTeam>\r<HomeTeam>Chicago Cubs</HomeTeam>\r<WeatherType>10</WeatherType>\r<Description>Clear. Winds blowing in from center field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>60</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41431</GameID>\r<Gamedate>9/18/2014 8:15:00 PM</Gamedate>\r<AwayTeam>Milwaukee Brewers</AwayTeam>\r<HomeTeam>St. Louis Cardinals</HomeTeam>\r<WeatherType>10</WeatherType>\r<Description>Clear. Winds blowing in from center field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>70</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41433</GameID>\r<Gamedate>9/18/2014 8:40:00 PM</Gamedate>\r<AwayTeam>Arizona Diamondbacks</AwayTeam>\r<HomeTeam>Colorado Rockies</HomeTeam>\r<WeatherType>10</WeatherType>\r<Description>Clear. Winds blowing out to left field at 10-15 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>85</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41432</GameID>\r<Gamedate>9/18/2014 9:10:00 PM</Gamedate>\r<AwayTeam>Philadelphia Phillies</AwayTeam>\r<HomeTeam>San Diego Padres</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy. Winds blowing in from left field at 10-15 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>75</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41429</GameID>\r<Gamedate>9/18/2014 7:05:00 PM</Gamedate>\r<AwayTeam>Boston Red Sox</AwayTeam>\r<HomeTeam>Pittsburgh Pirates</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy. Winds blowing out to right field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>65</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41426</GameID>\r<Gamedate>9/18/2014 3:35:00 PM</Gamedate>\r<AwayTeam>Texas Rangers</AwayTeam>\r<HomeTeam>Oakland Athletics</HomeTeam>\r<WeatherType>3</WeatherType>\r<Description>Cloudy with a 40-percent chance of rain. Winds blowing out to center field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>70</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41424</GameID>\r<Gamedate>9/18/2014 7:05:00 PM</Gamedate>\r<AwayTeam>Toronto Blue Jays</AwayTeam>\r<HomeTeam>New York Yankees</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy. Winds blowing out to right field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>70</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41425</GameID>\r<Gamedate>9/18/2014 8:10:00 PM</Gamedate>\r<AwayTeam>Cleveland Indians</AwayTeam>\r<HomeTeam>Houston Astros</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy with a 70-percent chance of rain. Winds blowing out to left field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>80</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41427</GameID>\r<Gamedate>9/18/2014 10:05:00 PM</Gamedate>\r<AwayTeam>Seattle Mariners</AwayTeam>\r<HomeTeam>LA Angels of Anaheim</HomeTeam>\r<WeatherType>10</WeatherType>\r<Description>Clear. Winds blowing out to left field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>80</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41180</GameID>\r<Gamedate>9/22/2014 6:05:00 PM</Gamedate>\r<AwayTeam>Cleveland Indians</AwayTeam>\r<HomeTeam>Kansas City Royals</HomeTeam>\r<WeatherType>11</WeatherType>\r<Description></Description>\r<TempAdjust></TempAdjust>\r<Temperature>0</Temperature>\r</Item>\r</DW_Listing>\r<DW_Listing SportCode="AB" Sport="NFL">\r<Item>\r<Sportcode>AB</Sportcode>\r<GameID>4631</GameID>\r<Gamedate>9/18/2014 8:25:00 PM</Gamedate>\r<AwayTeam>Tampa Bay Buccaneers</AwayTeam>\r<HomeTeam>Atlanta Falcons</HomeTeam>\r<WeatherType>11</WeatherType>\r<Description>Game is being played inside a dome.</Description>\r<TempAdjust></TempAdjust>\r<Temperature>0</Temperature>\r</Item>\r</DW_Listing>\r<DW_Listing SportCode="AJ" Sport="CFL">\r<Item>\r<Sportcode>AJ</Sportcode>\r<GameID>1247</GameID>\r<Gamedate>9/19/2014 10:00:00 PM</Gamedate>\r<AwayTeam>Toronto Argonauts</AwayTeam>\r<HomeTeam>British Columbia Lions</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy. Winds southeast at 5-10 m.p.h.</Description>\r<TempAdjust>Near</TempAdjust>\r<Temperature>65</Temperature>\r</Item>\r</DW_Listing>\r<DW_Listing SportCode="AF" Sport="CFOOT">\r<Item>\r<Sportcode>AF</Sportcode>\r<GameID>42695</GameID>\r<Gamedate>9/18/2014 7:30:00 PM</Gamedate>\r<AwayTeam>Auburn</AwayTeam>\r<HomeTeam>Kansas State</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy. Winds southeast at 10-15 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>75</Temperature>\r</Item>\r<Item>\r<Sportcode>AF</Sportcode>\r<GameID>44032</GameID>\r<Gamedate>9/19/2014 8:00:00 PM</Gamedate>\r<AwayTeam>Connecticut</AwayTeam>\r<HomeTeam>So Florida</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy with a 50-percent chance of rain. Winds northeast at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>80</Temperature>\r</Item>\r</DW_Listing>\r</Detailed_Weather>\r<time_stamp> September 18, 2014, at 09:19 AM ET </time_stamp>\r</message>\r
\ No newline at end of file