]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blob - src/TSN/XML/Odds.hs
Add the FromXmlFk class, like FromXml except it requires an FK (old idea).
[dead/htsn-import.git] / src / TSN / XML / Odds.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE GADTs #-}
4 {-# LANGUAGE QuasiQuotes #-}
5 {-# LANGUAGE RecordWildCards #-}
6 {-# LANGUAGE StandaloneDeriving #-}
7 {-# LANGUAGE TemplateHaskell #-}
8 {-# LANGUAGE TypeFamilies #-}
9
10 -- | Parse TSN XML for the DTD "Odds_XML.dtd". Each document contains
11 -- a root element \<message\> that contains a bunch of other
12 -- unorganized crap.
13 --
14 module TSN.XML.Odds (
15 pickle_message,
16 -- * Tests
17 odds_tests,
18 -- * WARNING: these are private but exported to silence warnings
19 Odds_OddsGameConstructor(..),
20 OddsCasinoConstructor(..),
21 OddsConstructor(..),
22 OddsGame_OddsGameTeamConstructor(..),
23 OddsGameConstructor(..),
24 OddsGameLineConstructor(..),
25 OddsGameTeamConstructor(..) )
26 where
27
28 -- System imports.
29 import Control.Monad ( forM_, join )
30 import Data.Time ( UTCTime(..) )
31 import Data.Tuple.Curry ( uncurryN )
32 import Database.Groundhog (
33 (=.),
34 (==.),
35 insert_,
36 insertByAll,
37 migrate,
38 update )
39 import Database.Groundhog.Core ( DefaultKey )
40 import Database.Groundhog.TH (
41 groundhog,
42 mkPersist )
43 import Test.Tasty ( TestTree, testGroup )
44 import Test.Tasty.HUnit ( (@?=), testCase )
45 import Text.Read ( readMaybe )
46 import Text.XML.HXT.Core (
47 PU,
48 xp5Tuple,
49 xp6Tuple,
50 xp8Tuple,
51 xpAttr,
52 xpElem,
53 xpInt,
54 xpList,
55 xpOption,
56 xpPair,
57 xpText,
58 xpTriple,
59 xpWrap )
60
61 -- Local imports.
62 import TSN.Codegen (
63 tsn_codegen_config )
64 import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
65 import TSN.Picklers ( xp_date, xp_time )
66 import TSN.XmlImport ( XmlImport(..) )
67 import Xml ( FromXml(..), ToDb(..), pickle_unpickle, unpickleable )
68
69
70
71 -- | The home/away lines are 'Double's, but the over/under lines are
72 -- textual. If we want to use one data type for both, we have to go
73 -- with a 'String' and then attempt to 'read' a 'Double' later when we
74 -- go to insert the thing.
75 --
76 data OddsGameCasinoXml =
77 OddsGameCasinoXml {
78 xml_casino_client_id :: Int,
79 xml_casino_name :: String,
80 xml_casino_line :: Maybe String }
81 deriving (Eq, Show)
82
83
84 -- | Try to get a 'Double' out of the 'xml_casino_line' which is a
85 -- priori textual (because it might be an over/under line).
86 --
87 home_away_line :: OddsGameCasinoXml -> Maybe Double
88 home_away_line = join . (fmap readMaybe) . xml_casino_line
89
90
91 -- | The casinos should have their own table, but the lines don't
92 -- belong in that table (there should be another table joining the
93 -- casinos and the thing the lines are for together.)
94 --
95 -- We drop the 'Game' prefix because the Casinos really aren't
96 -- children of the games; the XML just makes it seem that way.
97 --
98 data OddsCasino =
99 OddsCasino {
100 casino_client_id :: Int,
101 casino_name :: String }
102 deriving (Eq, Show)
103
104
105 instance ToDb OddsGameCasinoXml where
106 -- | The database representation of an 'OddsGameCasinoXml' is an
107 -- 'OddsCasino'.
108 --
109 type Db OddsGameCasinoXml = OddsCasino
110
111 instance FromXml OddsGameCasinoXml where
112 -- | We convert from XML to the database by dropping the line field.
113 from_xml OddsGameCasinoXml{..} =
114 OddsCasino {
115 casino_client_id = xml_casino_client_id,
116 casino_name = xml_casino_name }
117
118 -- | This allows us to call 'insert_xml' on an 'OddsGameCasinoXml'
119 -- without first converting it to the database representation.
120 instance XmlImport OddsGameCasinoXml
121
122
123 -- | The database representation of teams as they appear in odds
124 -- games.
125 --
126 data OddsGameTeam =
127 OddsGameTeam {
128 db_team_id :: String, -- ^ The home/away team IDs are
129 -- three characters but Postgres
130 -- imposes no performance penalty
131 -- on lengthless text fields, so
132 -- we ignore the probable upper
133 -- bound of three characters.
134 db_abbr :: String,
135 db_team_name :: String }
136 deriving (Eq, Show)
137
138
139 -- | The XML representation of a \<HomeTeam\>, as found in \<Game\>s.
140 --
141 data OddsGameHomeTeamXml =
142 OddsGameHomeTeamXml {
143 xml_home_team_id :: String, -- ^ The home/away team IDs
144 -- are three characters but
145 -- Postgres imposes no
146 -- performance penalty on
147 -- lengthless text fields,
148 -- so we ignore the probable
149 -- upper bound of three
150 -- characters.
151 xml_home_rotation_number :: Int,
152 xml_home_abbr :: String,
153 xml_home_team_name :: String,
154 xml_home_casinos :: [OddsGameCasinoXml] }
155 deriving (Eq, Show)
156
157 instance ToDb OddsGameHomeTeamXml where
158 -- | The database representation of an 'OddsGameHomeTeamXml' is an
159 -- 'OddsGameTeam'.
160 --
161 type Db OddsGameHomeTeamXml = OddsGameTeam
162
163 instance FromXml OddsGameHomeTeamXml where
164 -- | We convert from XML to the database by dropping the lines and
165 -- rotation number (which are specific to the games, not the teams
166 -- themselves).
167 --
168 from_xml OddsGameHomeTeamXml{..} =
169 OddsGameTeam {
170 db_team_id = xml_home_team_id,
171 db_abbr = xml_home_abbr,
172 db_team_name = xml_home_team_name }
173
174 -- | XmlImport allows us to call 'insert_xml' directly on an
175 -- 'OddsGameHomeTeamXml' without explicitly converting it to the
176 -- associated database type.
177 --
178 instance XmlImport OddsGameHomeTeamXml where
179
180
181 -- | The XML representation of a \<AwayTeam\>, as found in \<Game\>s.
182 --
183 data OddsGameAwayTeamXml =
184 OddsGameAwayTeamXml {
185 xml_away_team_id :: String, -- ^ The home/away team IDs are
186 -- three characters but Postgres
187 -- imposes no performance penalty
188 -- on lengthless text fields, so
189 -- we ignore the probable upper
190 -- bound of three characters
191 xml_away_rotation_number :: Int,
192 xml_away_abbr :: String,
193 xml_away_team_name :: String,
194 xml_away_casinos :: [OddsGameCasinoXml] }
195 deriving (Eq, Show)
196
197 instance ToDb OddsGameAwayTeamXml where
198 -- | The database representation of an 'OddsGameAwayTeamXml' is an
199 -- 'OddsGameTeam'.
200 --
201 type Db OddsGameAwayTeamXml = OddsGameTeam
202
203 instance FromXml OddsGameAwayTeamXml where
204 -- | We convert from XML to the database by dropping the lines and
205 -- rotation number (which are specific to the games, not the teams
206 -- themselves).
207 --
208 from_xml OddsGameAwayTeamXml{..} = OddsGameTeam
209 xml_away_team_id
210 xml_away_abbr
211 xml_away_team_name
212
213 -- | XmlImport allows us to call 'insert_xml' directly on an
214 -- 'OddsGameAwayTeamXml' without explicitly converting it to the
215 -- associated database type.
216 --
217 instance XmlImport OddsGameAwayTeamXml where
218
219
220 -- | Database mapping between games and their home/away teams.
221 data OddsGame_OddsGameTeam =
222 OddsGame_OddsGameTeam {
223 ogogt_odds_games_id :: DefaultKey OddsGame,
224 ogogt_away_team_id :: DefaultKey OddsGameTeam,
225 ogogt_home_team_id :: DefaultKey OddsGameTeam }
226
227
228 -- | XML representation of the over/under. A wrapper around a bunch of
229 -- casino elements.
230 --
231 newtype OddsGameOverUnderXml =
232 OddsGameOverUnderXml { xml_casinos :: [OddsGameCasinoXml] }
233 deriving (Eq, Show)
234
235
236 -- | This database representation of the casino lines can't be
237 -- constructed from the one in the XML. The casinos within
238 -- Game>HomeTeam, Game>AwayTeam, and Game>Over_Under are all more or
239 -- less the same. We don't need a bajillion different tables to
240 -- store that, just one tying the casino/game pair to the three
241 -- lines.
242 --
243 -- The one small difference between the over/under casinos and the
244 -- home/away ones is that the home/away lines are all 'Double's, but
245 -- the over/under lines appear to be textual.
246 --
247 data OddsGameLine =
248 OddsGameLine {
249 ogl_odds_games_id :: DefaultKey OddsGame,
250 ogl_odds_casinos_id :: DefaultKey OddsCasino,
251 ogl_over_under :: Maybe String,
252 ogl_away_line :: Maybe Double,
253 ogl_home_line :: Maybe Double }
254
255
256 -- | Database representation of a game. We retain the rotation number
257 -- of the home/away teams, since those are specific to the game and
258 -- not the teams.
259 --
260 data OddsGame =
261 OddsGame {
262 db_game_id :: Int,
263 db_game_time :: UTCTime, -- ^ Contains both the date and time.
264 db_game_away_team_rotation_number :: Int,
265 db_game_home_team_rotation_number :: Int }
266 deriving (Eq, Show)
267
268 -- | XML representation of a game.
269 --
270 data OddsGameXml =
271 OddsGameXml {
272 xml_game_id :: Int,
273 xml_game_date :: UTCTime, -- ^ Contains only the date
274 xml_game_time :: UTCTime, -- ^ Contains only the time
275 xml_game_away_team :: OddsGameAwayTeamXml,
276 xml_game_home_team :: OddsGameHomeTeamXml,
277 xml_game_over_under :: OddsGameOverUnderXml }
278 deriving (Eq, Show)
279
280 -- | Pseudo-field that lets us get the 'OddsGameCasinoXml's out of
281 -- xml_game_over_under.
282 --
283 xml_game_over_under_casinos :: OddsGameXml -> [OddsGameCasinoXml]
284 xml_game_over_under_casinos = xml_casinos . xml_game_over_under
285
286
287 instance ToDb OddsGameXml where
288 -- | The database representation of an 'OddsGameXml' is an
289 -- 'OddsGame'.
290 --
291 type Db OddsGameXml = OddsGame
292
293 instance FromXml OddsGameXml where
294 -- | To convert from the XML representation to the database one, we
295 -- drop the home/away teams and the casino lines, but retain the
296 -- home/away rotation numbers.
297 --
298 from_xml OddsGameXml{..} =
299 OddsGame {
300 db_game_id = xml_game_id,
301
302 db_game_time = UTCTime
303 (utctDay xml_game_date) -- Take the day part from one,
304 (utctDayTime xml_game_time), -- the time from the other.
305
306 db_game_away_team_rotation_number =
307 (xml_away_rotation_number xml_game_away_team),
308
309 db_game_home_team_rotation_number =
310 (xml_home_rotation_number xml_game_home_team) }
311
312 -- | This lets us call 'insert_xml' directly on an 'OddsGameXml'
313 -- without converting it to the database representation explicitly.
314 --
315 instance XmlImport OddsGameXml
316
317
318 -- | Database and representation of the top-level Odds object (a
319 -- 'Message').
320 data Odds =
321 Odds {
322 db_sport :: String,
323 db_title :: String,
324 db_line_time :: String -- ^ We don't parse these as a 'UTCTime'
325 -- because their timezones are ambiguous
326 -- (and the date is less than useful when
327 -- it might be off by an hour).
328 }
329
330
331 -- | Map 'Odds' to their children 'OddsGame's.
332 --
333 data Odds_OddsGame = Odds_OddsGame
334 (DefaultKey Odds)
335 (DefaultKey OddsGame)
336
337
338 -- | This is our best guess at what occurs in the Odds_XML
339 -- documents. It looks like each consecutive set of games can
340 -- optionally have some notes appear before it. Each "note" comes as
341 -- its own <Notes>...</Notes> element.
342 --
343 -- The notes are ignored completely in the database; we only bother
344 -- with them to ensure that we're (un)pickling correctly.
345 --
346 -- We can't group the notes with a "set" of 'OddsGame's, because that
347 -- leads to ambiguity in parsing. Since we're going to ignore the
348 -- notes anyway, we just stick them with an arbitrary game. C'est la
349 -- vie.
350 --
351 data OddsGameWithNotes =
352 OddsGameWithNotes {
353 notes :: [String],
354 game :: OddsGameXml }
355 deriving (Eq, Show)
356
357 -- | The XML representation of 'Odds'.
358 data Message =
359 Message {
360 xml_xml_file_id :: Int,
361 xml_heading :: String,
362 xml_category :: String,
363 xml_sport :: String,
364 xml_title :: String,
365 xml_line_time :: String,
366 xml_games_with_notes :: [OddsGameWithNotes],
367 xml_time_stamp :: String }
368 deriving (Eq, Show)
369
370 -- | Pseudo-field that lets us get the 'OddsGame's out of
371 -- 'xml_games_with_notes'.
372 --
373 xml_games :: Message -> [OddsGameXml]
374 xml_games m = map game (xml_games_with_notes m)
375
376
377 instance ToDb Message where
378 -- | The database representation of a 'Message' is 'Odds'.
379 --
380 type Db Message = Odds
381
382 instance FromXml Message where
383 -- | To convert from the XML representation to the database one, we
384 -- just drop a bunch of fields.
385 --
386 from_xml Message{..} =
387 Odds {
388 db_sport = xml_sport,
389 db_title = xml_title,
390 db_line_time = xml_line_time }
391
392 -- | This lets us call 'insert_xml' on a Message directly, without
393 -- having to convert it to its database representation explicitly.
394 --
395 instance XmlImport Message
396
397
398
399 -- Groundhog database schema. This must come before the DbImport
400 -- instance definition.
401 mkPersist tsn_codegen_config [groundhog|
402 - entity: Odds
403
404 - entity: OddsCasino
405 dbName: odds_casinos
406 constructors:
407 - name: OddsCasino
408 uniques:
409 - name: unique_odds_casino
410 type: constraint
411 fields: [casino_client_id]
412
413 - entity: OddsGameTeam
414 dbName: odds_games_teams
415 constructors:
416 - name: OddsGameTeam
417 uniques:
418 - name: unique_odds_games_team
419 type: constraint
420 fields: [db_team_id]
421
422
423 - entity: OddsGame
424 dbName: odds_games
425 constructors:
426 - name: OddsGame
427 uniques:
428 - name: unique_odds_game
429 type: constraint
430 fields: [db_game_id]
431
432 - entity: OddsGameLine
433 dbName: odds_games_lines
434
435 - entity: Odds_OddsGame
436 dbName: odds__odds_games
437 constructors:
438 - name: Odds_OddsGame
439 fields:
440 - name: odds_OddsGame0 # Default created by mkNormalFieldName
441 dbName: odds_id
442 reference:
443 onDelete: cascade
444 - name: odds_OddsGame1 # Default created by mkNormalFieldName
445 dbName: odds_games_id
446 reference:
447 onDelete: cascade
448
449 - entity: OddsGame_OddsGameTeam
450 dbName: odds_games__odds_games_teams
451 constructors:
452 - name: OddsGame_OddsGameTeam
453 fields:
454 - name: ogogt_odds_games_id
455 reference:
456 onDelete: cascade
457 - name: ogogt_away_team_id
458 reference:
459 onDelete: cascade
460 - name: ogogt_home_team_id
461 reference:
462 onDelete: cascade
463 |]
464
465 instance DbImport Message where
466 dbmigrate _=
467 run_dbmigrate $ do
468 migrate (undefined :: Odds)
469 migrate (undefined :: OddsCasino)
470 migrate (undefined :: OddsGameTeam)
471 migrate (undefined :: OddsGame)
472 migrate (undefined :: Odds_OddsGame)
473 migrate (undefined :: OddsGame_OddsGameTeam)
474 migrate (undefined :: OddsGameLine)
475
476 dbimport m = do
477 -- Insert the root "odds" element and acquire its primary key (id).
478 odds_id <- insert_xml m
479
480 -- Next, we insert the home and away teams. We do this before
481 -- inserting the game itself because the game has two foreign keys
482 -- pointing to odds_games_teams.
483 forM_ (xml_games m) $ \g -> do
484 game_id <- insert_xml_or_select g
485 -- Insert a record into odds__odds_game mapping this game
486 -- to its parent in the odds table.
487 insert_ (Odds_OddsGame odds_id game_id)
488
489 -- Next to insert the home and away teams.
490 away_team_id <- insert_xml_or_select (xml_game_away_team g)
491 home_team_id <- insert_xml_or_select (xml_game_home_team g)
492
493 -- Insert a record into odds_games__odds_games_teams mapping the
494 -- home/away teams to this game. Use the full record syntax
495 -- because the types would let us mix up the home/away teams.
496 insert_ OddsGame_OddsGameTeam {
497 ogogt_odds_games_id = game_id,
498 ogogt_away_team_id = away_team_id,
499 ogogt_home_team_id = home_team_id }
500
501 -- Finaly, we insert the lines. The over/under entries for this
502 -- game and the lines for the casinos all wind up in the same
503 -- table, odds_games_lines. We can insert the over/under entries
504 -- freely with empty away/home lines:
505 forM_ (xml_game_over_under_casinos g) $ \c -> do
506 -- Start by inderting the casino.
507 ou_casino_id <- insert_xml_or_select c
508
509 -- Now add the over/under entry with the casino's id.
510 let ogl = OddsGameLine {
511 ogl_odds_games_id = game_id,
512 ogl_odds_casinos_id = ou_casino_id,
513 ogl_over_under = (xml_casino_line c),
514 ogl_away_line = Nothing,
515 ogl_home_line = Nothing }
516
517 insertByAll ogl
518
519 -- ...but then when we insert the home/away team lines, we
520 -- prefer to update the existing entry rather than overwrite it
521 -- or add a new record.
522 forM_ (xml_away_casinos $ xml_game_away_team g) $ \c ->do
523 -- insert, or more likely retrieve the existing, casino
524 a_casino_id <- insert_xml_or_select c
525
526 -- Get a Maybe Double instead of the Maybe String that's in there.
527 let away_line = home_away_line c
528
529 -- Unconditionally update that casino's away team line with ours.
530 update [Ogl_Away_Line =. away_line] $ -- WHERE
531 Ogl_Odds_Casinos_Id ==. a_casino_id
532
533 -- Repeat all that for the home team.
534 forM_ (xml_home_casinos $ xml_game_home_team g) $ \c ->do
535 h_casino_id <- insert_xml_or_select c
536 let home_line = home_away_line c
537 update [Ogl_Home_Line =. home_line] $ -- WHERE
538 Ogl_Odds_Casinos_Id ==. h_casino_id
539
540 return game_id
541
542 return ImportSucceeded
543
544 -- | Pickler for an 'OddsGame' optionally preceded by some notes.
545 --
546 pickle_game_with_notes :: PU OddsGameWithNotes
547 pickle_game_with_notes =
548 xpWrap (from_pair, to_pair) $
549 xpPair
550 (xpList $ xpElem "Notes" xpText)
551 pickle_game
552 where
553 from_pair = uncurry OddsGameWithNotes
554 to_pair OddsGameWithNotes{..} = (notes, game)
555
556
557 -- | Pickler for an 'OddsGameCasinoXml'.
558 --
559 pickle_casino :: PU OddsGameCasinoXml
560 pickle_casino =
561 xpElem "Casino" $
562 xpWrap (from_tuple, to_tuple) $
563 xpTriple
564 (xpAttr "ClientID" xpInt)
565 (xpAttr "Name" xpText)
566 (xpOption xpText)
567 where
568 from_tuple = uncurryN OddsGameCasinoXml
569 -- Use record wildcards to avoid unused field warnings.
570 to_tuple OddsGameCasinoXml{..} = (xml_casino_client_id,
571 xml_casino_name,
572 xml_casino_line)
573
574
575 -- | Pickler for an 'OddsGameHomeTeamXml'.
576 --
577 pickle_home_team :: PU OddsGameHomeTeamXml
578 pickle_home_team =
579 xpElem "HomeTeam" $
580 xpWrap (from_tuple, to_tuple) $
581 xp5Tuple
582 (xpElem "HomeTeamID" xpText)
583 (xpElem "HomeRotationNumber" xpInt)
584 (xpElem "HomeAbbr" xpText)
585 (xpElem "HomeTeamName" xpText)
586 (xpList pickle_casino)
587 where
588 from_tuple = uncurryN OddsGameHomeTeamXml
589 -- Use record wildcards to avoid unused field warnings.
590 to_tuple OddsGameHomeTeamXml{..} = (xml_home_team_id,
591 xml_home_rotation_number,
592 xml_home_abbr,
593 xml_home_team_name,
594 xml_home_casinos)
595
596
597 -- | Pickler for an 'OddsGameAwayTeamXml'.
598 --
599 pickle_away_team :: PU OddsGameAwayTeamXml
600 pickle_away_team =
601 xpElem "AwayTeam" $
602 xpWrap (from_tuple, to_tuple) $
603 xp5Tuple
604 (xpElem "AwayTeamID" xpText)
605 (xpElem "AwayRotationNumber" xpInt)
606 (xpElem "AwayAbbr" xpText)
607 (xpElem "AwayTeamName" xpText)
608 (xpList pickle_casino)
609 where
610 from_tuple = uncurryN OddsGameAwayTeamXml
611 -- Use record wildcards to avoid unused field warnings.
612 to_tuple OddsGameAwayTeamXml{..} = (xml_away_team_id,
613 xml_away_rotation_number,
614 xml_away_abbr,
615 xml_away_team_name,
616 xml_away_casinos)
617
618
619
620 -- | Pickler for an 'OddsGameOverUnderXml'.
621 --
622 pickle_over_under :: PU OddsGameOverUnderXml
623 pickle_over_under =
624 xpElem "Over_Under" $
625 xpWrap (to_newtype, from_newtype) $
626 xpList pickle_casino
627 where
628 from_newtype (OddsGameOverUnderXml cs) = cs
629 to_newtype = OddsGameOverUnderXml
630
631
632 -- | Pickler for an 'OddsGameXml'.
633 --
634 pickle_game :: PU OddsGameXml
635 pickle_game =
636 xpElem "Game" $
637 xpWrap (from_tuple, to_tuple) $
638 xp6Tuple
639 (xpElem "GameID" xpInt)
640 (xpElem "Game_Date" xp_date)
641 (xpElem "Game_Time" xp_time)
642 pickle_away_team
643 pickle_home_team
644 pickle_over_under
645 where
646 from_tuple = uncurryN OddsGameXml
647 -- Use record wildcards to avoid unused field warnings.
648 to_tuple OddsGameXml{..} = (xml_game_id,
649 xml_game_date,
650 xml_game_time,
651 xml_game_away_team,
652 xml_game_home_team,
653 xml_game_over_under)
654
655
656 -- | Pickler for the top-level 'Message'.
657 --
658 pickle_message :: PU Message
659 pickle_message =
660 xpElem "message" $
661 xpWrap (from_tuple, to_tuple) $
662 xp8Tuple (xpElem "XML_File_ID" xpInt)
663 (xpElem "heading" xpText)
664 (xpElem "category" xpText)
665 (xpElem "sport" xpText)
666 (xpElem "Title" xpText)
667 (xpElem "Line_Time" xpText)
668 (xpList pickle_game_with_notes)
669 (xpElem "time_stamp" xpText)
670 where
671 from_tuple = uncurryN Message
672 to_tuple m = (xml_xml_file_id m,
673 xml_heading m,
674 xml_category m,
675 xml_sport m,
676 xml_title m,
677 xml_line_time m,
678 xml_games_with_notes m,
679 xml_time_stamp m)
680
681
682 --
683 -- Tasty Tests
684 --
685
686 -- | A list of all tests for this module.
687 --
688 odds_tests :: TestTree
689 odds_tests =
690 testGroup
691 "Odds tests"
692 [ test_pickle_of_unpickle_is_identity,
693 test_unpickle_succeeds ]
694
695
696 -- | If we unpickle something and then pickle it, we should wind up
697 -- with the same thing we started with. WARNING: success of this
698 -- test does not mean that unpickling succeeded.
699 --
700 test_pickle_of_unpickle_is_identity :: TestTree
701 test_pickle_of_unpickle_is_identity = testGroup "pickle-unpickle tests"
702 [ check "pickle composed with unpickle is the identity"
703 "test/xml/Odds_XML.xml",
704
705 check "pickle composed with unpickle is the identity (non-int team_id)"
706 "test/xml/Odds_XML-noninteger-team-id.xml",
707
708 check "pickle composed with unpickle is the identity (positive(+) line)"
709 "test/xml/Odds_XML-positive-line.xml",
710
711 check "pickle composed with unpickle is the identity (large file)"
712 "test/xml/Odds_XML-largefile.xml" ]
713 where
714 check desc path = testCase desc $ do
715 (expected, actual) <- pickle_unpickle pickle_message path
716 actual @?= expected
717
718
719 -- | Make sure we can actually unpickle these things.
720 --
721 test_unpickle_succeeds :: TestTree
722 test_unpickle_succeeds = testGroup "unpickle tests"
723 [ check "unpickling succeeds"
724 "test/xml/Odds_XML.xml",
725
726 check "unpickling succeeds (non-int team_id)"
727 "test/xml/Odds_XML-noninteger-team-id.xml",
728
729 check "unpickling succeeds (positive(+) line)"
730 "test/xml/Odds_XML-positive-line.xml",
731
732 check "unpickling succeeds (large file)"
733 "test/xml/Odds_XML-largefile.xml" ]
734 where
735 check desc path = testCase desc $ do
736 actual <- unpickleable path pickle_message
737 let expected = True
738 actual @?= expected