class testRegexes : """ Test Regexes Class """ def setUp(self) : self.Tools = Tools() self.Tools.createRootDir() self.Tools.createBackendFiles() self.regex = Regexes() def tearDown(self): self.Tools.removeTempFiles() def testRemoveTags(self): assert self.regex.removeTags( '<h1>Text</h1>' ) == 'Text' #assert self.regex.removeTags( '<h1><h1>Text</h1></h1>' ) == 'Text' #assert self.regex.removeTags( '<h1>Text</h1></h1>' ) == 'Text' def testExtractAirDate(self): self.regex.extractAirDate( '<strong>6 November 2008</strong>' ) == ('6 November 2008',) def testExtractEpSeTitle(self): assert self.regex.extractEpSeTitle( '<h3>Season 00051, Episode 010: <a href="/title/t0987tsa/">Title</a></h3>' ) == ('51', '10', 'Title') assert self.regex.extractEpSeTitle( '<h3>Season 9, Episode 201: <a href="/title/t/">T80932sdf/[]}}]</a></h3>' ) == ('9', '201', 'T80932sdf/[]}}]') assert self.regex.extractEpSeTitle( '<h3>Season 12, Episode 00: <a href="/title/098sdft8/">) s{ }350dfklj</a></h3>' ) == ('12', '0', ') s{ }350dfklj') assert self.regex.extractEpSeTitle( '<h3>Season 001000050, Episode 010: <a href="/title/098sdft8/"></a></h3>' ) == ('1000050', '10', None)
class testBackends : """ Test Backends Class """ def setUp(self) : self.Tools = Tools() self.Tools.createRootDir() self.Tools.createBackendFiles() self.backend1 = Backends() def tearDown(self): self.Tools.removeTempFiles() def testGetBackends(self): assert self.backend1.getBackends(self.Tools.BackendDirectory) == ['imdbtvbackend']
class testBackends: """ Test Backends Class """ def setUp(self): self.Tools = Tools() self.Tools.createRootDir() self.Tools.createBackendFiles() self.backend1 = Backends() def tearDown(self): self.Tools.removeTempFiles() def testGetBackends(self): assert self.backend1.getBackends( self.Tools.BackendDirectory) == ['imdbtvbackend']
class testBackend : """ Test Backend Class """ def setUp(self) : self.Tools = Tools() self.Tools.createRootDir() self.Tools.createBackendFiles() self.Tools.createDatabaseFiles() self.backend = Backend() validShows1 = [ Show( "Spaced", "60", "imdbtvbackend", "tt0187664" ) ] self.database1 = Database(self.Tools.databaseDir, validShows1) self.database1.loadDB() validShows2 = [ Show( "Black Books", "30", "imdbtvbackend", "tt0262150" ) ] self.database2 = Database(self.Tools.databaseDir, validShows2) self.database2.loadDB() def tearDown(self): self.Tools.removeTempFiles() def testDownloadShowList(self): content = self.backend.downloadShowList(self.database1.database) assert [ show.name for show in content.keys() ] == ['Spaced'] content = self.backend.downloadShowList(self.database2.database) assert [ show.name for show in content.keys() ] == ['Black Books'] def testGetShowDetails(self): updateDB1 = self.backend.getShowDetails( self.backend.downloadShowList(self.database1.database)) assert [ (show.name, season.name, episode.name, episode.title ) for show in updateDB1.database for season in show.seasons for episode in season.episodes ] == [('Spaced', '1', '1', 'Beginnings'), ('Spaced', '1', '2', 'Gatherings'), ('Spaced', '1', '3', 'Art'), ('Spaced', '1', '4', 'Battles'), ('Spaced', '1', '5', 'Chaos'), ('Spaced', '1', '6', 'Epiphanies'), ('Spaced', '1', '7', 'Ends'), ('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt')] updateDB2 = self.backend.getShowDetails( self.backend.downloadShowList(self.database2.database)) assert [ (show.name, season.name, episode.name, episode.title ) for show in updateDB2.database for season in show.seasons for episode in season.episodes ] == [('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')]
class testBackendInterface: """ Test BackendInterface Class """ def setUp(self): self.Tools = Tools() self.Tools.createRootDir() self.Tools.createBackendFiles() self.Tools.createDatabaseFiles() class NewBackendInterface(BackendInterface): def solveEpisodeConflicts(self, firstEpisode, secondEpisode): return firstEpisode self.BaIf1 = NewBackendInterface(self.Tools.databaseDir) def tearDown(self): self.Tools.removeTempFiles() def testAddNewShow(self): Show1 = Show("Test Show One", "60", "dummybackend", "dummyurlone") Show2 = Show("Test Show Two", "60", "dummybackend", "dummyurltwo") Show3 = Show("Test Show Three", "60", "dummybackend", "dummyurlthree") assert self.BaIf1.addNewShow(Show1) == Show1 assert self.BaIf1.addNewShow(Show1) == None assert self.BaIf1.addNewShow(Show2) == Show2 assert self.BaIf1.addNewShow( Show("Test Show Two", "60", "dummybackend", "dummyurltwo")) == None assert self.BaIf1.addNewShow(Show3) == Show3 def testUpdateDatabase(self): assert os.path.exists(self.Tools.databaseDir) == True DB2 = [] for filename in self.Tools.databaseFiles.values(): testfile = open(os.path.join(self.Tools.databaseDir, filename), "r") content = testfile.read() testfile.close() DB2.append((content, filename)) assert DB2 == [ ('<?xml version="1.0" encoding="UTF-8"?>\n<tvshow>\n <showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664"/>\n <aliases>\n <alias value="spaced"/>\n </aliases>\n <season number="1">\n <episode airdate="24 September 1999" arc="none" number="1" title="Beginnings"/>\n <episode airdate="1 October 1999" arc="none" number="2" title="Gatherings"/>\n <episode airdate="8 October 1999" arc="none" number="3" title="Art"/>\n <episode airdate="15 October 1999" arc="none" number="4" title="Battles"/>\n <episode airdate="22 October 1999" arc="none" number="5" title="Chaos"/>\n <episode airdate="29 October 1999" arc="none" number="6" title="Epiphanies"/>\n <episode airdate="5 November 1999" arc="none" number="7" title="Ends"/>\n </season>\n <season number="2">\n <episode airdate="23 February 2001" arc="none" number="1" title="Back"/>\n <episode airdate="2 March 2001" arc="none" number="2" title="Change"/>\n <episode airdate="9 March 2001" arc="none" number="3" title="Mettle"/>\n <episode airdate="23 March 2001" arc="none" number="4" title="Help"/>\n <episode airdate="None" arc="none" number="5" title="Gone"/>\n <episode airdate="6 April 2001" arc="none" number="6" title="Dissolution"/>\n <episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt"/>\n </season>\n</tvshow>', 'spaced.show'), ('<?xml version="1.0" encoding="UTF-8"?>\n<tvshow>\n <showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150"/>\n <aliases>\n <alias value="blackbooks"/>\n <alias value="black books"/>\n <alias value="black.books"/>\n <alias value="bb"/>\n </aliases>\n <season number="1">\n <episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books"/>\n <episode airdate="6 October 2000" arc="none" number="2" title="Manny\'s First Day"/>\n <episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath"/>\n <episode airdate="20 October 2000" arc="none" number="4" title="The Blackout"/>\n <episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out"/>\n <episode airdate="3 November 2000" arc="none" number="6" title="He\'s Leaving Home"/>\n </season>\n <season number="2">\n <episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer"/>\n <episode airdate="8 March 2002" arc="none" number="2" title="Fever"/>\n <episode airdate="15 March 2002" arc="none" number="3" title="The Fixer"/>\n <episode airdate="22 March 2002" arc="none" number="4" title="Blood"/>\n <episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun"/>\n <episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change"/>\n </season>\n <season number="3">\n <episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home"/>\n <episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens"/>\n <episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa"/>\n <episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter"/>\n <episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer"/>\n <episode airdate="15 April 2004" arc="none" number="6" title="Party"/>\n </season>\n</tvshow>\n', 'blackbooks.show'), ('<?xml version="1.0" encoding="UTF-8"?>\n<tvshow>\n <showproperties backend="imdbtvbackend" duration="60" name="C.S.I" url="tt0247082"/>\n <aliases>\n <alias value="csi"/>\n </aliases>\n <season number="1">\n <episode airdate="6 October 2000" arc="none" number="1" title="Pilot"/>\n <episode airdate="13 October 2000" arc="none" number="2" title="Cool Change"/>\n <episode airdate="20 October 2000" arc="none" number="3" title="Crate \'n\' Burial"/>\n <episode airdate="27 October 2000" arc="none" number="4" title="Pledging Mr. Johnson"/>\n <episode airdate="3 November 2000" arc="none" number="5" title="Friends & Lovers"/>\n <episode airdate="10 November 2000" arc="none" number="6" title="Who Are You?"/>\n <episode airdate="17 November 2000" arc="none" number="7" title="Blood Drops"/>\n <episode airdate="24 November 2000" arc="none" number="8" title="Anonymous"/>\n <episode airdate="8 December 2000" arc="none" number="9" title="Unfriendly Skies"/>\n <episode airdate="22 December 2000" arc="none" number="10" title="Sex, Lies and Larvae"/>\n <episode airdate="12 January 2001" arc="none" number="11" title="I-15 Murders"/>\n <episode airdate="1 February 2001" arc="none" number="12" title="Fahrenheit 932"/>\n <episode airdate="8 February 2001" arc="none" number="13" title="Boom"/>\n <episode airdate="15 February 2001" arc="none" number="14" title="To Halve and to Hold"/>\n <episode airdate="22 February 2001" arc="none" number="15" title="Table Stakes"/>\n <episode airdate="1 March 2001" arc="none" number="16" title="Too Tough to Die"/>\n <episode airdate="8 March 2001" arc="none" number="17" title="Face Lift"/>\n <episode airdate="29 March 2001" arc="none" number="18" title="$35K O.B.O."/>\n <episode airdate="12 April 2001" arc="none" number="19" title="Gentle, Gentle"/>\n <episode airdate="19 April 2001" arc="none" number="20" title="Sounds of Silence"/>\n <episode airdate="26 April 2001" arc="none" number="21" title="Justice Is Served"/>\n <episode airdate="10 May 2001" arc="none" number="22" title="Evaluation Day"/>\n <episode airdate="17 May 2001" arc="none" number="23" title="The Strip Strangler"/>\n </season>\n <season number="2">\n <episode airdate="27 September 2001" arc="none" number="1" title="Burked"/>\n <episode airdate="4 October 2001" arc="none" number="2" title="Chaos Theory"/>\n <episode airdate="11 October 2001" arc="none" number="3" title="Overload"/>\n <episode airdate="18 October 2001" arc="none" number="4" title="Bully for You"/>\n <episode airdate="25 October 2001" arc="none" number="5" title="Scuba Doobie-Doo"/>\n <episode airdate="1 November 2001" arc="none" number="6" title="Alter Boys"/>\n <episode airdate="8 November 2001" arc="none" number="7" title="Caged"/>\n <episode airdate="15 November 2001" arc="none" number="8" title="Slaves of Las Vegas"/>\n <episode airdate="22 November 2001" arc="none" number="9" title="And Then There Were None"/>\n <episode airdate="6 December 2001" arc="none" number="10" title="Ellie"/>\n <episode airdate="13 December 2001" arc="none" number="11" title="Organ Grinder"/>\n <episode airdate="20 December 2001" arc="none" number="12" title="You\'ve Got Male"/>\n <episode airdate="17 January 2002" arc="none" number="13" title="Identity Crisis"/>\n <episode airdate="None" arc="none" number="14" title="The Finger"/>\n <episode airdate="7 February 2002" arc="none" number="15" title="Burden of Proof"/>\n <episode airdate="28 February 2002" arc="none" number="16" title="Primum Non Nocere"/>\n <episode airdate="7 March 2002" arc="none" number="17" title="Felonious Monk"/>\n <episode airdate="28 March 2002" arc="none" number="18" title="Chasing the Bus"/>\n <episode airdate="4 April 2002" arc="none" number="19" title="Stalker"/>\n <episode airdate="25 April 2002" arc="none" number="20" title="Cats in the Cradle..."/>\n <episode airdate="2 May 2002" arc="none" number="21" title="Anatomy of a Lye"/>\n <episode airdate="9 May 2002" arc="none" number="22" title="Cross-Jurisdictions"/>\n <episode airdate="18 May 2002" arc="none" number="23" title="The Hunger Artist"/>\n </season>\n</tvshow>\n', 'csi.show') ] show1 = self.BaIf1.currentDB.getShow( Show('Spaced', '30', 'imdbtvbackend', 'tt000000')) show1.removeSeason(Season('1')) DB21 = [] for filename in self.Tools.databaseFiles.values(): testfile = open(os.path.join(self.Tools.databaseDir, filename), "r") content = testfile.read() testfile.close() DB21.append((content, filename)) assert DB21 == [ ('<?xml version="1.0" encoding="UTF-8"?>\n<tvshow>\n <showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664"/>\n <aliases>\n <alias value="spaced"/>\n </aliases>\n <season number="1">\n <episode airdate="24 September 1999" arc="none" number="1" title="Beginnings"/>\n <episode airdate="1 October 1999" arc="none" number="2" title="Gatherings"/>\n <episode airdate="8 October 1999" arc="none" number="3" title="Art"/>\n <episode airdate="15 October 1999" arc="none" number="4" title="Battles"/>\n <episode airdate="22 October 1999" arc="none" number="5" title="Chaos"/>\n <episode airdate="29 October 1999" arc="none" number="6" title="Epiphanies"/>\n <episode airdate="5 November 1999" arc="none" number="7" title="Ends"/>\n </season>\n <season number="2">\n <episode airdate="23 February 2001" arc="none" number="1" title="Back"/>\n <episode airdate="2 March 2001" arc="none" number="2" title="Change"/>\n <episode airdate="9 March 2001" arc="none" number="3" title="Mettle"/>\n <episode airdate="23 March 2001" arc="none" number="4" title="Help"/>\n <episode airdate="None" arc="none" number="5" title="Gone"/>\n <episode airdate="6 April 2001" arc="none" number="6" title="Dissolution"/>\n <episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt"/>\n </season>\n</tvshow>', 'spaced.show'), ('<?xml version="1.0" encoding="UTF-8"?>\n<tvshow>\n <showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150"/>\n <aliases>\n <alias value="blackbooks"/>\n <alias value="black books"/>\n <alias value="black.books"/>\n <alias value="bb"/>\n </aliases>\n <season number="1">\n <episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books"/>\n <episode airdate="6 October 2000" arc="none" number="2" title="Manny\'s First Day"/>\n <episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath"/>\n <episode airdate="20 October 2000" arc="none" number="4" title="The Blackout"/>\n <episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out"/>\n <episode airdate="3 November 2000" arc="none" number="6" title="He\'s Leaving Home"/>\n </season>\n <season number="2">\n <episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer"/>\n <episode airdate="8 March 2002" arc="none" number="2" title="Fever"/>\n <episode airdate="15 March 2002" arc="none" number="3" title="The Fixer"/>\n <episode airdate="22 March 2002" arc="none" number="4" title="Blood"/>\n <episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun"/>\n <episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change"/>\n </season>\n <season number="3">\n <episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home"/>\n <episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens"/>\n <episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa"/>\n <episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter"/>\n <episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer"/>\n <episode airdate="15 April 2004" arc="none" number="6" title="Party"/>\n </season>\n</tvshow>\n', 'blackbooks.show'), ('<?xml version="1.0" encoding="UTF-8"?>\n<tvshow>\n <showproperties backend="imdbtvbackend" duration="60" name="C.S.I" url="tt0247082"/>\n <aliases>\n <alias value="csi"/>\n </aliases>\n <season number="1">\n <episode airdate="6 October 2000" arc="none" number="1" title="Pilot"/>\n <episode airdate="13 October 2000" arc="none" number="2" title="Cool Change"/>\n <episode airdate="20 October 2000" arc="none" number="3" title="Crate \'n\' Burial"/>\n <episode airdate="27 October 2000" arc="none" number="4" title="Pledging Mr. Johnson"/>\n <episode airdate="3 November 2000" arc="none" number="5" title="Friends & Lovers"/>\n <episode airdate="10 November 2000" arc="none" number="6" title="Who Are You?"/>\n <episode airdate="17 November 2000" arc="none" number="7" title="Blood Drops"/>\n <episode airdate="24 November 2000" arc="none" number="8" title="Anonymous"/>\n <episode airdate="8 December 2000" arc="none" number="9" title="Unfriendly Skies"/>\n <episode airdate="22 December 2000" arc="none" number="10" title="Sex, Lies and Larvae"/>\n <episode airdate="12 January 2001" arc="none" number="11" title="I-15 Murders"/>\n <episode airdate="1 February 2001" arc="none" number="12" title="Fahrenheit 932"/>\n <episode airdate="8 February 2001" arc="none" number="13" title="Boom"/>\n <episode airdate="15 February 2001" arc="none" number="14" title="To Halve and to Hold"/>\n <episode airdate="22 February 2001" arc="none" number="15" title="Table Stakes"/>\n <episode airdate="1 March 2001" arc="none" number="16" title="Too Tough to Die"/>\n <episode airdate="8 March 2001" arc="none" number="17" title="Face Lift"/>\n <episode airdate="29 March 2001" arc="none" number="18" title="$35K O.B.O."/>\n <episode airdate="12 April 2001" arc="none" number="19" title="Gentle, Gentle"/>\n <episode airdate="19 April 2001" arc="none" number="20" title="Sounds of Silence"/>\n <episode airdate="26 April 2001" arc="none" number="21" title="Justice Is Served"/>\n <episode airdate="10 May 2001" arc="none" number="22" title="Evaluation Day"/>\n <episode airdate="17 May 2001" arc="none" number="23" title="The Strip Strangler"/>\n </season>\n <season number="2">\n <episode airdate="27 September 2001" arc="none" number="1" title="Burked"/>\n <episode airdate="4 October 2001" arc="none" number="2" title="Chaos Theory"/>\n <episode airdate="11 October 2001" arc="none" number="3" title="Overload"/>\n <episode airdate="18 October 2001" arc="none" number="4" title="Bully for You"/>\n <episode airdate="25 October 2001" arc="none" number="5" title="Scuba Doobie-Doo"/>\n <episode airdate="1 November 2001" arc="none" number="6" title="Alter Boys"/>\n <episode airdate="8 November 2001" arc="none" number="7" title="Caged"/>\n <episode airdate="15 November 2001" arc="none" number="8" title="Slaves of Las Vegas"/>\n <episode airdate="22 November 2001" arc="none" number="9" title="And Then There Were None"/>\n <episode airdate="6 December 2001" arc="none" number="10" title="Ellie"/>\n <episode airdate="13 December 2001" arc="none" number="11" title="Organ Grinder"/>\n <episode airdate="20 December 2001" arc="none" number="12" title="You\'ve Got Male"/>\n <episode airdate="17 January 2002" arc="none" number="13" title="Identity Crisis"/>\n <episode airdate="None" arc="none" number="14" title="The Finger"/>\n <episode airdate="7 February 2002" arc="none" number="15" title="Burden of Proof"/>\n <episode airdate="28 February 2002" arc="none" number="16" title="Primum Non Nocere"/>\n <episode airdate="7 March 2002" arc="none" number="17" title="Felonious Monk"/>\n <episode airdate="28 March 2002" arc="none" number="18" title="Chasing the Bus"/>\n <episode airdate="4 April 2002" arc="none" number="19" title="Stalker"/>\n <episode airdate="25 April 2002" arc="none" number="20" title="Cats in the Cradle..."/>\n <episode airdate="2 May 2002" arc="none" number="21" title="Anatomy of a Lye"/>\n <episode airdate="9 May 2002" arc="none" number="22" title="Cross-Jurisdictions"/>\n <episode airdate="18 May 2002" arc="none" number="23" title="The Hunger Artist"/>\n </season>\n</tvshow>\n', 'csi.show') ] self.BaIf1.currentDB.write() DB211 = [] for filename in self.Tools.databaseFiles.values(): testfile = open(os.path.join(self.Tools.databaseDir, filename), "r") content = testfile.read() testfile.close() DB211.append((content, filename)) assert DB211 == [ ('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664" /><aliases><alias value="spaced" /></aliases><season number="2"><episode airdate="23 February 2001" arc="none" number="1" title="Back" /><episode airdate="2 March 2001" arc="none" number="2" title="Change" /><episode airdate="9 March 2001" arc="none" number="3" title="Mettle" /><episode airdate="23 March 2001" arc="none" number="4" title="Help" /><episode airdate="None" arc="none" number="5" title="Gone" /><episode airdate="6 April 2001" arc="none" number="6" title="Dissolution" /><episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt" /></season></tvshow>', 'spaced.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150" /><aliases><alias value="blackbooks" /><alias value="black books" /><alias value="black.books" /><alias value="bb" /></aliases><season number="1"><episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books" /><episode airdate="6 October 2000" arc="none" number="2" title="Manny's First Day" /><episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath" /><episode airdate="20 October 2000" arc="none" number="4" title="The Blackout" /><episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out" /><episode airdate="3 November 2000" arc="none" number="6" title="He's Leaving Home" /></season><season number="2"><episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer" /><episode airdate="8 March 2002" arc="none" number="2" title="Fever" /><episode airdate="15 March 2002" arc="none" number="3" title="The Fixer" /><episode airdate="22 March 2002" arc="none" number="4" title="Blood" /><episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun" /><episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change" /></season><season number="3"><episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home" /><episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens" /><episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa" /><episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter" /><episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer" /><episode airdate="15 April 2004" arc="none" number="6" title="Party" /></season></tvshow>', 'blackbooks.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="C.S.I" url="tt0247082" /><aliases><alias value="csi" /></aliases><season number="1"><episode airdate="6 October 2000" arc="none" number="1" title="Pilot" /><episode airdate="13 October 2000" arc="none" number="2" title="Cool Change" /><episode airdate="20 October 2000" arc="none" number="3" title="Crate 'n' Burial" /><episode airdate="27 October 2000" arc="none" number="4" title="Pledging Mr. Johnson" /><episode airdate="3 November 2000" arc="none" number="5" title="Friends & Lovers" /><episode airdate="10 November 2000" arc="none" number="6" title="Who Are You?" /><episode airdate="17 November 2000" arc="none" number="7" title="Blood Drops" /><episode airdate="24 November 2000" arc="none" number="8" title="Anonymous" /><episode airdate="8 December 2000" arc="none" number="9" title="Unfriendly Skies" /><episode airdate="22 December 2000" arc="none" number="10" title="Sex, Lies and Larvae" /><episode airdate="12 January 2001" arc="none" number="11" title="I-15 Murders" /><episode airdate="1 February 2001" arc="none" number="12" title="Fahrenheit 932" /><episode airdate="8 February 2001" arc="none" number="13" title="Boom" /><episode airdate="15 February 2001" arc="none" number="14" title="To Halve and to Hold" /><episode airdate="22 February 2001" arc="none" number="15" title="Table Stakes" /><episode airdate="1 March 2001" arc="none" number="16" title="Too Tough to Die" /><episode airdate="8 March 2001" arc="none" number="17" title="Face Lift" /><episode airdate="29 March 2001" arc="none" number="18" title="$35K O.B.O." /><episode airdate="12 April 2001" arc="none" number="19" title="Gentle, Gentle" /><episode airdate="19 April 2001" arc="none" number="20" title="Sounds of Silence" /><episode airdate="26 April 2001" arc="none" number="21" title="Justice Is Served" /><episode airdate="10 May 2001" arc="none" number="22" title="Evaluation Day" /><episode airdate="17 May 2001" arc="none" number="23" title="The Strip Strangler" /></season><season number="2"><episode airdate="27 September 2001" arc="none" number="1" title="Burked" /><episode airdate="4 October 2001" arc="none" number="2" title="Chaos Theory" /><episode airdate="11 October 2001" arc="none" number="3" title="Overload" /><episode airdate="18 October 2001" arc="none" number="4" title="Bully for You" /><episode airdate="25 October 2001" arc="none" number="5" title="Scuba Doobie-Doo" /><episode airdate="1 November 2001" arc="none" number="6" title="Alter Boys" /><episode airdate="8 November 2001" arc="none" number="7" title="Caged" /><episode airdate="15 November 2001" arc="none" number="8" title="Slaves of Las Vegas" /><episode airdate="22 November 2001" arc="none" number="9" title="And Then There Were None" /><episode airdate="6 December 2001" arc="none" number="10" title="Ellie" /><episode airdate="13 December 2001" arc="none" number="11" title="Organ Grinder" /><episode airdate="20 December 2001" arc="none" number="12" title="You've Got Male" /><episode airdate="17 January 2002" arc="none" number="13" title="Identity Crisis" /><episode airdate="None" arc="none" number="14" title="The Finger" /><episode airdate="7 February 2002" arc="none" number="15" title="Burden of Proof" /><episode airdate="28 February 2002" arc="none" number="16" title="Primum Non Nocere" /><episode airdate="7 March 2002" arc="none" number="17" title="Felonious Monk" /><episode airdate="28 March 2002" arc="none" number="18" title="Chasing the Bus" /><episode airdate="4 April 2002" arc="none" number="19" title="Stalker" /><episode airdate="25 April 2002" arc="none" number="20" title="Cats in the Cradle..." /><episode airdate="2 May 2002" arc="none" number="21" title="Anatomy of a Lye" /><episode airdate="9 May 2002" arc="none" number="22" title="Cross-Jurisdictions" /><episode airdate="18 May 2002" arc="none" number="23" title="The Hunger Artist" /></season></tvshow>', 'csi.show') ] self.BaIf1.currentDB.removeShow( Show('C.S.I', '60', 'imdbtvbackend', 'tt000000')) self.BaIf1.currentDB.delete( Show('C.S.I', '60', 'imdbtvbackend', 'tt000000')) #Tools.databaseFiles = {key : value for key, value in self.Tools.databaseFiles.items() if value is not 'csi.show'} temp_dict = dict() for key, value in self.Tools.databaseFiles.iteritems(): if value != 'csi.show': temp_dict[key] = value self.Tools.databaseFiles = temp_dict DB22 = [] for filename in self.Tools.databaseFiles.values(): testfile = open(os.path.join(self.Tools.databaseDir, filename), "r") content = testfile.read() testfile.close() DB22.append((content, filename)) assert DB22 == [ ('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664" /><aliases><alias value="spaced" /></aliases><season number="2"><episode airdate="23 February 2001" arc="none" number="1" title="Back" /><episode airdate="2 March 2001" arc="none" number="2" title="Change" /><episode airdate="9 March 2001" arc="none" number="3" title="Mettle" /><episode airdate="23 March 2001" arc="none" number="4" title="Help" /><episode airdate="None" arc="none" number="5" title="Gone" /><episode airdate="6 April 2001" arc="none" number="6" title="Dissolution" /><episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt" /></season></tvshow>', 'spaced.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150" /><aliases><alias value="blackbooks" /><alias value="black books" /><alias value="black.books" /><alias value="bb" /></aliases><season number="1"><episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books" /><episode airdate="6 October 2000" arc="none" number="2" title="Manny's First Day" /><episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath" /><episode airdate="20 October 2000" arc="none" number="4" title="The Blackout" /><episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out" /><episode airdate="3 November 2000" arc="none" number="6" title="He's Leaving Home" /></season><season number="2"><episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer" /><episode airdate="8 March 2002" arc="none" number="2" title="Fever" /><episode airdate="15 March 2002" arc="none" number="3" title="The Fixer" /><episode airdate="22 March 2002" arc="none" number="4" title="Blood" /><episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun" /><episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change" /></season><season number="3"><episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home" /><episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens" /><episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa" /><episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter" /><episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer" /><episode airdate="15 April 2004" arc="none" number="6" title="Party" /></season></tvshow>', 'blackbooks.show') ] self.BaIf1.updateDatabase() DB3 = [] for filename in self.Tools.databaseFiles.values(): testfile = open(os.path.join(self.Tools.databaseDir, filename), "r") content = testfile.read() testfile.close() DB3.append((content, filename)) assert DB3 == [ ('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664" /><aliases /><season number="1"><episode airdate="Sep. 24, 1999" arc="none" number="1" title="Beginnings" /><episode airdate="Oct. 1, 1999" arc="none" number="2" title="Gatherings" /><episode airdate="Oct. 8, 1999" arc="none" number="3" title="Art" /><episode airdate="Oct. 15, 1999" arc="none" number="4" title="Battles" /><episode airdate="Oct. 22, 1999" arc="none" number="5" title="Chaos" /><episode airdate="Oct. 29, 1999" arc="none" number="6" title="Epiphanies" /><episode airdate="Nov. 5, 1999" arc="none" number="7" title="Ends" /></season><season number="2"><episode airdate="23 February 2001" arc="none" number="1" title="Back" /><episode airdate="2 March 2001" arc="none" number="2" title="Change" /><episode airdate="9 March 2001" arc="none" number="3" title="Mettle" /><episode airdate="23 March 2001" arc="none" number="4" title="Help" /><episode airdate="None" arc="none" number="5" title="Gone" /><episode airdate="6 April 2001" arc="none" number="6" title="Dissolution" /><episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt" /></season></tvshow>', 'spaced.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150" /><aliases /><season number="1"><episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books" /><episode airdate="6 October 2000" arc="none" number="2" title="Manny's First Day" /><episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath" /><episode airdate="20 October 2000" arc="none" number="4" title="The Blackout" /><episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out" /><episode airdate="3 November 2000" arc="none" number="6" title="He's Leaving Home" /></season><season number="2"><episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer" /><episode airdate="8 March 2002" arc="none" number="2" title="Fever" /><episode airdate="15 March 2002" arc="none" number="3" title="The Fixer" /><episode airdate="22 March 2002" arc="none" number="4" title="Blood" /><episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun" /><episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change" /></season><season number="3"><episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home" /><episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens" /><episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa" /><episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter" /><episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer" /><episode airdate="15 April 2004" arc="none" number="6" title="Party" /></season></tvshow>', 'blackbooks.show') ] def testFillUpdateDB(self): assert os.path.exists(self.Tools.databaseDir) == True assert [(show.name, season.name, episode.name, episode.title) for show in self.BaIf1.currentDB.database for season in show.seasons for episode in season.episodes ] == [('C.S.I', '1', '1', 'Pilot'), ('C.S.I', '1', '2', 'Cool Change'), ('C.S.I', '1', '3', "Crate 'n' Burial"), ('C.S.I', '1', '4', 'Pledging Mr. Johnson'), ('C.S.I', '1', '5', 'Friends & Lovers'), ('C.S.I', '1', '6', 'Who Are You?'), ('C.S.I', '1', '7', 'Blood Drops'), ('C.S.I', '1', '8', 'Anonymous'), ('C.S.I', '1', '9', 'Unfriendly Skies'), ('C.S.I', '1', '10', 'Sex, Lies and Larvae'), ('C.S.I', '1', '11', 'I-15 Murders'), ('C.S.I', '1', '12', 'Fahrenheit 932'), ('C.S.I', '1', '13', 'Boom'), ('C.S.I', '1', '14', 'To Halve and to Hold'), ('C.S.I', '1', '15', 'Table Stakes'), ('C.S.I', '1', '16', 'Too Tough to Die'), ('C.S.I', '1', '17', 'Face Lift'), ('C.S.I', '1', '18', '$35K O.B.O.'), ('C.S.I', '1', '19', 'Gentle, Gentle'), ('C.S.I', '1', '20', 'Sounds of Silence'), ('C.S.I', '1', '21', 'Justice Is Served'), ('C.S.I', '1', '22', 'Evaluation Day'), ('C.S.I', '1', '23', 'The Strip Strangler'), ('C.S.I', '2', '1', 'Burked'), ('C.S.I', '2', '2', 'Chaos Theory'), ('C.S.I', '2', '3', 'Overload'), ('C.S.I', '2', '4', 'Bully for You'), ('C.S.I', '2', '5', 'Scuba Doobie-Doo'), ('C.S.I', '2', '6', 'Alter Boys'), ('C.S.I', '2', '7', 'Caged'), ('C.S.I', '2', '8', 'Slaves of Las Vegas'), ('C.S.I', '2', '9', 'And Then There Were None'), ('C.S.I', '2', '10', 'Ellie'), ('C.S.I', '2', '11', 'Organ Grinder'), ('C.S.I', '2', '12', "You've Got Male"), ('C.S.I', '2', '13', 'Identity Crisis'), ('C.S.I', '2', '14', 'The Finger'), ('C.S.I', '2', '15', 'Burden of Proof'), ('C.S.I', '2', '16', 'Primum Non Nocere'), ('C.S.I', '2', '17', 'Felonious Monk'), ('C.S.I', '2', '18', 'Chasing the Bus'), ('C.S.I', '2', '19', 'Stalker'), ('C.S.I', '2', '20', 'Cats in the Cradle...'), ('C.S.I', '2', '21', 'Anatomy of a Lye'), ('C.S.I', '2', '22', 'Cross-Jurisdictions'), ('C.S.I', '2', '23', 'The Hunger Artist'), ('Spaced', '1', '1', 'Beginnings'), ('Spaced', '1', '2', 'Gatherings'), ('Spaced', '1', '3', 'Art'), ('Spaced', '1', '4', 'Battles'), ('Spaced', '1', '5', 'Chaos'), ('Spaced', '1', '6', 'Epiphanies'), ('Spaced', '1', '7', 'Ends'), ('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] show1 = self.BaIf1.currentDB.getShow( Show('Spaced', '30', 'imdbtvbackend', 'tt000000')) show1.removeSeason(Season('1')) assert [(show.name, season.name, episode.name, episode.title) for show in self.BaIf1.currentDB.database for season in show.seasons for episode in season.episodes ] == [('C.S.I', '1', '1', 'Pilot'), ('C.S.I', '1', '2', 'Cool Change'), ('C.S.I', '1', '3', "Crate 'n' Burial"), ('C.S.I', '1', '4', 'Pledging Mr. Johnson'), ('C.S.I', '1', '5', 'Friends & Lovers'), ('C.S.I', '1', '6', 'Who Are You?'), ('C.S.I', '1', '7', 'Blood Drops'), ('C.S.I', '1', '8', 'Anonymous'), ('C.S.I', '1', '9', 'Unfriendly Skies'), ('C.S.I', '1', '10', 'Sex, Lies and Larvae'), ('C.S.I', '1', '11', 'I-15 Murders'), ('C.S.I', '1', '12', 'Fahrenheit 932'), ('C.S.I', '1', '13', 'Boom'), ('C.S.I', '1', '14', 'To Halve and to Hold'), ('C.S.I', '1', '15', 'Table Stakes'), ('C.S.I', '1', '16', 'Too Tough to Die'), ('C.S.I', '1', '17', 'Face Lift'), ('C.S.I', '1', '18', '$35K O.B.O.'), ('C.S.I', '1', '19', 'Gentle, Gentle'), ('C.S.I', '1', '20', 'Sounds of Silence'), ('C.S.I', '1', '21', 'Justice Is Served'), ('C.S.I', '1', '22', 'Evaluation Day'), ('C.S.I', '1', '23', 'The Strip Strangler'), ('C.S.I', '2', '1', 'Burked'), ('C.S.I', '2', '2', 'Chaos Theory'), ('C.S.I', '2', '3', 'Overload'), ('C.S.I', '2', '4', 'Bully for You'), ('C.S.I', '2', '5', 'Scuba Doobie-Doo'), ('C.S.I', '2', '6', 'Alter Boys'), ('C.S.I', '2', '7', 'Caged'), ('C.S.I', '2', '8', 'Slaves of Las Vegas'), ('C.S.I', '2', '9', 'And Then There Were None'), ('C.S.I', '2', '10', 'Ellie'), ('C.S.I', '2', '11', 'Organ Grinder'), ('C.S.I', '2', '12', "You've Got Male"), ('C.S.I', '2', '13', 'Identity Crisis'), ('C.S.I', '2', '14', 'The Finger'), ('C.S.I', '2', '15', 'Burden of Proof'), ('C.S.I', '2', '16', 'Primum Non Nocere'), ('C.S.I', '2', '17', 'Felonious Monk'), ('C.S.I', '2', '18', 'Chasing the Bus'), ('C.S.I', '2', '19', 'Stalker'), ('C.S.I', '2', '20', 'Cats in the Cradle...'), ('C.S.I', '2', '21', 'Anatomy of a Lye'), ('C.S.I', '2', '22', 'Cross-Jurisdictions'), ('C.S.I', '2', '23', 'The Hunger Artist'), ('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] self.BaIf1.currentDB.removeShow( Show('C.S.I', '60', 'imdbtvbackend', 'tt000000')) assert [(show.name, season.name, episode.name, episode.title) for show in self.BaIf1.currentDB.database for season in show.seasons for episode in season.episodes ] == [('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] print self.BaIf1.dbDir self.BaIf1.updateDB.printDb() self.BaIf1.fillUpdateDB() self.BaIf1.updateDB.printDb() self.BaIf1.currentDB.printDb() self.BaIf1.mergeDB.printDb() assert [ (show.name, season.name, episode.name, episode.title) for show in self.BaIf1.mergeDB.database for season in show.seasons for episode in season.episodes ] == [('Spaced', '1', '1', 'Beginnings'), ('Spaced', '1', '2', 'Gatherings'), ('Spaced', '1', '3', 'Art'), ('Spaced', '1', '4', 'Battles'), ('Spaced', '1', '5', 'Chaos'), ('Spaced', '1', '6', 'Epiphanies'), ('Spaced', '1', '7', 'Ends'), ('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] def testCompareDetails(self): Episode1 = Episode("2", "What A Title", "6 November, 2008") Episode2 = Episode("333", "For A TV Show", "18 November, 2008") Episode3 = Episode("4", "What A Title", "6 November, 2008") Episode4 = Episode("2", "What A Title", "6 November, 2008") Episode5 = Episode("333", "For A TV Show", "18 November, 2008") Episode6 = Episode("4", "What A Title", "6 November, 2008") Season1 = Season('1') Season2 = Season('2') Season1.addEpisode(Episode1) Season1.addEpisode(Episode2) Season1.addEpisode(Episode3) Season2.addEpisode(Episode4) Season2.addEpisode(Episode5) Season2.addEpisode(Episode6) Season3 = Season1 Season4 = Season2 Show1 = Show("Test Show One", "60", "dummybackend", "dummyurlone") Show2 = Show("Test Show Two", "60", "dummybackend", "dummyurltwo") Show3 = Show1 Show1.addSeason(Season1) Show1.addSeason(Season2) Show2.addSeason(Season3) Show2.addSeason(Season4) s = self.BaIf1.compareDetails(Show1, Show2) assert (s.name, s.duration, s.backend, s.url) == ("Test Show One", "60", "dummybackend", "dummyurlone") s = self.BaIf1.compareDetails(Show1, Show2) assert (s.name, s.duration, s.backend, s.url) == ("Test Show One", "60", "dummybackend", "dummyurlone") def testCompareSeasons(self): Episode1 = Episode("2", "What A Title", "6 November, 2008") Episode2 = Episode("333", "For A TV Show", "18 November, 2008") Episode3 = Episode("4", "What A Title", "6 November, 2008") Episode4 = Episode("2", "What A Title", "6 November, 2008") Episode5 = Episode("333", "For A TV Show", "18 November, 2008") Episode6 = Episode("4", "What A Title", "6 November, 2008") Season1 = Season('1') Season2 = Season('2') Season1.addEpisode(Episode1) Season1.addEpisode(Episode2) Season1.addEpisode(Episode3) Season2.addEpisode(Episode4) Season2.addEpisode(Episode5) Season2.addEpisode(Episode6) assert self.BaIf1.compareSeasons(Season1, Season2).name == "1" assert self.BaIf1.compareSeasons(Season1, Season2).name == "1" def testCompareEpisodes(self): Episode1 = Episode("2", "What A Title", "6 November, 2008") Episode2 = Episode( "2", "For A TV Show", "6 November, 2008" ) # Gives NotImplemented Error, which is correct behaviour. Episode3 = Episode("2", "What A Title", "6 November, 2008") e = self.BaIf1.compareEpisodes(Episode1, Episode1) (e.name, e.title, e.airdate) == ("2", "What A Title", "6 November, 2008")
class testDatabase : """ Test Database Class """ def setUp(self) : self.Tools = Tools() self.Tools.createRootDir() self.Tools.createDatabaseFiles() self.database = Database(self.Tools.databaseDir) def tearDown(self): self.Tools.removeTempFiles() def testLoadDB(self) : assert self.database.database == [ ] self.database.loadDB() assert [ ( show.name, season.name, episode.name, episode.title ) for show in self.database.database for season in show.seasons for episode in season.episodes ] == [('C.S.I', '1', '1', 'Pilot'), ('C.S.I', '1', '2', 'Cool Change'), ('C.S.I', '1', '3', "Crate 'n' Burial"), ('C.S.I', '1', '4', 'Pledging Mr. Johnson'), ('C.S.I', '1', '5', 'Friends & Lovers'), ('C.S.I', '1', '6', 'Who Are You?'), ('C.S.I', '1', '7', 'Blood Drops'), ('C.S.I', '1', '8', 'Anonymous'), ('C.S.I', '1', '9', 'Unfriendly Skies'), ('C.S.I', '1', '10', 'Sex, Lies and Larvae'), ('C.S.I', '1', '11', 'I-15 Murders'), ('C.S.I', '1', '12', 'Fahrenheit 932'), ('C.S.I', '1', '13', 'Boom'), ('C.S.I', '1', '14', 'To Halve and to Hold'), ('C.S.I', '1', '15', 'Table Stakes'), ('C.S.I', '1', '16', 'Too Tough to Die'), ('C.S.I', '1', '17', 'Face Lift'), ('C.S.I', '1', '18', '$35K O.B.O.'), ('C.S.I', '1', '19', 'Gentle, Gentle'), ('C.S.I', '1', '20', 'Sounds of Silence'), ('C.S.I', '1', '21', 'Justice Is Served'), ('C.S.I', '1', '22', 'Evaluation Day'), ('C.S.I', '1', '23', 'The Strip Strangler'), ('C.S.I', '2', '1', 'Burked'), ('C.S.I', '2', '2', 'Chaos Theory'), ('C.S.I', '2', '3', 'Overload'), ('C.S.I', '2', '4', 'Bully for You'), ('C.S.I', '2', '5', 'Scuba Doobie-Doo'), ('C.S.I', '2', '6', 'Alter Boys'), ('C.S.I', '2', '7', 'Caged'), ('C.S.I', '2', '8', 'Slaves of Las Vegas'), ('C.S.I', '2', '9', 'And Then There Were None'), ('C.S.I', '2', '10', 'Ellie'), ('C.S.I', '2', '11', 'Organ Grinder'), ('C.S.I', '2', '12', "You've Got Male"), ('C.S.I', '2', '13', 'Identity Crisis'), ('C.S.I', '2', '14', 'The Finger'), ('C.S.I', '2', '15', 'Burden of Proof'), ('C.S.I', '2', '16', 'Primum Non Nocere'), ('C.S.I', '2', '17', 'Felonious Monk'), ('C.S.I', '2', '18', 'Chasing the Bus'), ('C.S.I', '2', '19', 'Stalker'), ('C.S.I', '2', '20', 'Cats in the Cradle...'), ('C.S.I', '2', '21', 'Anatomy of a Lye'), ('C.S.I', '2', '22', 'Cross-Jurisdictions'), ('C.S.I', '2', '23', 'The Hunger Artist'), ('Spaced', '1', '1', 'Beginnings'), ('Spaced', '1', '2', 'Gatherings'), ('Spaced', '1', '3', 'Art'), ('Spaced', '1', '4', 'Battles'), ('Spaced', '1', '5', 'Chaos'), ('Spaced', '1', '6', 'Epiphanies'), ('Spaced', '1', '7', 'Ends'), ('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] os.remove( os.path.join( self.Tools.databaseDir , 'csi.show' )) self.database.loadDB() assert [ ( show.name, season.name, episode.name, episode.title ) for show in self.database.database for season in show.seasons for episode in season.episodes ] == [('Spaced', '1', '1', 'Beginnings'), ('Spaced', '1', '2', 'Gatherings'), ('Spaced', '1', '3', 'Art'), ('Spaced', '1', '4', 'Battles'), ('Spaced', '1', '5', 'Chaos'), ('Spaced', '1', '6', 'Epiphanies'), ('Spaced', '1', '7', 'Ends'), ('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] def testAddShow(self) : Show1 = Show( "Test Show One", "60", "dummybackend", "dummyurlone" ) Show2 = Show( "Test Show Two", "60", "dummybackend", "dummyurltwo" ) Show3 = Show( "Test Show Three", "60", "dummybackend", "dummyurlthree" ) assert self.database.addShow( Show1 ) == Show1 assert self.database.addShow( Show1 ) == None assert self.database.addShow( Show2 ) == Show2 assert self.database.addShow( Show( "Test Show Two", "60", "dummybackend", "dummyurltwo" )) == None assert self.database.addShow( Show3 ) == Show3 def testGetShow(self) : Show1 = Show( "Test Show One", "60", "dummybackend", "dummyurlone" ) Show2 = Show( "Test Show Two", "60", "dummybackend", "dummyurltwo" ) Show3 = Show( "Test Show Three", "60", "dummybackend", "dummyurlthree" ) self.database.addShow( Show1 ) self.database.addShow( Show2 ) assert self.database.getShow( Show1 ) == Show1 assert self.database.getShow( Show3 ) == None assert self.database.getShow( Show( "Test Show Two", "60", "dummybackend", "dummyurltwo" ) ) == Show2 assert self.database.getShow( Show( "Test Show Three", "60", "dummybackend", "dummyurlthree" ) ) == None def testRemoveShow(self) : Show1 = Show( "Test Show One", "60", "dummybackend", "dummyurlone" ) Show2 = Show( "Test Show Two", "60", "dummybackend", "dummyurltwo" ) Show3 = Show( "Test Show Three", "60", "dummybackend", "dummyurlthree" ) self.database.addShow( Show1 ) self.database.addShow( Show2 ) assert self.database.removeShow( Show1 ) == Show1 assert self.database.removeShow( Show1 ) == None assert self.database.removeShow( Show( "Test Show Three", "60", "dummybackend", "dummyurlthree" ) ) == None assert self.database.removeShow( Show( "Test Show Two", "60", "dummybackend", "dummyurltwo" ) ) == Show2 def testWrite(self) : assert self.database.write() == [] self.database.loadDB() assert [ ( show.name, season.name, episode.name, episode.title ) for show in self.database.write() for season in show.seasons for episode in season.episodes ] == [('C.S.I', '1', '1', 'Pilot'), ('C.S.I', '1', '2', 'Cool Change'), ('C.S.I', '1', '3', "Crate 'n' Burial"), ('C.S.I', '1', '4', 'Pledging Mr. Johnson'), ('C.S.I', '1', '5', 'Friends & Lovers'), ('C.S.I', '1', '6', 'Who Are You?'), ('C.S.I', '1', '7', 'Blood Drops'), ('C.S.I', '1', '8', 'Anonymous'), ('C.S.I', '1', '9', 'Unfriendly Skies'), ('C.S.I', '1', '10', 'Sex, Lies and Larvae'), ('C.S.I', '1', '11', 'I-15 Murders'), ('C.S.I', '1', '12', 'Fahrenheit 932'), ('C.S.I', '1', '13', 'Boom'), ('C.S.I', '1', '14', 'To Halve and to Hold'), ('C.S.I', '1', '15', 'Table Stakes'), ('C.S.I', '1', '16', 'Too Tough to Die'), ('C.S.I', '1', '17', 'Face Lift'), ('C.S.I', '1', '18', '$35K O.B.O.'), ('C.S.I', '1', '19', 'Gentle, Gentle'), ('C.S.I', '1', '20', 'Sounds of Silence'), ('C.S.I', '1', '21', 'Justice Is Served'), ('C.S.I', '1', '22', 'Evaluation Day'), ('C.S.I', '1', '23', 'The Strip Strangler'), ('C.S.I', '2', '1', 'Burked'), ('C.S.I', '2', '2', 'Chaos Theory'), ('C.S.I', '2', '3', 'Overload'), ('C.S.I', '2', '4', 'Bully for You'), ('C.S.I', '2', '5', 'Scuba Doobie-Doo'), ('C.S.I', '2', '6', 'Alter Boys'), ('C.S.I', '2', '7', 'Caged'), ('C.S.I', '2', '8', 'Slaves of Las Vegas'), ('C.S.I', '2', '9', 'And Then There Were None'), ('C.S.I', '2', '10', 'Ellie'), ('C.S.I', '2', '11', 'Organ Grinder'), ('C.S.I', '2', '12', "You've Got Male"), ('C.S.I', '2', '13', 'Identity Crisis'), ('C.S.I', '2', '14', 'The Finger'), ('C.S.I', '2', '15', 'Burden of Proof'), ('C.S.I', '2', '16', 'Primum Non Nocere'), ('C.S.I', '2', '17', 'Felonious Monk'), ('C.S.I', '2', '18', 'Chasing the Bus'), ('C.S.I', '2', '19', 'Stalker'), ('C.S.I', '2', '20', 'Cats in the Cradle...'), ('C.S.I', '2', '21', 'Anatomy of a Lye'), ('C.S.I', '2', '22', 'Cross-Jurisdictions'), ('C.S.I', '2', '23', 'The Hunger Artist'), ('Spaced', '1', '1', 'Beginnings'), ('Spaced', '1', '2', 'Gatherings'), ('Spaced', '1', '3', 'Art'), ('Spaced', '1', '4', 'Battles'), ('Spaced', '1', '5', 'Chaos'), ('Spaced', '1', '6', 'Epiphanies'), ('Spaced', '1', '7', 'Ends'), ('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] assert os.path.exists(self.Tools.databaseDir) == True DB2 = [ ] for filename in self.Tools.databaseFiles.values() : testfile = open(os.path.join( self.Tools.databaseDir, filename ),"r") content = testfile.read() testfile.close() DB2.append( ( content , filename ) ) assert DB2 == [('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664" /><aliases><alias value="spaced" /></aliases><season number="1"><episode airdate="24 September 1999" arc="none" number="1" title="Beginnings" /><episode airdate="1 October 1999" arc="none" number="2" title="Gatherings" /><episode airdate="8 October 1999" arc="none" number="3" title="Art" /><episode airdate="15 October 1999" arc="none" number="4" title="Battles" /><episode airdate="22 October 1999" arc="none" number="5" title="Chaos" /><episode airdate="29 October 1999" arc="none" number="6" title="Epiphanies" /><episode airdate="5 November 1999" arc="none" number="7" title="Ends" /></season><season number="2"><episode airdate="23 February 2001" arc="none" number="1" title="Back" /><episode airdate="2 March 2001" arc="none" number="2" title="Change" /><episode airdate="9 March 2001" arc="none" number="3" title="Mettle" /><episode airdate="23 March 2001" arc="none" number="4" title="Help" /><episode airdate="None" arc="none" number="5" title="Gone" /><episode airdate="6 April 2001" arc="none" number="6" title="Dissolution" /><episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt" /></season></tvshow>', 'spaced.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150" /><aliases><alias value="blackbooks" /><alias value="black books" /><alias value="black.books" /><alias value="bb" /></aliases><season number="1"><episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books" /><episode airdate="6 October 2000" arc="none" number="2" title="Manny's First Day" /><episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath" /><episode airdate="20 October 2000" arc="none" number="4" title="The Blackout" /><episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out" /><episode airdate="3 November 2000" arc="none" number="6" title="He's Leaving Home" /></season><season number="2"><episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer" /><episode airdate="8 March 2002" arc="none" number="2" title="Fever" /><episode airdate="15 March 2002" arc="none" number="3" title="The Fixer" /><episode airdate="22 March 2002" arc="none" number="4" title="Blood" /><episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun" /><episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change" /></season><season number="3"><episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home" /><episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens" /><episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa" /><episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter" /><episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer" /><episode airdate="15 April 2004" arc="none" number="6" title="Party" /></season></tvshow>', 'blackbooks.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="C.S.I" url="tt0247082" /><aliases><alias value="csi" /></aliases><season number="1"><episode airdate="6 October 2000" arc="none" number="1" title="Pilot" /><episode airdate="13 October 2000" arc="none" number="2" title="Cool Change" /><episode airdate="20 October 2000" arc="none" number="3" title="Crate 'n' Burial" /><episode airdate="27 October 2000" arc="none" number="4" title="Pledging Mr. Johnson" /><episode airdate="3 November 2000" arc="none" number="5" title="Friends & Lovers" /><episode airdate="10 November 2000" arc="none" number="6" title="Who Are You?" /><episode airdate="17 November 2000" arc="none" number="7" title="Blood Drops" /><episode airdate="24 November 2000" arc="none" number="8" title="Anonymous" /><episode airdate="8 December 2000" arc="none" number="9" title="Unfriendly Skies" /><episode airdate="22 December 2000" arc="none" number="10" title="Sex, Lies and Larvae" /><episode airdate="12 January 2001" arc="none" number="11" title="I-15 Murders" /><episode airdate="1 February 2001" arc="none" number="12" title="Fahrenheit 932" /><episode airdate="8 February 2001" arc="none" number="13" title="Boom" /><episode airdate="15 February 2001" arc="none" number="14" title="To Halve and to Hold" /><episode airdate="22 February 2001" arc="none" number="15" title="Table Stakes" /><episode airdate="1 March 2001" arc="none" number="16" title="Too Tough to Die" /><episode airdate="8 March 2001" arc="none" number="17" title="Face Lift" /><episode airdate="29 March 2001" arc="none" number="18" title="$35K O.B.O." /><episode airdate="12 April 2001" arc="none" number="19" title="Gentle, Gentle" /><episode airdate="19 April 2001" arc="none" number="20" title="Sounds of Silence" /><episode airdate="26 April 2001" arc="none" number="21" title="Justice Is Served" /><episode airdate="10 May 2001" arc="none" number="22" title="Evaluation Day" /><episode airdate="17 May 2001" arc="none" number="23" title="The Strip Strangler" /></season><season number="2"><episode airdate="27 September 2001" arc="none" number="1" title="Burked" /><episode airdate="4 October 2001" arc="none" number="2" title="Chaos Theory" /><episode airdate="11 October 2001" arc="none" number="3" title="Overload" /><episode airdate="18 October 2001" arc="none" number="4" title="Bully for You" /><episode airdate="25 October 2001" arc="none" number="5" title="Scuba Doobie-Doo" /><episode airdate="1 November 2001" arc="none" number="6" title="Alter Boys" /><episode airdate="8 November 2001" arc="none" number="7" title="Caged" /><episode airdate="15 November 2001" arc="none" number="8" title="Slaves of Las Vegas" /><episode airdate="22 November 2001" arc="none" number="9" title="And Then There Were None" /><episode airdate="6 December 2001" arc="none" number="10" title="Ellie" /><episode airdate="13 December 2001" arc="none" number="11" title="Organ Grinder" /><episode airdate="20 December 2001" arc="none" number="12" title="You've Got Male" /><episode airdate="17 January 2002" arc="none" number="13" title="Identity Crisis" /><episode airdate="None" arc="none" number="14" title="The Finger" /><episode airdate="7 February 2002" arc="none" number="15" title="Burden of Proof" /><episode airdate="28 February 2002" arc="none" number="16" title="Primum Non Nocere" /><episode airdate="7 March 2002" arc="none" number="17" title="Felonious Monk" /><episode airdate="28 March 2002" arc="none" number="18" title="Chasing the Bus" /><episode airdate="4 April 2002" arc="none" number="19" title="Stalker" /><episode airdate="25 April 2002" arc="none" number="20" title="Cats in the Cradle..." /><episode airdate="2 May 2002" arc="none" number="21" title="Anatomy of a Lye" /><episode airdate="9 May 2002" arc="none" number="22" title="Cross-Jurisdictions" /><episode airdate="18 May 2002" arc="none" number="23" title="The Hunger Artist" /></season></tvshow>', 'csi.show')] show1 = self.database.getShow( Show('Spaced', '30', 'imdbtvbackend', 'tt000000') ) show1.addEpisode( Episode( '8', 'New Test Episode', '8 January 2009', 'none' ) , Season('2') ) assert [ ( show.name, season.name, episode.name, episode.title ) for show in self.database.write() for season in show.seasons for episode in season.episodes ] == [('C.S.I', '1', '1', 'Pilot'), ('C.S.I', '1', '2', 'Cool Change'), ('C.S.I', '1', '3', "Crate 'n' Burial"), ('C.S.I', '1', '4', 'Pledging Mr. Johnson'), ('C.S.I', '1', '5', 'Friends & Lovers'), ('C.S.I', '1', '6', 'Who Are You?'), ('C.S.I', '1', '7', 'Blood Drops'), ('C.S.I', '1', '8', 'Anonymous'), ('C.S.I', '1', '9', 'Unfriendly Skies'), ('C.S.I', '1', '10', 'Sex, Lies and Larvae'), ('C.S.I', '1', '11', 'I-15 Murders'), ('C.S.I', '1', '12', 'Fahrenheit 932'), ('C.S.I', '1', '13', 'Boom'), ('C.S.I', '1', '14', 'To Halve and to Hold'), ('C.S.I', '1', '15', 'Table Stakes'), ('C.S.I', '1', '16', 'Too Tough to Die'), ('C.S.I', '1', '17', 'Face Lift'), ('C.S.I', '1', '18', '$35K O.B.O.'), ('C.S.I', '1', '19', 'Gentle, Gentle'), ('C.S.I', '1', '20', 'Sounds of Silence'), ('C.S.I', '1', '21', 'Justice Is Served'), ('C.S.I', '1', '22', 'Evaluation Day'), ('C.S.I', '1', '23', 'The Strip Strangler'), ('C.S.I', '2', '1', 'Burked'), ('C.S.I', '2', '2', 'Chaos Theory'), ('C.S.I', '2', '3', 'Overload'), ('C.S.I', '2', '4', 'Bully for You'), ('C.S.I', '2', '5', 'Scuba Doobie-Doo'), ('C.S.I', '2', '6', 'Alter Boys'), ('C.S.I', '2', '7', 'Caged'), ('C.S.I', '2', '8', 'Slaves of Las Vegas'), ('C.S.I', '2', '9', 'And Then There Were None'), ('C.S.I', '2', '10', 'Ellie'), ('C.S.I', '2', '11', 'Organ Grinder'), ('C.S.I', '2', '12', "You've Got Male"), ('C.S.I', '2', '13', 'Identity Crisis'), ('C.S.I', '2', '14', 'The Finger'), ('C.S.I', '2', '15', 'Burden of Proof'), ('C.S.I', '2', '16', 'Primum Non Nocere'), ('C.S.I', '2', '17', 'Felonious Monk'), ('C.S.I', '2', '18', 'Chasing the Bus'), ('C.S.I', '2', '19', 'Stalker'), ('C.S.I', '2', '20', 'Cats in the Cradle...'), ('C.S.I', '2', '21', 'Anatomy of a Lye'), ('C.S.I', '2', '22', 'Cross-Jurisdictions'), ('C.S.I', '2', '23', 'The Hunger Artist'), ('Spaced', '1', '1', 'Beginnings'), ('Spaced', '1', '2', 'Gatherings'), ('Spaced', '1', '3', 'Art'), ('Spaced', '1', '4', 'Battles'), ('Spaced', '1', '5', 'Chaos'), ('Spaced', '1', '6', 'Epiphanies'), ('Spaced', '1', '7', 'Ends'), ('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Spaced', '2', '8', 'New Test Episode'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] DB3 = [ ] for filename in self.Tools.databaseFiles.values() : testfile = open(os.path.join( self.Tools.databaseDir, filename ),"r") content = testfile.read() testfile.close() DB3.append( ( content , filename ) ) assert DB3 == [('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664" /><aliases><alias value="spaced" /></aliases><season number="1"><episode airdate="24 September 1999" arc="none" number="1" title="Beginnings" /><episode airdate="1 October 1999" arc="none" number="2" title="Gatherings" /><episode airdate="8 October 1999" arc="none" number="3" title="Art" /><episode airdate="15 October 1999" arc="none" number="4" title="Battles" /><episode airdate="22 October 1999" arc="none" number="5" title="Chaos" /><episode airdate="29 October 1999" arc="none" number="6" title="Epiphanies" /><episode airdate="5 November 1999" arc="none" number="7" title="Ends" /></season><season number="2"><episode airdate="23 February 2001" arc="none" number="1" title="Back" /><episode airdate="2 March 2001" arc="none" number="2" title="Change" /><episode airdate="9 March 2001" arc="none" number="3" title="Mettle" /><episode airdate="23 March 2001" arc="none" number="4" title="Help" /><episode airdate="None" arc="none" number="5" title="Gone" /><episode airdate="6 April 2001" arc="none" number="6" title="Dissolution" /><episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt" /><episode airdate="8 January 2009" arc="none" number="8" title="New Test Episode" /></season></tvshow>', 'spaced.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150" /><aliases><alias value="blackbooks" /><alias value="black books" /><alias value="black.books" /><alias value="bb" /></aliases><season number="1"><episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books" /><episode airdate="6 October 2000" arc="none" number="2" title="Manny's First Day" /><episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath" /><episode airdate="20 October 2000" arc="none" number="4" title="The Blackout" /><episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out" /><episode airdate="3 November 2000" arc="none" number="6" title="He's Leaving Home" /></season><season number="2"><episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer" /><episode airdate="8 March 2002" arc="none" number="2" title="Fever" /><episode airdate="15 March 2002" arc="none" number="3" title="The Fixer" /><episode airdate="22 March 2002" arc="none" number="4" title="Blood" /><episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun" /><episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change" /></season><season number="3"><episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home" /><episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens" /><episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa" /><episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter" /><episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer" /><episode airdate="15 April 2004" arc="none" number="6" title="Party" /></season></tvshow>', 'blackbooks.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="C.S.I" url="tt0247082" /><aliases><alias value="csi" /></aliases><season number="1"><episode airdate="6 October 2000" arc="none" number="1" title="Pilot" /><episode airdate="13 October 2000" arc="none" number="2" title="Cool Change" /><episode airdate="20 October 2000" arc="none" number="3" title="Crate 'n' Burial" /><episode airdate="27 October 2000" arc="none" number="4" title="Pledging Mr. Johnson" /><episode airdate="3 November 2000" arc="none" number="5" title="Friends & Lovers" /><episode airdate="10 November 2000" arc="none" number="6" title="Who Are You?" /><episode airdate="17 November 2000" arc="none" number="7" title="Blood Drops" /><episode airdate="24 November 2000" arc="none" number="8" title="Anonymous" /><episode airdate="8 December 2000" arc="none" number="9" title="Unfriendly Skies" /><episode airdate="22 December 2000" arc="none" number="10" title="Sex, Lies and Larvae" /><episode airdate="12 January 2001" arc="none" number="11" title="I-15 Murders" /><episode airdate="1 February 2001" arc="none" number="12" title="Fahrenheit 932" /><episode airdate="8 February 2001" arc="none" number="13" title="Boom" /><episode airdate="15 February 2001" arc="none" number="14" title="To Halve and to Hold" /><episode airdate="22 February 2001" arc="none" number="15" title="Table Stakes" /><episode airdate="1 March 2001" arc="none" number="16" title="Too Tough to Die" /><episode airdate="8 March 2001" arc="none" number="17" title="Face Lift" /><episode airdate="29 March 2001" arc="none" number="18" title="$35K O.B.O." /><episode airdate="12 April 2001" arc="none" number="19" title="Gentle, Gentle" /><episode airdate="19 April 2001" arc="none" number="20" title="Sounds of Silence" /><episode airdate="26 April 2001" arc="none" number="21" title="Justice Is Served" /><episode airdate="10 May 2001" arc="none" number="22" title="Evaluation Day" /><episode airdate="17 May 2001" arc="none" number="23" title="The Strip Strangler" /></season><season number="2"><episode airdate="27 September 2001" arc="none" number="1" title="Burked" /><episode airdate="4 October 2001" arc="none" number="2" title="Chaos Theory" /><episode airdate="11 October 2001" arc="none" number="3" title="Overload" /><episode airdate="18 October 2001" arc="none" number="4" title="Bully for You" /><episode airdate="25 October 2001" arc="none" number="5" title="Scuba Doobie-Doo" /><episode airdate="1 November 2001" arc="none" number="6" title="Alter Boys" /><episode airdate="8 November 2001" arc="none" number="7" title="Caged" /><episode airdate="15 November 2001" arc="none" number="8" title="Slaves of Las Vegas" /><episode airdate="22 November 2001" arc="none" number="9" title="And Then There Were None" /><episode airdate="6 December 2001" arc="none" number="10" title="Ellie" /><episode airdate="13 December 2001" arc="none" number="11" title="Organ Grinder" /><episode airdate="20 December 2001" arc="none" number="12" title="You've Got Male" /><episode airdate="17 January 2002" arc="none" number="13" title="Identity Crisis" /><episode airdate="None" arc="none" number="14" title="The Finger" /><episode airdate="7 February 2002" arc="none" number="15" title="Burden of Proof" /><episode airdate="28 February 2002" arc="none" number="16" title="Primum Non Nocere" /><episode airdate="7 March 2002" arc="none" number="17" title="Felonious Monk" /><episode airdate="28 March 2002" arc="none" number="18" title="Chasing the Bus" /><episode airdate="4 April 2002" arc="none" number="19" title="Stalker" /><episode airdate="25 April 2002" arc="none" number="20" title="Cats in the Cradle..." /><episode airdate="2 May 2002" arc="none" number="21" title="Anatomy of a Lye" /><episode airdate="9 May 2002" arc="none" number="22" title="Cross-Jurisdictions" /><episode airdate="18 May 2002" arc="none" number="23" title="The Hunger Artist" /></season></tvshow>', 'csi.show')] show1 = self.database.getShow( Show('Spaced', '30', 'imdbtvbackend', 'tt000000') ) show1.removeSeason( Season('1') ) assert [ ( show.name, season.name, episode.name, episode.title ) for show in self.database.write() for season in show.seasons for episode in season.episodes ] == [('C.S.I', '1', '1', 'Pilot'), ('C.S.I', '1', '2', 'Cool Change'), ('C.S.I', '1', '3', "Crate 'n' Burial"), ('C.S.I', '1', '4', 'Pledging Mr. Johnson'), ('C.S.I', '1', '5', 'Friends & Lovers'), ('C.S.I', '1', '6', 'Who Are You?'), ('C.S.I', '1', '7', 'Blood Drops'), ('C.S.I', '1', '8', 'Anonymous'), ('C.S.I', '1', '9', 'Unfriendly Skies'), ('C.S.I', '1', '10', 'Sex, Lies and Larvae'), ('C.S.I', '1', '11', 'I-15 Murders'), ('C.S.I', '1', '12', 'Fahrenheit 932'), ('C.S.I', '1', '13', 'Boom'), ('C.S.I', '1', '14', 'To Halve and to Hold'), ('C.S.I', '1', '15', 'Table Stakes'), ('C.S.I', '1', '16', 'Too Tough to Die'), ('C.S.I', '1', '17', 'Face Lift'), ('C.S.I', '1', '18', '$35K O.B.O.'), ('C.S.I', '1', '19', 'Gentle, Gentle'), ('C.S.I', '1', '20', 'Sounds of Silence'), ('C.S.I', '1', '21', 'Justice Is Served'), ('C.S.I', '1', '22', 'Evaluation Day'), ('C.S.I', '1', '23', 'The Strip Strangler'), ('C.S.I', '2', '1', 'Burked'), ('C.S.I', '2', '2', 'Chaos Theory'), ('C.S.I', '2', '3', 'Overload'), ('C.S.I', '2', '4', 'Bully for You'), ('C.S.I', '2', '5', 'Scuba Doobie-Doo'), ('C.S.I', '2', '6', 'Alter Boys'), ('C.S.I', '2', '7', 'Caged'), ('C.S.I', '2', '8', 'Slaves of Las Vegas'), ('C.S.I', '2', '9', 'And Then There Were None'), ('C.S.I', '2', '10', 'Ellie'), ('C.S.I', '2', '11', 'Organ Grinder'), ('C.S.I', '2', '12', "You've Got Male"), ('C.S.I', '2', '13', 'Identity Crisis'), ('C.S.I', '2', '14', 'The Finger'), ('C.S.I', '2', '15', 'Burden of Proof'), ('C.S.I', '2', '16', 'Primum Non Nocere'), ('C.S.I', '2', '17', 'Felonious Monk'), ('C.S.I', '2', '18', 'Chasing the Bus'), ('C.S.I', '2', '19', 'Stalker'), ('C.S.I', '2', '20', 'Cats in the Cradle...'), ('C.S.I', '2', '21', 'Anatomy of a Lye'), ('C.S.I', '2', '22', 'Cross-Jurisdictions'), ('C.S.I', '2', '23', 'The Hunger Artist'), ('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Spaced', '2', '8', 'New Test Episode'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] DB3 = [ ] for filename in self.Tools.databaseFiles.values() : testfile = open(os.path.join( self.Tools.databaseDir, filename ),"r") content = testfile.read() testfile.close() DB3.append( ( content , filename ) ) assert DB3 == [('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664" /><aliases><alias value="spaced" /></aliases><season number="2"><episode airdate="23 February 2001" arc="none" number="1" title="Back" /><episode airdate="2 March 2001" arc="none" number="2" title="Change" /><episode airdate="9 March 2001" arc="none" number="3" title="Mettle" /><episode airdate="23 March 2001" arc="none" number="4" title="Help" /><episode airdate="None" arc="none" number="5" title="Gone" /><episode airdate="6 April 2001" arc="none" number="6" title="Dissolution" /><episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt" /><episode airdate="8 January 2009" arc="none" number="8" title="New Test Episode" /></season></tvshow>', 'spaced.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150" /><aliases><alias value="blackbooks" /><alias value="black books" /><alias value="black.books" /><alias value="bb" /></aliases><season number="1"><episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books" /><episode airdate="6 October 2000" arc="none" number="2" title="Manny's First Day" /><episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath" /><episode airdate="20 October 2000" arc="none" number="4" title="The Blackout" /><episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out" /><episode airdate="3 November 2000" arc="none" number="6" title="He's Leaving Home" /></season><season number="2"><episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer" /><episode airdate="8 March 2002" arc="none" number="2" title="Fever" /><episode airdate="15 March 2002" arc="none" number="3" title="The Fixer" /><episode airdate="22 March 2002" arc="none" number="4" title="Blood" /><episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun" /><episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change" /></season><season number="3"><episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home" /><episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens" /><episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa" /><episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter" /><episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer" /><episode airdate="15 April 2004" arc="none" number="6" title="Party" /></season></tvshow>', 'blackbooks.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="C.S.I" url="tt0247082" /><aliases><alias value="csi" /></aliases><season number="1"><episode airdate="6 October 2000" arc="none" number="1" title="Pilot" /><episode airdate="13 October 2000" arc="none" number="2" title="Cool Change" /><episode airdate="20 October 2000" arc="none" number="3" title="Crate 'n' Burial" /><episode airdate="27 October 2000" arc="none" number="4" title="Pledging Mr. Johnson" /><episode airdate="3 November 2000" arc="none" number="5" title="Friends & Lovers" /><episode airdate="10 November 2000" arc="none" number="6" title="Who Are You?" /><episode airdate="17 November 2000" arc="none" number="7" title="Blood Drops" /><episode airdate="24 November 2000" arc="none" number="8" title="Anonymous" /><episode airdate="8 December 2000" arc="none" number="9" title="Unfriendly Skies" /><episode airdate="22 December 2000" arc="none" number="10" title="Sex, Lies and Larvae" /><episode airdate="12 January 2001" arc="none" number="11" title="I-15 Murders" /><episode airdate="1 February 2001" arc="none" number="12" title="Fahrenheit 932" /><episode airdate="8 February 2001" arc="none" number="13" title="Boom" /><episode airdate="15 February 2001" arc="none" number="14" title="To Halve and to Hold" /><episode airdate="22 February 2001" arc="none" number="15" title="Table Stakes" /><episode airdate="1 March 2001" arc="none" number="16" title="Too Tough to Die" /><episode airdate="8 March 2001" arc="none" number="17" title="Face Lift" /><episode airdate="29 March 2001" arc="none" number="18" title="$35K O.B.O." /><episode airdate="12 April 2001" arc="none" number="19" title="Gentle, Gentle" /><episode airdate="19 April 2001" arc="none" number="20" title="Sounds of Silence" /><episode airdate="26 April 2001" arc="none" number="21" title="Justice Is Served" /><episode airdate="10 May 2001" arc="none" number="22" title="Evaluation Day" /><episode airdate="17 May 2001" arc="none" number="23" title="The Strip Strangler" /></season><season number="2"><episode airdate="27 September 2001" arc="none" number="1" title="Burked" /><episode airdate="4 October 2001" arc="none" number="2" title="Chaos Theory" /><episode airdate="11 October 2001" arc="none" number="3" title="Overload" /><episode airdate="18 October 2001" arc="none" number="4" title="Bully for You" /><episode airdate="25 October 2001" arc="none" number="5" title="Scuba Doobie-Doo" /><episode airdate="1 November 2001" arc="none" number="6" title="Alter Boys" /><episode airdate="8 November 2001" arc="none" number="7" title="Caged" /><episode airdate="15 November 2001" arc="none" number="8" title="Slaves of Las Vegas" /><episode airdate="22 November 2001" arc="none" number="9" title="And Then There Were None" /><episode airdate="6 December 2001" arc="none" number="10" title="Ellie" /><episode airdate="13 December 2001" arc="none" number="11" title="Organ Grinder" /><episode airdate="20 December 2001" arc="none" number="12" title="You've Got Male" /><episode airdate="17 January 2002" arc="none" number="13" title="Identity Crisis" /><episode airdate="None" arc="none" number="14" title="The Finger" /><episode airdate="7 February 2002" arc="none" number="15" title="Burden of Proof" /><episode airdate="28 February 2002" arc="none" number="16" title="Primum Non Nocere" /><episode airdate="7 March 2002" arc="none" number="17" title="Felonious Monk" /><episode airdate="28 March 2002" arc="none" number="18" title="Chasing the Bus" /><episode airdate="4 April 2002" arc="none" number="19" title="Stalker" /><episode airdate="25 April 2002" arc="none" number="20" title="Cats in the Cradle..." /><episode airdate="2 May 2002" arc="none" number="21" title="Anatomy of a Lye" /><episode airdate="9 May 2002" arc="none" number="22" title="Cross-Jurisdictions" /><episode airdate="18 May 2002" arc="none" number="23" title="The Hunger Artist" /></season></tvshow>', 'csi.show')]
class testFilesystems: """ Test Filesystems Class. """ def setUp(self): self.FS = Filesystems() # Filesystem dir is None def testLoadFilesystems(self): self.Tools = Tools() self.Tools.createRootDir() self.Tools.createFilesystemXML() self.FS = Filesystems(self.Tools.filetypesXML) Ext3FS = self.FS.getFilesystem(Filesystem('ext3')) NTFSFS = self.FS.getFilesystem(Filesystem('ntfs')) Filesystem3 = Filesystem('FS3') assert self.FS.addFilesystem(Ext3FS) == None assert self.FS.addFilesystem(Filesystem('ntfs')) == None assert self.FS.addFilesystem(Filesystem3) == Filesystem3 assert self.FS.getFilesystem(Filesystem3) == Filesystem3 assert self.FS.getFilesystem(NTFSFS) == NTFSFS assert self.FS.getFilesystem(Ext3FS) == Ext3FS assert self.FS.removeFilesystem(NTFSFS) == NTFSFS assert self.FS.removeFilesystem(NTFSFS) == None assert self.FS.removeFilesystem(Ext3FS) == Ext3FS assert self.FS.removeFilesystem(Ext3FS) == None self.Tools.removeTempFiles() def testAddFilesystem(self): Filesystem1 = Filesystem('FS1') Filesystem2 = Filesystem('FS2') Filesystem3 = Filesystem('FS3') assert self.FS.addFilesystem(Filesystem1) == Filesystem1 assert self.FS.addFilesystem(Filesystem1) == None assert self.FS.addFilesystem(Filesystem2) == Filesystem2 assert self.FS.addFilesystem(Filesystem('FS2')) == None assert self.FS.addFilesystem(Filesystem3) == Filesystem3 def testGetFilesystem(self): Filesystem1 = Filesystem('FS1') Filesystem2 = Filesystem('FS2') Filesystem3 = Filesystem('FS3') self.FS.addFilesystem(Filesystem1) self.FS.addFilesystem(Filesystem2) assert self.FS.getFilesystem(Filesystem1) == Filesystem1 assert self.FS.getFilesystem(Filesystem3) == None assert self.FS.getFilesystem(Filesystem('FS2')) == Filesystem2 assert self.FS.getFilesystem(Filesystem('FS3')) == None def testRemoveFilesystem(self): Filesystem1 = Filesystem('FS1') Filesystem2 = Filesystem('FS2') Filesystem3 = Filesystem('FS3') self.FS.addFilesystem(Filesystem1) self.FS.addFilesystem(Filesystem2) assert self.FS.removeFilesystem(Filesystem1) == Filesystem1 assert self.FS.removeFilesystem(Filesystem1) == None assert self.FS.removeFilesystem(Filesystem('FS3')) == None assert self.FS.removeFilesystem(Filesystem('FS2')) == Filesystem2
class testFileName: """ Test FileName Class """ def setUp(self): self.Tools = Tools() self.Tools.createRootDir() self.Tools.createTempFiles() self.Tools.createDatabaseFiles() self.Tools.createFilesystemXML() self.database = Database(self.Tools.databaseDir) self.database.loadDB() smallville = Show('Smallville', '60', 'dummy', 'dummy') smallville.addAlias(Alias('smallville')) smallville.addEpisode(Episode('10', 'Bizarro', 'dummy'), Season('7')) self.database.addShow(smallville) self.files = [ 'blackbooks.s01e02.avi', 'spaced.2x03.avi', 'csi.s02E13.avi', 'black books - 03x02 - Six of One.avi', 'Smallville.S07E10.HDTV.XviD-XOR.avi' ] self.filenames = [ FileName(files, self.database) for files in self.files ] def tearDown(self): self.Tools.removeTempFiles() def testGetPattern(self): dummydb = Database() dummyFN = FileName('dummy', dummydb) assert [ fn.getPattern() for fn in self.filenames ] == \ [ dummyFN.pattern1, dummyFN.pattern2, dummyFN.pattern1, dummyFN.pattern2, dummyFN.pattern1 ] def testGetSeason(self): assert [ fn.getSeason() for fn in self.filenames ] == \ [ '1', '2', '2', '3', '7' ] def testGetEpisode(self): assert [ fn.getEpisode() for fn in self.filenames ] == \ [ '2', '3', '13', '2', '10' ] def testGetMatchingShows(self): assert [ fn.getMatchingShows().name for fn in self.filenames ] == \ [ 'Black Books', 'Spaced', 'C.S.I', 'Black Books', 'Smallville' ] def testGeneratePreview(self): result = [] for fn in self.filenames: fn.getMatchingShows() result.append( fn.generatePreview( self.Tools.filetypesXML, 'ext3', '%show - %seasonx%episode - %title ( %arc - %airdate )')) assert result == [ ('blackbooks.s01e02.avi', "Black Books - 01x02 - Manny's First Day ( none - 6 October 2000 ).avi" ), ('spaced.2x03.avi', 'Spaced - 02x03 - Mettle ( none - 9 March 2001 ).avi'), ('csi.s02E13.avi', 'C.S.I - 02x13 - Identity Crisis ( none - 17 January 2002 ).avi'), ('black books - 03x02 - Six of One.avi', 'Black Books - 03x02 - Elephants and Hens ( none - 18 March 2004 ).avi' ), ('Smallville.S07E10.HDTV.XviD-XOR.avi', 'Smallville - 07x10 - Bizarro ( none - dummy ).avi') ] result = [] for fn in self.filenames: fn.getMatchingShows() result.append( fn.generatePreview( self.Tools.filetypesXML, 'ntfs', '%show - %seasonE%episode - %title ( %arc - %airdate )')) assert result == [ ('blackbooks.s01e02.avi', 'Black Books - 01E02 - Mannys First Day ( none - 6 October 2000 ).avi' ), ('spaced.2x03.avi', 'Spaced - 02E03 - Mettle ( none - 9 March 2001 ).avi'), ('csi.s02E13.avi', 'C.S.I - 02E13 - Identity Crisis ( none - 17 January 2002 ).avi'), ('black books - 03x02 - Six of One.avi', 'Black Books - 03E02 - Elephants and Hens ( none - 18 March 2004 ).avi' ), ('Smallville.S07E10.HDTV.XviD-XOR.avi', 'Smallville - 07E10 - Bizarro ( none - dummy ).avi') ] def testGetShowDetails(self): testShows = [ fn.getShowDetails(self.Tools.filetypesXML, fn.getMatchingShows()) for fn in self.filenames ] assert [len(ts.seasons) for ts in testShows] == [1, 1, 1, 1, 1] assert [len(ts.seasons[0].episodes) for ts in testShows] == [1, 1, 1, 1, 1] correctShow1 = Show('Black Books', '30', 'imdbtvbackend', 'tt0262150') correctShow1.addEpisode( Episode('2', "Manny's First Day", '6 October 2000', 'none'), Season('1')) correctShow2 = Show('Spaced', '60', 'imdbtvbackend', 'tt0187664') correctShow2.addEpisode(Episode('3', 'Mettle', '9 March 2001', 'none'), Season('2')) correctShow3 = Show('C.S.I', '60', 'imdbtvbackend', 'tt0247082') correctShow3.addEpisode( Episode('13', 'Identity Crisis', '17 January 2002', 'none'), Season('2')) def compareShows(show, other): if show.name != other.name or show.duration != other.duration or show.backend != other.backend or show.url != other.url: assert False elif show.seasons[0].name != other.seasons[0].name: assert False elif show.seasons[0].episodes[0].name != other.seasons[0].episodes[ 0].name or show.seasons[0].episodes[ 0].title != other.seasons[0].episodes[ 0].title or show.seasons[0].episodes[ 0].airdate != other.seasons[0].episodes[ 0].airdate or show.seasons[0].episodes[ 0].arc != other.seasons[0].episodes[ 0].arc: assert False else: return True assert compareShows(testShows[0], correctShow1) assert compareShows(testShows[1], correctShow2) assert compareShows(testShows[2], correctShow3) def testGenerateFileName(self): #FIXME: More than one Style, different file suffixes, arcs. # generateFileName(Style=None) correctShow1 = Show('Black Books', '30', 'imdbtvbackend', 'tt0262150') correctShow1.addEpisode( Episode('2', "A test's test' & a test / # a test", '6 October 2000', 'none'), Season('1')) correctShow2 = Show('Spaced', '60', 'imdbtvbackend', 'tt0187664') correctShow2.addEpisode( Episode('3', "A test's test' & a test / # a test", '9 March 2001', 'none'), Season('2')) correctShow3 = Show('C.S.I', '60', 'imdbtvbackend', 'tt0247082') correctShow3.addEpisode( Episode('13', "Identity Crisis / # 4587", '17 January 2002', 'none'), Season('2')) self.FN = FileName('', self.database) self.FN.fileSuffix = '.avi' fileName1 = self.FN.generateFileName( correctShow1, self.Tools.filetypesXML, 'ext3', '%show.S%seasonE%episode.%title.%arc.%airdate') fileName2 = self.FN.generateFileName( correctShow2, self.Tools.filetypesXML, 'ntfs', '%show.S%seasonE%episode.%title.%arc.%airdate') fileName3 = self.FN.generateFileName( correctShow3, self.Tools.filetypesXML, 'ext3', '%show.S%seasonE%episode.%title.%arc.%airdate') assert fileName1 == "Black Books.S01E02.A test's test' & a test or # a test.none.6 October 2000.avi" assert fileName2 == "Spaced.S02E03.A tests test and a test or No. a test.none.9 March 2001.avi" assert fileName3 == "C.S.I.S02E13.Identity Crisis or # 4587.none.17 January 2002.avi" def testRenameFile(self): self.folder1 = Folder( os.path.join(self.Tools.rootDir, self.Tools.testDirs[0]), self.Tools.databaseDir) self.folder1.loadFiles() self.filename1 = FileName('blackbooks.s01e02.avi', self.database) self.filename1.getMatchingShows() self.filename1.generatePreview( self.Tools.filetypesXML, 'ext3', '%show - %seasonx%episode - %title ( %arc - %airdate )') assert os.listdir( self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] self.filename1.renameFile(self.folder1.path) assert os.listdir(self.folder1.path) == [ 'bb.s03e05.avi', "Black Books - 01x02 - Manny's First Day ( none - 6 October 2000 ).avi" ] def testRevertFile(self): self.folder1 = Folder( os.path.join(self.Tools.rootDir, self.Tools.testDirs[0]), self.Tools.databaseDir) self.folder1.loadFiles() self.filename1 = FileName('blackbooks.s01e02.avi', self.database) self.filename1.getMatchingShows() self.filename1.generatePreview( self.Tools.filetypesXML, 'ext3', '%show - %seasonx%episode - %title ( %arc - %airdate )') assert os.listdir( self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] self.filename1.renameFile(self.folder1.path) assert os.listdir(self.folder1.path) == [ 'bb.s03e05.avi', "Black Books - 01x02 - Manny's First Day ( none - 6 October 2000 ).avi" ] self.filename1.revertFile(self.folder1.path) assert os.listdir( self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi']
class testRename: """ Test Rename Class """ def setUp(self): self.Tools = Tools() self.Tools.createRootDir() self.Tools.createTempFiles() self.Tools.createDatabaseFiles() self.Tools.createFilesystemXML() self.database = Database(self.Tools.databaseDir) self.database.loadDB() self.folder1 = Folder( os.path.join(self.Tools.rootDir, self.Tools.testDirs[0]), self.Tools.databaseDir) self.folder2 = Folder( os.path.join(self.Tools.rootDir, self.Tools.testDirs[1]), self.Tools.databaseDir) self.folder3 = Folder( os.path.join(self.Tools.rootDir, self.Tools.testDirs[2]), self.Tools.databaseDir) def tearDown(self): self.Tools.removeTempFiles() def testAddFolder(self): rename = Rename(self.Tools.databaseDir, self.Tools.filetypesXML) assert rename.addFolder(self.folder1) == self.folder1 assert rename.addFolder(self.folder1) == None assert rename.addFolder(self.folder1) == self.folder1 assert rename.addFolder( Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[1]), self.Tools.databaseDir)) == None assert rename.addFolder(self.folder3) == self.folder3 def testAddFoldersRecursively(self): rename = Rename(self.Tools.databaseDir, self.Tools.filetypesXML) rename.addFolder(self.folder1) assert rename.addFoldersRecursively(Folder( self.Tools.rootDir)) == Folder(self.Tools.rootDir) assert [folder.path for folder in rename.folders] == [ '/tmp/veefire/Black Books', '/tmp/veefire', '/tmp/veefire/Spaced', '/tmp/veefire/CSI', '/tmp/veefire/database' ] rename.addFolder(self.folder1) rename.addFolder(self.folder1) rename.addFolder(Folder('/tmp/veefire/Spaced')) rename.addFolder(Folder('/tmp/veefire/Spaced')) rename.addFolder(Folder('/tmp/veefire/Spaced')) assert rename.removeFolder( Folder('/tmp/veefire')).path == '/tmp/veefire' assert [folder.path for folder in rename.folders] == [ '/tmp/veefire/Black Books', '/tmp/veefire/Spaced', '/tmp/veefire/CSI', '/tmp/veefire/database' ] assert rename.removeFolder( Folder('/tmp/veefire/Spaced')).path == '/tmp/veefire/Spaced' assert rename.removeFolder(Folder('/tmp/veefire/Spaced')) == None assert [folder.path for folder in rename.folders] == [ '/tmp/veefire/Black Books', '/tmp/veefire/CSI', '/tmp/veefire/database' ] def testGetFolder(self): rename = Rename(self.Tools.databaseDir, self.Tools.filetypesXML) rename.addFolder(self.folder1) rename.addFolder(self.folder1) assert rename.getFolder(self.folder1) == True assert rename.getFolder(self.folder3) == None assert rename.getFolder( Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[1]), self.Tools.databaseDir)) == None assert rename.getFolder( Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[2]), self.Tools.databaseDir)) == None def testRemoveFolder(self): rename = Rename(self.Tools.databaseDir, self.Tools.filetypesXML) rename.addFolder(self.folder1) rename.addFolder(self.folder1) assert rename.removeFolder(self.folder1) == self.folder1 assert rename.removeFolder(self.folder1) == None assert rename.removeFolder( Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[2]), self.Tools.databaseDir)) == None assert rename.removeFolder( Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[1]), self.Tools.databaseDir)) == self.folder1 def testGetMatchingShows(self): self.folder1.loadFiles() self.folder2.loadFiles() self.folder3.loadFiles() rename1 = Rename(self.Tools.databaseDir, self.Tools.filetypesXML) rename2 = Rename(self.Tools.databaseDir, self.Tools.filetypesXML) rename3 = Rename(self.Tools.databaseDir, self.Tools.filetypesXML) rename1.addFolder(self.folder1) rename1.addFolder(self.folder2) rename2.addFolder(self.folder1) rename2.addFolder(self.folder3) rename3.addFolder(self.folder3) assert [ fn.CorrectShow.name for fo in rename1.getMatchingShows() for fn in fo.getMatchingShows() ] == ['Black Books', 'Black Books', 'C.S.I', 'C.S.I'] assert [ fn.CorrectShow.name for fo in rename2.getMatchingShows() for fn in fo.getMatchingShows() ] == ['Black Books', 'Black Books', 'Spaced', 'Spaced'] assert [ fn.CorrectShow.name for fo in rename3.getMatchingShows() for fn in fo.getMatchingShows() ] == ['Spaced', 'Spaced'] def testGeneratePreviews(self): self.folder1.loadFiles() self.folder2.loadFiles() self.folder3.loadFiles() rename1 = Rename(self.Tools.databaseDir, self.Tools.filetypesXML) rename2 = Rename(self.Tools.databaseDir, self.Tools.filetypesXML) rename3 = Rename(self.Tools.databaseDir, self.Tools.filetypesXML) rename1.addFolder(self.folder1) rename1.addFolder(self.folder2) rename2.addFolder(self.folder1) rename2.addFolder(self.folder3) rename3.addFolder(self.folder3) rename1.getMatchingShows() rename2.getMatchingShows() rename3.getMatchingShows() assert [fo for fo in rename1.generatePreviews('ext3') ] == [[('bb.s03e05.avi', 'Black Books - S03E05 - The Travel Writer.avi'), ('blackbooks.s01e02.avi', "Black Books - S01E02 - Manny's First Day.avi")], [('csiS01E11.avi', 'C.S.I - S01E11 - I-15 Murders.avi'), ('CSI.2x12.avi', "C.S.I - S02E12 - You've Got Male.avi") ]] assert [ fo for fo in rename2.generatePreviews('ntfs', '%show[%season](%title)') ] == [[('bb.s03e05.avi', 'Black Books[03](The Travel Writer).avi'), ('blackbooks.s01e02.avi', 'Black Books[01](Mannys First Day).avi')], [('Spaced.S02E03.avi', 'Spaced[02](Mettle).avi'), ('Spaced.2x4.avi', 'Spaced[02](Help).avi')]] assert [ fo for fo in rename3.generatePreviews( 'ext3', '%show - %seasonx%episode - %title') ] == [[('Spaced.S02E03.avi', 'Spaced - 02x03 - Mettle.avi'), ('Spaced.2x4.avi', 'Spaced - 02x04 - Help.avi')]] def testRename(self): self.folder1.loadFiles() rename1 = Rename(self.Tools.databaseDir, self.Tools.filetypesXML) rename1.addFolder(self.folder1) rename1.addFolder(self.folder2) rename1.getMatchingShows() rename1.generatePreviews('ext3') assert os.listdir( self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] rename1.rename() assert os.listdir(self.folder1.path) == [ "Black Books - S01E02 - Manny's First Day.avi", 'Black Books - S03E05 - The Travel Writer.avi' ] def testRevert(self): self.folder1.loadFiles() rename1 = Rename(self.Tools.databaseDir, self.Tools.filetypesXML) rename1.addFolder(self.folder1) rename1.addFolder(self.folder2) rename1.getMatchingShows() rename1.generatePreviews('ext3') assert os.listdir( self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] rename1.rename() assert os.listdir(self.folder1.path) == [ "Black Books - S01E02 - Manny's First Day.avi", 'Black Books - S03E05 - The Travel Writer.avi' ] rename1.revert() assert os.listdir( self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi']
class testFolder: """ Test Folder Class """ def setUp(self): self.Tools = Tools() self.Tools.createRootDir() self.Tools.createTempFiles() self.Tools.createDatabaseFiles() self.Tools.createFilesystemXML() self.database = Database(self.Tools.databaseDir) self.database.loadDB() self.folder1 = Folder( os.path.join(self.Tools.rootDir, self.Tools.testDirs[0]), self.Tools.databaseDir) self.folder2 = Folder( os.path.join(self.Tools.rootDir, self.Tools.testDirs[1]), self.Tools.databaseDir) self.folder3 = Folder( os.path.join(self.Tools.rootDir, self.Tools.testDirs[2]), self.Tools.databaseDir) def tearDown(self): self.Tools.removeTempFiles() def testLoadFiles(self): self.folder1.loadFiles() self.folder2.loadFiles() self.folder3.loadFiles() assert [fn.fileName for fn in self.folder1.fileNames ] == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] assert [fn.fileName for fn in self.folder2.fileNames ] == ['csiS01E11.avi', 'CSI.2x12.avi'] assert [fn.fileName for fn in self.folder3.fileNames ] == ['Spaced.S02E03.avi', 'Spaced.2x4.avi'] def testGetMatchingShows(self): self.folder1.loadFiles() self.folder2.loadFiles() self.folder3.loadFiles() assert [fn.CorrectShow.name for fn in self.folder1.getMatchingShows() ] == ['Black Books', 'Black Books'] assert [fn.CorrectShow.name for fn in self.folder2.getMatchingShows() ] == ['C.S.I', 'C.S.I'] assert [fn.CorrectShow.name for fn in self.folder3.getMatchingShows() ] == ['Spaced', 'Spaced'] def testGeneratePreviews(self): self.folder1.loadFiles() self.folder2.loadFiles() self.folder3.loadFiles() self.folder1.getMatchingShows() self.folder2.getMatchingShows() self.folder3.getMatchingShows() assert [ fn for fn in self.folder1.generatePreviews( self.Tools.filetypesXML, 'ext3', '%show - S0%sesonE0%episode - %title') ] == [('bb.s03e05.avi', 'Black Books - S0%sesonE005 - The Travel Writer.avi'), ('blackbooks.s01e02.avi', "Black Books - S0%sesonE002 - Manny's First Day.avi")] assert [ fn for fn in self.folder2.generatePreviews( self.Tools.filetypesXML, 'ntfs', '%show - S0%sesonE0%episode - %title') ] == [('csiS01E11.avi', 'C.S.I - S0%sesonE011 - I-15 Murders.avi'), ('CSI.2x12.avi', 'C.S.I - S0%sesonE012 - Youve Got Male.avi')] assert [ fn for fn in self.folder3.generatePreviews( self.Tools.filetypesXML, 'ext3', '%show - S0%sesonE0%episode - %title') ] == [('Spaced.S02E03.avi', 'Spaced - S0%sesonE003 - Mettle.avi'), ('Spaced.2x4.avi', 'Spaced - S0%sesonE004 - Help.avi')] def testRename(self): self.folder1.loadFiles() self.folder1.getMatchingShows() self.folder1.generatePreviews(self.Tools.filetypesXML, 'ext3', '%show - S0%sesonE0%episode - %title') assert os.listdir( self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] self.folder1.rename() assert os.listdir(self.folder1.path) == [ "Black Books - S0%sesonE002 - Manny's First Day.avi", 'Black Books - S0%sesonE005 - The Travel Writer.avi' ] def testRevert(self): self.folder1.loadFiles() self.folder1.getMatchingShows() self.folder1.generatePreviews(self.Tools.filetypesXML, 'ext3', '%show - S0%sesonE0%episode - %title') assert os.listdir( self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] self.folder1.rename() assert os.listdir(self.folder1.path) == [ "Black Books - S0%sesonE002 - Manny's First Day.avi", 'Black Books - S0%sesonE005 - The Travel Writer.avi' ] self.folder1.revert() assert os.listdir( self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi']
class testPreferences : """ Test Preferences Class """ def setUp(self) : self.Tools = Tools() self.Tools.createRootDir() self.Tools.createPreferencesXML() self.preferences = Preferences(self.Tools.preferencesXML) def tearDown(self): self.Tools.removeTempFiles() def testLoad(self): assert self.preferences.filename == self.Tools.preferencesXML assert self.preferences.elementTree == None self.preferences.load() assert self.preferences.elementTree != None assert self.preferences.Options != None assert self.preferences.Preferences != None def testGetPreference(self): self.preferences.load() assert self.preferences['confirm-on-rename'] == 'true' assert self.preferences['naming-style'] == '%show - S%seasonE%episode - %title' def testSetPreference(self): self.preferences.load() assert self.preferences['confirm-on-rename'] == 'true' assert self.preferences['naming-style'] == '%show - S%seasonE%episode - %title' self.preferences['confirm-on-rename'] = 'false' self.preferences['naming-style'] = '%show.%seasonx%episode.%title' assert self.preferences['confirm-on-rename'] == 'false' assert self.preferences['naming-style'] == '%show.%seasonx%episode.%title' def testGetOptions(self): self.preferences.load() assert self.preferences.getOptions('naming-style') == ['%show - S%seasonE%episode - %title', '%show.%seasonx%episode.%title'] def testAddOption(self): self.preferences.load() assert self.preferences.addOption('naming-style', '3') == ['%show - S%seasonE%episode - %title', '%show.%seasonx%episode.%title', '3'] def testRemoveOption(self): self.preferences.load() assert self.preferences.removeOption('naming-style', '%show - S%seasonE%episode - %title') == ['%show.%seasonx%episode.%title'] def testSave(self): self.preferences.load() self.preferences['confirm-on-rename'] = 'false' self.preferences['naming-style'] = '%show.%seasonx%episode.%title' self.preferences.addOption('naming-style', '3') self.preferences.removeOption('naming-style', '%show - S%seasonE%episode - %title') self.preferences.save() self.preferences.load() assert self.preferences.getOptions('naming-style') == ['%show.%seasonx%episode.%title', '3'] assert self.preferences['confirm-on-rename'] == 'false' assert self.preferences['naming-style'] == '%show.%seasonx%episode.%title' self.preferences2 = Preferences(self.Tools.preferencesXML) self.preferences2.load() assert self.preferences2.getOptions('naming-style') == ['%show.%seasonx%episode.%title', '3'] assert self.preferences2['confirm-on-rename'] == 'false' assert self.preferences2['naming-style'] == '%show.%seasonx%episode.%title'
class testBackendInterface : """ Test BackendInterface Class """ def setUp(self) : self.Tools = Tools() self.Tools.createRootDir() self.Tools.createBackendFiles() self.Tools.createDatabaseFiles() class NewBackendInterface(BackendInterface): def solveEpisodeConflicts(self, firstEpisode, secondEpisode): return firstEpisode self.BaIf1 = NewBackendInterface(self.Tools.databaseDir) def tearDown(self): self.Tools.removeTempFiles() def testAddNewShow(self): Show1 = Show( "Test Show One", "60", "dummybackend", "dummyurlone" ) Show2 = Show( "Test Show Two", "60", "dummybackend", "dummyurltwo" ) Show3 = Show( "Test Show Three", "60", "dummybackend", "dummyurlthree" ) assert self.BaIf1.addNewShow( Show1 ) == Show1 assert self.BaIf1.addNewShow( Show1 ) == None assert self.BaIf1.addNewShow( Show2 ) == Show2 assert self.BaIf1.addNewShow( Show( "Test Show Two", "60", "dummybackend", "dummyurltwo" )) == None assert self.BaIf1.addNewShow( Show3 ) == Show3 def testUpdateDatabase(self): assert os.path.exists(self.Tools.databaseDir) == True DB2 = [ ] for filename in self.Tools.databaseFiles.values() : testfile = open(os.path.join( self.Tools.databaseDir, filename ),"r") content = testfile.read() testfile.close() DB2.append( ( content , filename ) ) assert DB2 == [('<?xml version="1.0" encoding="UTF-8"?>\n<tvshow>\n <showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664"/>\n <aliases>\n <alias value="spaced"/>\n </aliases>\n <season number="1">\n <episode airdate="24 September 1999" arc="none" number="1" title="Beginnings"/>\n <episode airdate="1 October 1999" arc="none" number="2" title="Gatherings"/>\n <episode airdate="8 October 1999" arc="none" number="3" title="Art"/>\n <episode airdate="15 October 1999" arc="none" number="4" title="Battles"/>\n <episode airdate="22 October 1999" arc="none" number="5" title="Chaos"/>\n <episode airdate="29 October 1999" arc="none" number="6" title="Epiphanies"/>\n <episode airdate="5 November 1999" arc="none" number="7" title="Ends"/>\n </season>\n <season number="2">\n <episode airdate="23 February 2001" arc="none" number="1" title="Back"/>\n <episode airdate="2 March 2001" arc="none" number="2" title="Change"/>\n <episode airdate="9 March 2001" arc="none" number="3" title="Mettle"/>\n <episode airdate="23 March 2001" arc="none" number="4" title="Help"/>\n <episode airdate="None" arc="none" number="5" title="Gone"/>\n <episode airdate="6 April 2001" arc="none" number="6" title="Dissolution"/>\n <episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt"/>\n </season>\n</tvshow>', 'spaced.show'), ('<?xml version="1.0" encoding="UTF-8"?>\n<tvshow>\n <showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150"/>\n <aliases>\n <alias value="blackbooks"/>\n <alias value="black books"/>\n <alias value="black.books"/>\n <alias value="bb"/>\n </aliases>\n <season number="1">\n <episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books"/>\n <episode airdate="6 October 2000" arc="none" number="2" title="Manny\'s First Day"/>\n <episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath"/>\n <episode airdate="20 October 2000" arc="none" number="4" title="The Blackout"/>\n <episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out"/>\n <episode airdate="3 November 2000" arc="none" number="6" title="He\'s Leaving Home"/>\n </season>\n <season number="2">\n <episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer"/>\n <episode airdate="8 March 2002" arc="none" number="2" title="Fever"/>\n <episode airdate="15 March 2002" arc="none" number="3" title="The Fixer"/>\n <episode airdate="22 March 2002" arc="none" number="4" title="Blood"/>\n <episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun"/>\n <episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change"/>\n </season>\n <season number="3">\n <episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home"/>\n <episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens"/>\n <episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa"/>\n <episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter"/>\n <episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer"/>\n <episode airdate="15 April 2004" arc="none" number="6" title="Party"/>\n </season>\n</tvshow>\n', 'blackbooks.show'), ('<?xml version="1.0" encoding="UTF-8"?>\n<tvshow>\n <showproperties backend="imdbtvbackend" duration="60" name="C.S.I" url="tt0247082"/>\n <aliases>\n <alias value="csi"/>\n </aliases>\n <season number="1">\n <episode airdate="6 October 2000" arc="none" number="1" title="Pilot"/>\n <episode airdate="13 October 2000" arc="none" number="2" title="Cool Change"/>\n <episode airdate="20 October 2000" arc="none" number="3" title="Crate \'n\' Burial"/>\n <episode airdate="27 October 2000" arc="none" number="4" title="Pledging Mr. Johnson"/>\n <episode airdate="3 November 2000" arc="none" number="5" title="Friends & Lovers"/>\n <episode airdate="10 November 2000" arc="none" number="6" title="Who Are You?"/>\n <episode airdate="17 November 2000" arc="none" number="7" title="Blood Drops"/>\n <episode airdate="24 November 2000" arc="none" number="8" title="Anonymous"/>\n <episode airdate="8 December 2000" arc="none" number="9" title="Unfriendly Skies"/>\n <episode airdate="22 December 2000" arc="none" number="10" title="Sex, Lies and Larvae"/>\n <episode airdate="12 January 2001" arc="none" number="11" title="I-15 Murders"/>\n <episode airdate="1 February 2001" arc="none" number="12" title="Fahrenheit 932"/>\n <episode airdate="8 February 2001" arc="none" number="13" title="Boom"/>\n <episode airdate="15 February 2001" arc="none" number="14" title="To Halve and to Hold"/>\n <episode airdate="22 February 2001" arc="none" number="15" title="Table Stakes"/>\n <episode airdate="1 March 2001" arc="none" number="16" title="Too Tough to Die"/>\n <episode airdate="8 March 2001" arc="none" number="17" title="Face Lift"/>\n <episode airdate="29 March 2001" arc="none" number="18" title="$35K O.B.O."/>\n <episode airdate="12 April 2001" arc="none" number="19" title="Gentle, Gentle"/>\n <episode airdate="19 April 2001" arc="none" number="20" title="Sounds of Silence"/>\n <episode airdate="26 April 2001" arc="none" number="21" title="Justice Is Served"/>\n <episode airdate="10 May 2001" arc="none" number="22" title="Evaluation Day"/>\n <episode airdate="17 May 2001" arc="none" number="23" title="The Strip Strangler"/>\n </season>\n <season number="2">\n <episode airdate="27 September 2001" arc="none" number="1" title="Burked"/>\n <episode airdate="4 October 2001" arc="none" number="2" title="Chaos Theory"/>\n <episode airdate="11 October 2001" arc="none" number="3" title="Overload"/>\n <episode airdate="18 October 2001" arc="none" number="4" title="Bully for You"/>\n <episode airdate="25 October 2001" arc="none" number="5" title="Scuba Doobie-Doo"/>\n <episode airdate="1 November 2001" arc="none" number="6" title="Alter Boys"/>\n <episode airdate="8 November 2001" arc="none" number="7" title="Caged"/>\n <episode airdate="15 November 2001" arc="none" number="8" title="Slaves of Las Vegas"/>\n <episode airdate="22 November 2001" arc="none" number="9" title="And Then There Were None"/>\n <episode airdate="6 December 2001" arc="none" number="10" title="Ellie"/>\n <episode airdate="13 December 2001" arc="none" number="11" title="Organ Grinder"/>\n <episode airdate="20 December 2001" arc="none" number="12" title="You\'ve Got Male"/>\n <episode airdate="17 January 2002" arc="none" number="13" title="Identity Crisis"/>\n <episode airdate="None" arc="none" number="14" title="The Finger"/>\n <episode airdate="7 February 2002" arc="none" number="15" title="Burden of Proof"/>\n <episode airdate="28 February 2002" arc="none" number="16" title="Primum Non Nocere"/>\n <episode airdate="7 March 2002" arc="none" number="17" title="Felonious Monk"/>\n <episode airdate="28 March 2002" arc="none" number="18" title="Chasing the Bus"/>\n <episode airdate="4 April 2002" arc="none" number="19" title="Stalker"/>\n <episode airdate="25 April 2002" arc="none" number="20" title="Cats in the Cradle..."/>\n <episode airdate="2 May 2002" arc="none" number="21" title="Anatomy of a Lye"/>\n <episode airdate="9 May 2002" arc="none" number="22" title="Cross-Jurisdictions"/>\n <episode airdate="18 May 2002" arc="none" number="23" title="The Hunger Artist"/>\n </season>\n</tvshow>\n', 'csi.show')] show1 = self.BaIf1.currentDB.getShow( Show('Spaced', '30', 'imdbtvbackend', 'tt000000') ) show1.removeSeason( Season('1') ) DB21 = [ ] for filename in self.Tools.databaseFiles.values() : testfile = open(os.path.join( self.Tools.databaseDir, filename ),"r") content = testfile.read() testfile.close() DB21.append( ( content , filename ) ) assert DB21 == [('<?xml version="1.0" encoding="UTF-8"?>\n<tvshow>\n <showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664"/>\n <aliases>\n <alias value="spaced"/>\n </aliases>\n <season number="1">\n <episode airdate="24 September 1999" arc="none" number="1" title="Beginnings"/>\n <episode airdate="1 October 1999" arc="none" number="2" title="Gatherings"/>\n <episode airdate="8 October 1999" arc="none" number="3" title="Art"/>\n <episode airdate="15 October 1999" arc="none" number="4" title="Battles"/>\n <episode airdate="22 October 1999" arc="none" number="5" title="Chaos"/>\n <episode airdate="29 October 1999" arc="none" number="6" title="Epiphanies"/>\n <episode airdate="5 November 1999" arc="none" number="7" title="Ends"/>\n </season>\n <season number="2">\n <episode airdate="23 February 2001" arc="none" number="1" title="Back"/>\n <episode airdate="2 March 2001" arc="none" number="2" title="Change"/>\n <episode airdate="9 March 2001" arc="none" number="3" title="Mettle"/>\n <episode airdate="23 March 2001" arc="none" number="4" title="Help"/>\n <episode airdate="None" arc="none" number="5" title="Gone"/>\n <episode airdate="6 April 2001" arc="none" number="6" title="Dissolution"/>\n <episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt"/>\n </season>\n</tvshow>', 'spaced.show'), ('<?xml version="1.0" encoding="UTF-8"?>\n<tvshow>\n <showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150"/>\n <aliases>\n <alias value="blackbooks"/>\n <alias value="black books"/>\n <alias value="black.books"/>\n <alias value="bb"/>\n </aliases>\n <season number="1">\n <episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books"/>\n <episode airdate="6 October 2000" arc="none" number="2" title="Manny\'s First Day"/>\n <episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath"/>\n <episode airdate="20 October 2000" arc="none" number="4" title="The Blackout"/>\n <episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out"/>\n <episode airdate="3 November 2000" arc="none" number="6" title="He\'s Leaving Home"/>\n </season>\n <season number="2">\n <episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer"/>\n <episode airdate="8 March 2002" arc="none" number="2" title="Fever"/>\n <episode airdate="15 March 2002" arc="none" number="3" title="The Fixer"/>\n <episode airdate="22 March 2002" arc="none" number="4" title="Blood"/>\n <episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun"/>\n <episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change"/>\n </season>\n <season number="3">\n <episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home"/>\n <episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens"/>\n <episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa"/>\n <episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter"/>\n <episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer"/>\n <episode airdate="15 April 2004" arc="none" number="6" title="Party"/>\n </season>\n</tvshow>\n', 'blackbooks.show'), ('<?xml version="1.0" encoding="UTF-8"?>\n<tvshow>\n <showproperties backend="imdbtvbackend" duration="60" name="C.S.I" url="tt0247082"/>\n <aliases>\n <alias value="csi"/>\n </aliases>\n <season number="1">\n <episode airdate="6 October 2000" arc="none" number="1" title="Pilot"/>\n <episode airdate="13 October 2000" arc="none" number="2" title="Cool Change"/>\n <episode airdate="20 October 2000" arc="none" number="3" title="Crate \'n\' Burial"/>\n <episode airdate="27 October 2000" arc="none" number="4" title="Pledging Mr. Johnson"/>\n <episode airdate="3 November 2000" arc="none" number="5" title="Friends & Lovers"/>\n <episode airdate="10 November 2000" arc="none" number="6" title="Who Are You?"/>\n <episode airdate="17 November 2000" arc="none" number="7" title="Blood Drops"/>\n <episode airdate="24 November 2000" arc="none" number="8" title="Anonymous"/>\n <episode airdate="8 December 2000" arc="none" number="9" title="Unfriendly Skies"/>\n <episode airdate="22 December 2000" arc="none" number="10" title="Sex, Lies and Larvae"/>\n <episode airdate="12 January 2001" arc="none" number="11" title="I-15 Murders"/>\n <episode airdate="1 February 2001" arc="none" number="12" title="Fahrenheit 932"/>\n <episode airdate="8 February 2001" arc="none" number="13" title="Boom"/>\n <episode airdate="15 February 2001" arc="none" number="14" title="To Halve and to Hold"/>\n <episode airdate="22 February 2001" arc="none" number="15" title="Table Stakes"/>\n <episode airdate="1 March 2001" arc="none" number="16" title="Too Tough to Die"/>\n <episode airdate="8 March 2001" arc="none" number="17" title="Face Lift"/>\n <episode airdate="29 March 2001" arc="none" number="18" title="$35K O.B.O."/>\n <episode airdate="12 April 2001" arc="none" number="19" title="Gentle, Gentle"/>\n <episode airdate="19 April 2001" arc="none" number="20" title="Sounds of Silence"/>\n <episode airdate="26 April 2001" arc="none" number="21" title="Justice Is Served"/>\n <episode airdate="10 May 2001" arc="none" number="22" title="Evaluation Day"/>\n <episode airdate="17 May 2001" arc="none" number="23" title="The Strip Strangler"/>\n </season>\n <season number="2">\n <episode airdate="27 September 2001" arc="none" number="1" title="Burked"/>\n <episode airdate="4 October 2001" arc="none" number="2" title="Chaos Theory"/>\n <episode airdate="11 October 2001" arc="none" number="3" title="Overload"/>\n <episode airdate="18 October 2001" arc="none" number="4" title="Bully for You"/>\n <episode airdate="25 October 2001" arc="none" number="5" title="Scuba Doobie-Doo"/>\n <episode airdate="1 November 2001" arc="none" number="6" title="Alter Boys"/>\n <episode airdate="8 November 2001" arc="none" number="7" title="Caged"/>\n <episode airdate="15 November 2001" arc="none" number="8" title="Slaves of Las Vegas"/>\n <episode airdate="22 November 2001" arc="none" number="9" title="And Then There Were None"/>\n <episode airdate="6 December 2001" arc="none" number="10" title="Ellie"/>\n <episode airdate="13 December 2001" arc="none" number="11" title="Organ Grinder"/>\n <episode airdate="20 December 2001" arc="none" number="12" title="You\'ve Got Male"/>\n <episode airdate="17 January 2002" arc="none" number="13" title="Identity Crisis"/>\n <episode airdate="None" arc="none" number="14" title="The Finger"/>\n <episode airdate="7 February 2002" arc="none" number="15" title="Burden of Proof"/>\n <episode airdate="28 February 2002" arc="none" number="16" title="Primum Non Nocere"/>\n <episode airdate="7 March 2002" arc="none" number="17" title="Felonious Monk"/>\n <episode airdate="28 March 2002" arc="none" number="18" title="Chasing the Bus"/>\n <episode airdate="4 April 2002" arc="none" number="19" title="Stalker"/>\n <episode airdate="25 April 2002" arc="none" number="20" title="Cats in the Cradle..."/>\n <episode airdate="2 May 2002" arc="none" number="21" title="Anatomy of a Lye"/>\n <episode airdate="9 May 2002" arc="none" number="22" title="Cross-Jurisdictions"/>\n <episode airdate="18 May 2002" arc="none" number="23" title="The Hunger Artist"/>\n </season>\n</tvshow>\n', 'csi.show')] self.BaIf1.currentDB.write() DB211 = [ ] for filename in self.Tools.databaseFiles.values() : testfile = open(os.path.join( self.Tools.databaseDir, filename ),"r") content = testfile.read() testfile.close() DB211.append( ( content , filename ) ) assert DB211 == [('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664" /><aliases><alias value="spaced" /></aliases><season number="2"><episode airdate="23 February 2001" arc="none" number="1" title="Back" /><episode airdate="2 March 2001" arc="none" number="2" title="Change" /><episode airdate="9 March 2001" arc="none" number="3" title="Mettle" /><episode airdate="23 March 2001" arc="none" number="4" title="Help" /><episode airdate="None" arc="none" number="5" title="Gone" /><episode airdate="6 April 2001" arc="none" number="6" title="Dissolution" /><episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt" /></season></tvshow>', 'spaced.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150" /><aliases><alias value="blackbooks" /><alias value="black books" /><alias value="black.books" /><alias value="bb" /></aliases><season number="1"><episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books" /><episode airdate="6 October 2000" arc="none" number="2" title="Manny's First Day" /><episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath" /><episode airdate="20 October 2000" arc="none" number="4" title="The Blackout" /><episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out" /><episode airdate="3 November 2000" arc="none" number="6" title="He's Leaving Home" /></season><season number="2"><episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer" /><episode airdate="8 March 2002" arc="none" number="2" title="Fever" /><episode airdate="15 March 2002" arc="none" number="3" title="The Fixer" /><episode airdate="22 March 2002" arc="none" number="4" title="Blood" /><episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun" /><episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change" /></season><season number="3"><episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home" /><episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens" /><episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa" /><episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter" /><episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer" /><episode airdate="15 April 2004" arc="none" number="6" title="Party" /></season></tvshow>', 'blackbooks.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="C.S.I" url="tt0247082" /><aliases><alias value="csi" /></aliases><season number="1"><episode airdate="6 October 2000" arc="none" number="1" title="Pilot" /><episode airdate="13 October 2000" arc="none" number="2" title="Cool Change" /><episode airdate="20 October 2000" arc="none" number="3" title="Crate 'n' Burial" /><episode airdate="27 October 2000" arc="none" number="4" title="Pledging Mr. Johnson" /><episode airdate="3 November 2000" arc="none" number="5" title="Friends & Lovers" /><episode airdate="10 November 2000" arc="none" number="6" title="Who Are You?" /><episode airdate="17 November 2000" arc="none" number="7" title="Blood Drops" /><episode airdate="24 November 2000" arc="none" number="8" title="Anonymous" /><episode airdate="8 December 2000" arc="none" number="9" title="Unfriendly Skies" /><episode airdate="22 December 2000" arc="none" number="10" title="Sex, Lies and Larvae" /><episode airdate="12 January 2001" arc="none" number="11" title="I-15 Murders" /><episode airdate="1 February 2001" arc="none" number="12" title="Fahrenheit 932" /><episode airdate="8 February 2001" arc="none" number="13" title="Boom" /><episode airdate="15 February 2001" arc="none" number="14" title="To Halve and to Hold" /><episode airdate="22 February 2001" arc="none" number="15" title="Table Stakes" /><episode airdate="1 March 2001" arc="none" number="16" title="Too Tough to Die" /><episode airdate="8 March 2001" arc="none" number="17" title="Face Lift" /><episode airdate="29 March 2001" arc="none" number="18" title="$35K O.B.O." /><episode airdate="12 April 2001" arc="none" number="19" title="Gentle, Gentle" /><episode airdate="19 April 2001" arc="none" number="20" title="Sounds of Silence" /><episode airdate="26 April 2001" arc="none" number="21" title="Justice Is Served" /><episode airdate="10 May 2001" arc="none" number="22" title="Evaluation Day" /><episode airdate="17 May 2001" arc="none" number="23" title="The Strip Strangler" /></season><season number="2"><episode airdate="27 September 2001" arc="none" number="1" title="Burked" /><episode airdate="4 October 2001" arc="none" number="2" title="Chaos Theory" /><episode airdate="11 October 2001" arc="none" number="3" title="Overload" /><episode airdate="18 October 2001" arc="none" number="4" title="Bully for You" /><episode airdate="25 October 2001" arc="none" number="5" title="Scuba Doobie-Doo" /><episode airdate="1 November 2001" arc="none" number="6" title="Alter Boys" /><episode airdate="8 November 2001" arc="none" number="7" title="Caged" /><episode airdate="15 November 2001" arc="none" number="8" title="Slaves of Las Vegas" /><episode airdate="22 November 2001" arc="none" number="9" title="And Then There Were None" /><episode airdate="6 December 2001" arc="none" number="10" title="Ellie" /><episode airdate="13 December 2001" arc="none" number="11" title="Organ Grinder" /><episode airdate="20 December 2001" arc="none" number="12" title="You've Got Male" /><episode airdate="17 January 2002" arc="none" number="13" title="Identity Crisis" /><episode airdate="None" arc="none" number="14" title="The Finger" /><episode airdate="7 February 2002" arc="none" number="15" title="Burden of Proof" /><episode airdate="28 February 2002" arc="none" number="16" title="Primum Non Nocere" /><episode airdate="7 March 2002" arc="none" number="17" title="Felonious Monk" /><episode airdate="28 March 2002" arc="none" number="18" title="Chasing the Bus" /><episode airdate="4 April 2002" arc="none" number="19" title="Stalker" /><episode airdate="25 April 2002" arc="none" number="20" title="Cats in the Cradle..." /><episode airdate="2 May 2002" arc="none" number="21" title="Anatomy of a Lye" /><episode airdate="9 May 2002" arc="none" number="22" title="Cross-Jurisdictions" /><episode airdate="18 May 2002" arc="none" number="23" title="The Hunger Artist" /></season></tvshow>', 'csi.show')] self.BaIf1.currentDB.removeShow( Show('C.S.I', '60', 'imdbtvbackend', 'tt000000') ) self.BaIf1.currentDB.delete(Show('C.S.I', '60', 'imdbtvbackend', 'tt000000')) #Tools.databaseFiles = {key : value for key, value in self.Tools.databaseFiles.items() if value is not 'csi.show'} temp_dict = dict() for key, value in self.Tools.databaseFiles.iteritems() : if value != 'csi.show' : temp_dict[key] = value self.Tools.databaseFiles = temp_dict DB22 = [ ] for filename in self.Tools.databaseFiles.values() : testfile = open(os.path.join( self.Tools.databaseDir, filename ),"r") content = testfile.read() testfile.close() DB22.append( ( content , filename ) ) assert DB22 == [('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664" /><aliases><alias value="spaced" /></aliases><season number="2"><episode airdate="23 February 2001" arc="none" number="1" title="Back" /><episode airdate="2 March 2001" arc="none" number="2" title="Change" /><episode airdate="9 March 2001" arc="none" number="3" title="Mettle" /><episode airdate="23 March 2001" arc="none" number="4" title="Help" /><episode airdate="None" arc="none" number="5" title="Gone" /><episode airdate="6 April 2001" arc="none" number="6" title="Dissolution" /><episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt" /></season></tvshow>', 'spaced.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150" /><aliases><alias value="blackbooks" /><alias value="black books" /><alias value="black.books" /><alias value="bb" /></aliases><season number="1"><episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books" /><episode airdate="6 October 2000" arc="none" number="2" title="Manny's First Day" /><episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath" /><episode airdate="20 October 2000" arc="none" number="4" title="The Blackout" /><episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out" /><episode airdate="3 November 2000" arc="none" number="6" title="He's Leaving Home" /></season><season number="2"><episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer" /><episode airdate="8 March 2002" arc="none" number="2" title="Fever" /><episode airdate="15 March 2002" arc="none" number="3" title="The Fixer" /><episode airdate="22 March 2002" arc="none" number="4" title="Blood" /><episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun" /><episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change" /></season><season number="3"><episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home" /><episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens" /><episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa" /><episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter" /><episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer" /><episode airdate="15 April 2004" arc="none" number="6" title="Party" /></season></tvshow>', 'blackbooks.show')] self.BaIf1.updateDatabase() DB3 = [ ] for filename in self.Tools.databaseFiles.values() : testfile = open(os.path.join( self.Tools.databaseDir, filename ),"r") content = testfile.read() testfile.close() DB3.append( ( content , filename ) ) assert DB3 == [('<tvshow><showproperties backend="imdbtvbackend" duration="60" name="Spaced" url="tt0187664" /><aliases /><season number="1"><episode airdate="Sep. 24, 1999" arc="none" number="1" title="Beginnings" /><episode airdate="Oct. 1, 1999" arc="none" number="2" title="Gatherings" /><episode airdate="Oct. 8, 1999" arc="none" number="3" title="Art" /><episode airdate="Oct. 15, 1999" arc="none" number="4" title="Battles" /><episode airdate="Oct. 22, 1999" arc="none" number="5" title="Chaos" /><episode airdate="Oct. 29, 1999" arc="none" number="6" title="Epiphanies" /><episode airdate="Nov. 5, 1999" arc="none" number="7" title="Ends" /></season><season number="2"><episode airdate="23 February 2001" arc="none" number="1" title="Back" /><episode airdate="2 March 2001" arc="none" number="2" title="Change" /><episode airdate="9 March 2001" arc="none" number="3" title="Mettle" /><episode airdate="23 March 2001" arc="none" number="4" title="Help" /><episode airdate="None" arc="none" number="5" title="Gone" /><episode airdate="6 April 2001" arc="none" number="6" title="Dissolution" /><episode airdate="13 April 2001" arc="none" number="7" title="Testkonflikt" /></season></tvshow>', 'spaced.show'), ('<tvshow><showproperties backend="imdbtvbackend" duration="30" name="Black Books" url="tt0262150" /><aliases /><season number="1"><episode airdate="29 September 2000" arc="none" number="1" title="Cooking the Books" /><episode airdate="6 October 2000" arc="none" number="2" title="Manny's First Day" /><episode airdate="13 October 2000" arc="none" number="3" title="The Grapes of Wrath" /><episode airdate="20 October 2000" arc="none" number="4" title="The Blackout" /><episode airdate="27 October 2000" arc="none" number="5" title="The Big Lock-Out" /><episode airdate="3 November 2000" arc="none" number="6" title="He's Leaving Home" /></season><season number="2"><episode airdate="1 March 2002" arc="none" number="1" title="The Entertainer" /><episode airdate="8 March 2002" arc="none" number="2" title="Fever" /><episode airdate="15 March 2002" arc="none" number="3" title="The Fixer" /><episode airdate="22 March 2002" arc="none" number="4" title="Blood" /><episode airdate="29 March 2002" arc="none" number="5" title="Hello Sun" /><episode airdate="5 April 2002" arc="none" number="6" title="A Nice Change" /></season><season number="3"><episode airdate="11 March 2004" arc="none" number="1" title="Manny Come Home" /><episode airdate="18 March 2004" arc="none" number="2" title="Elephants and Hens" /><episode airdate="25 March 2004" arc="none" number="3" title="Moo-Ma and Moo-Pa" /><episode airdate="1 April 2004" arc="none" number="4" title="A Little Flutter" /><episode airdate="8 April 2004" arc="none" number="5" title="The Travel Writer" /><episode airdate="15 April 2004" arc="none" number="6" title="Party" /></season></tvshow>', 'blackbooks.show')] def testFillUpdateDB(self): assert os.path.exists(self.Tools.databaseDir) == True assert [ ( show.name, season.name, episode.name, episode.title ) for show in self.BaIf1.currentDB.database for season in show.seasons for episode in season.episodes ] == [('C.S.I', '1', '1', 'Pilot'), ('C.S.I', '1', '2', 'Cool Change'), ('C.S.I', '1', '3', "Crate 'n' Burial"), ('C.S.I', '1', '4', 'Pledging Mr. Johnson'), ('C.S.I', '1', '5', 'Friends & Lovers'), ('C.S.I', '1', '6', 'Who Are You?'), ('C.S.I', '1', '7', 'Blood Drops'), ('C.S.I', '1', '8', 'Anonymous'), ('C.S.I', '1', '9', 'Unfriendly Skies'), ('C.S.I', '1', '10', 'Sex, Lies and Larvae'), ('C.S.I', '1', '11', 'I-15 Murders'), ('C.S.I', '1', '12', 'Fahrenheit 932'), ('C.S.I', '1', '13', 'Boom'), ('C.S.I', '1', '14', 'To Halve and to Hold'), ('C.S.I', '1', '15', 'Table Stakes'), ('C.S.I', '1', '16', 'Too Tough to Die'), ('C.S.I', '1', '17', 'Face Lift'), ('C.S.I', '1', '18', '$35K O.B.O.'), ('C.S.I', '1', '19', 'Gentle, Gentle'), ('C.S.I', '1', '20', 'Sounds of Silence'), ('C.S.I', '1', '21', 'Justice Is Served'), ('C.S.I', '1', '22', 'Evaluation Day'), ('C.S.I', '1', '23', 'The Strip Strangler'), ('C.S.I', '2', '1', 'Burked'), ('C.S.I', '2', '2', 'Chaos Theory'), ('C.S.I', '2', '3', 'Overload'), ('C.S.I', '2', '4', 'Bully for You'), ('C.S.I', '2', '5', 'Scuba Doobie-Doo'), ('C.S.I', '2', '6', 'Alter Boys'), ('C.S.I', '2', '7', 'Caged'), ('C.S.I', '2', '8', 'Slaves of Las Vegas'), ('C.S.I', '2', '9', 'And Then There Were None'), ('C.S.I', '2', '10', 'Ellie'), ('C.S.I', '2', '11', 'Organ Grinder'), ('C.S.I', '2', '12', "You've Got Male"), ('C.S.I', '2', '13', 'Identity Crisis'), ('C.S.I', '2', '14', 'The Finger'), ('C.S.I', '2', '15', 'Burden of Proof'), ('C.S.I', '2', '16', 'Primum Non Nocere'), ('C.S.I', '2', '17', 'Felonious Monk'), ('C.S.I', '2', '18', 'Chasing the Bus'), ('C.S.I', '2', '19', 'Stalker'), ('C.S.I', '2', '20', 'Cats in the Cradle...'), ('C.S.I', '2', '21', 'Anatomy of a Lye'), ('C.S.I', '2', '22', 'Cross-Jurisdictions'), ('C.S.I', '2', '23', 'The Hunger Artist'), ('Spaced', '1', '1', 'Beginnings'), ('Spaced', '1', '2', 'Gatherings'), ('Spaced', '1', '3', 'Art'), ('Spaced', '1', '4', 'Battles'), ('Spaced', '1', '5', 'Chaos'), ('Spaced', '1', '6', 'Epiphanies'), ('Spaced', '1', '7', 'Ends'), ('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] show1 = self.BaIf1.currentDB.getShow( Show('Spaced', '30', 'imdbtvbackend', 'tt000000') ) show1.removeSeason( Season('1') ) assert [ ( show.name, season.name, episode.name, episode.title ) for show in self.BaIf1.currentDB.database for season in show.seasons for episode in season.episodes ] == [('C.S.I', '1', '1', 'Pilot'), ('C.S.I', '1', '2', 'Cool Change'), ('C.S.I', '1', '3', "Crate 'n' Burial"), ('C.S.I', '1', '4', 'Pledging Mr. Johnson'), ('C.S.I', '1', '5', 'Friends & Lovers'), ('C.S.I', '1', '6', 'Who Are You?'), ('C.S.I', '1', '7', 'Blood Drops'), ('C.S.I', '1', '8', 'Anonymous'), ('C.S.I', '1', '9', 'Unfriendly Skies'), ('C.S.I', '1', '10', 'Sex, Lies and Larvae'), ('C.S.I', '1', '11', 'I-15 Murders'), ('C.S.I', '1', '12', 'Fahrenheit 932'), ('C.S.I', '1', '13', 'Boom'), ('C.S.I', '1', '14', 'To Halve and to Hold'), ('C.S.I', '1', '15', 'Table Stakes'), ('C.S.I', '1', '16', 'Too Tough to Die'), ('C.S.I', '1', '17', 'Face Lift'), ('C.S.I', '1', '18', '$35K O.B.O.'), ('C.S.I', '1', '19', 'Gentle, Gentle'), ('C.S.I', '1', '20', 'Sounds of Silence'), ('C.S.I', '1', '21', 'Justice Is Served'), ('C.S.I', '1', '22', 'Evaluation Day'), ('C.S.I', '1', '23', 'The Strip Strangler'), ('C.S.I', '2', '1', 'Burked'), ('C.S.I', '2', '2', 'Chaos Theory'), ('C.S.I', '2', '3', 'Overload'), ('C.S.I', '2', '4', 'Bully for You'), ('C.S.I', '2', '5', 'Scuba Doobie-Doo'), ('C.S.I', '2', '6', 'Alter Boys'), ('C.S.I', '2', '7', 'Caged'), ('C.S.I', '2', '8', 'Slaves of Las Vegas'), ('C.S.I', '2', '9', 'And Then There Were None'), ('C.S.I', '2', '10', 'Ellie'), ('C.S.I', '2', '11', 'Organ Grinder'), ('C.S.I', '2', '12', "You've Got Male"), ('C.S.I', '2', '13', 'Identity Crisis'), ('C.S.I', '2', '14', 'The Finger'), ('C.S.I', '2', '15', 'Burden of Proof'), ('C.S.I', '2', '16', 'Primum Non Nocere'), ('C.S.I', '2', '17', 'Felonious Monk'), ('C.S.I', '2', '18', 'Chasing the Bus'), ('C.S.I', '2', '19', 'Stalker'), ('C.S.I', '2', '20', 'Cats in the Cradle...'), ('C.S.I', '2', '21', 'Anatomy of a Lye'), ('C.S.I', '2', '22', 'Cross-Jurisdictions'), ('C.S.I', '2', '23', 'The Hunger Artist'), ('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] self.BaIf1.currentDB.removeShow( Show('C.S.I', '60', 'imdbtvbackend', 'tt000000') ) assert [ ( show.name, season.name, episode.name, episode.title ) for show in self.BaIf1.currentDB.database for season in show.seasons for episode in season.episodes ] == [('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] print self.BaIf1.dbDir self.BaIf1.updateDB.printDb() self.BaIf1.fillUpdateDB() self.BaIf1.updateDB.printDb() self.BaIf1.currentDB.printDb() self.BaIf1.mergeDB.printDb() assert [ ( show.name, season.name, episode.name, episode.title ) for show in self.BaIf1.mergeDB.database for season in show.seasons for episode in season.episodes ] == [('Spaced', '1', '1', 'Beginnings'), ('Spaced', '1', '2', 'Gatherings'), ('Spaced', '1', '3', 'Art'), ('Spaced', '1', '4', 'Battles'), ('Spaced', '1', '5', 'Chaos'), ('Spaced', '1', '6', 'Epiphanies'), ('Spaced', '1', '7', 'Ends'), ('Spaced', '2', '1', 'Back'), ('Spaced', '2', '2', 'Change'), ('Spaced', '2', '3', 'Mettle'), ('Spaced', '2', '4', 'Help'), ('Spaced', '2', '5', 'Gone'), ('Spaced', '2', '6', 'Dissolution'), ('Spaced', '2', '7', 'Testkonflikt'), ('Black Books', '1', '1', 'Cooking the Books'), ('Black Books', '1', '2', "Manny's First Day"), ('Black Books', '1', '3', 'The Grapes of Wrath'), ('Black Books', '1', '4', 'The Blackout'), ('Black Books', '1', '5', 'The Big Lock-Out'), ('Black Books', '1', '6', "He's Leaving Home"), ('Black Books', '2', '1', 'The Entertainer'), ('Black Books', '2', '2', 'Fever'), ('Black Books', '2', '3', 'The Fixer'), ('Black Books', '2', '4', 'Blood'), ('Black Books', '2', '5', 'Hello Sun'), ('Black Books', '2', '6', 'A Nice Change'), ('Black Books', '3', '1', 'Manny Come Home'), ('Black Books', '3', '2', 'Elephants and Hens'), ('Black Books', '3', '3', 'Moo-Ma and Moo-Pa'), ('Black Books', '3', '4', 'A Little Flutter'), ('Black Books', '3', '5', 'The Travel Writer'), ('Black Books', '3', '6', 'Party')] def testCompareDetails(self): Episode1 = Episode( "2", "What A Title", "6 November, 2008" ) Episode2 = Episode( "333", "For A TV Show", "18 November, 2008" ) Episode3 = Episode( "4", "What A Title", "6 November, 2008") Episode4 = Episode( "2", "What A Title", "6 November, 2008" ) Episode5 = Episode( "333", "For A TV Show", "18 November, 2008" ) Episode6 = Episode( "4", "What A Title", "6 November, 2008") Season1 = Season('1') Season2 = Season('2') Season1.addEpisode( Episode1 ) Season1.addEpisode( Episode2 ) Season1.addEpisode( Episode3 ) Season2.addEpisode( Episode4 ) Season2.addEpisode( Episode5 ) Season2.addEpisode( Episode6 ) Season3 = Season1 Season4 = Season2 Show1 = Show( "Test Show One", "60", "dummybackend", "dummyurlone" ) Show2 = Show( "Test Show Two", "60", "dummybackend", "dummyurltwo" ) Show3 = Show1 Show1.addSeason(Season1) Show1.addSeason(Season2) Show2.addSeason(Season3) Show2.addSeason(Season4) s = self.BaIf1.compareDetails( Show1, Show2 ) assert (s.name, s.duration, s.backend, s.url ) == ( "Test Show One", "60", "dummybackend", "dummyurlone" ) s = self.BaIf1.compareDetails( Show1, Show2 ) assert (s.name, s.duration, s.backend, s.url ) == ( "Test Show One", "60", "dummybackend", "dummyurlone" ) def testCompareSeasons(self): Episode1 = Episode( "2", "What A Title", "6 November, 2008" ) Episode2 = Episode( "333", "For A TV Show", "18 November, 2008" ) Episode3 = Episode( "4", "What A Title", "6 November, 2008") Episode4 = Episode( "2", "What A Title", "6 November, 2008" ) Episode5 = Episode( "333", "For A TV Show", "18 November, 2008" ) Episode6 = Episode( "4", "What A Title", "6 November, 2008") Season1 = Season('1') Season2 = Season('2') Season1.addEpisode( Episode1 ) Season1.addEpisode( Episode2 ) Season1.addEpisode( Episode3 ) Season2.addEpisode( Episode4 ) Season2.addEpisode( Episode5 ) Season2.addEpisode( Episode6 ) assert self.BaIf1.compareSeasons( Season1, Season2 ).name == "1" assert self.BaIf1.compareSeasons( Season1, Season2 ).name == "1" def testCompareEpisodes(self): Episode1 = Episode( "2", "What A Title", "6 November, 2008" ) Episode2 = Episode( "2", "For A TV Show", "6 November, 2008" ) # Gives NotImplemented Error, which is correct behaviour. Episode3 = Episode( "2", "What A Title", "6 November, 2008") e = self.BaIf1.compareEpisodes(Episode1, Episode1 ) ( e.name, e.title, e.airdate )==( "2", "What A Title", "6 November, 2008" )
class testFilesystems : """ Test Filesystems Class. """ def setUp(self) : self.FS = Filesystems() # Filesystem dir is None def testLoadFilesystems( self ) : self.Tools = Tools() self.Tools.createRootDir() self.Tools.createFilesystemXML() self.FS = Filesystems(self.Tools.filetypesXML) Ext3FS = self.FS.getFilesystem(Filesystem('ext3')) NTFSFS = self.FS.getFilesystem(Filesystem('ntfs')) Filesystem3 = Filesystem('FS3') assert self.FS.addFilesystem( Ext3FS ) == None assert self.FS.addFilesystem( Filesystem('ntfs') ) == None assert self.FS.addFilesystem( Filesystem3 ) == Filesystem3 assert self.FS.getFilesystem( Filesystem3 ) == Filesystem3 assert self.FS.getFilesystem( NTFSFS ) == NTFSFS assert self.FS.getFilesystem( Ext3FS ) == Ext3FS assert self.FS.removeFilesystem( NTFSFS ) == NTFSFS assert self.FS.removeFilesystem( NTFSFS ) == None assert self.FS.removeFilesystem( Ext3FS ) == Ext3FS assert self.FS.removeFilesystem( Ext3FS ) == None self.Tools.removeTempFiles() def testAddFilesystem( self ) : Filesystem1 = Filesystem('FS1') Filesystem2 = Filesystem('FS2') Filesystem3 = Filesystem('FS3') assert self.FS.addFilesystem( Filesystem1 ) == Filesystem1 assert self.FS.addFilesystem( Filesystem1 ) == None assert self.FS.addFilesystem( Filesystem2 ) == Filesystem2 assert self.FS.addFilesystem( Filesystem('FS2') ) == None assert self.FS.addFilesystem( Filesystem3 ) == Filesystem3 def testGetFilesystem(self) : Filesystem1 = Filesystem('FS1') Filesystem2 = Filesystem('FS2') Filesystem3 = Filesystem('FS3') self.FS.addFilesystem( Filesystem1 ) self.FS.addFilesystem( Filesystem2 ) assert self.FS.getFilesystem( Filesystem1 ) == Filesystem1 assert self.FS.getFilesystem( Filesystem3 ) == None assert self.FS.getFilesystem( Filesystem('FS2') ) == Filesystem2 assert self.FS.getFilesystem( Filesystem('FS3') ) == None def testRemoveFilesystem(self) : Filesystem1 = Filesystem('FS1') Filesystem2 = Filesystem('FS2') Filesystem3 = Filesystem('FS3') self.FS.addFilesystem( Filesystem1 ) self.FS.addFilesystem( Filesystem2 ) assert self.FS.removeFilesystem( Filesystem1 ) == Filesystem1 assert self.FS.removeFilesystem( Filesystem1 ) == None assert self.FS.removeFilesystem( Filesystem('FS3') ) == None assert self.FS.removeFilesystem( Filesystem('FS2') ) == Filesystem2
class testRename : """ Test Rename Class """ def setUp(self) : self.Tools = Tools() self.Tools.createRootDir() self.Tools.createTempFiles() self.Tools.createDatabaseFiles() self.Tools.createFilesystemXML() self.database = Database(self.Tools.databaseDir) self.database.loadDB() self.folder1 = Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[0]), self.Tools.databaseDir) self.folder2 = Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[1]), self.Tools.databaseDir) self.folder3 = Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[2]), self.Tools.databaseDir) def tearDown(self): self.Tools.removeTempFiles() def testAddFolder(self) : rename = Rename( self.Tools.databaseDir, self.Tools.filetypesXML ) assert rename.addFolder( self.folder1 ) == self.folder1 assert rename.addFolder( self.folder1 ) == None assert rename.addFolder( self.folder1 ) == self.folder1 assert rename.addFolder( Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[1]), self.Tools.databaseDir) ) == None assert rename.addFolder( self.folder3 ) == self.folder3 def testAddFoldersRecursively(self) : rename = Rename( self.Tools.databaseDir, self.Tools.filetypesXML ) rename.addFolder( self.folder1 ) assert rename.addFoldersRecursively( Folder(self.Tools.rootDir) ) == Folder(self.Tools.rootDir) assert [ folder.path for folder in rename.folders ] == ['/tmp/veefire/Black Books', '/tmp/veefire', '/tmp/veefire/Spaced', '/tmp/veefire/CSI', '/tmp/veefire/database'] rename.addFolder( self.folder1 ) rename.addFolder( self.folder1 ) rename.addFolder( Folder('/tmp/veefire/Spaced' )) rename.addFolder( Folder('/tmp/veefire/Spaced' )) rename.addFolder( Folder('/tmp/veefire/Spaced' )) assert rename.removeFolder(Folder('/tmp/veefire')).path == '/tmp/veefire' assert [ folder.path for folder in rename.folders ] == ['/tmp/veefire/Black Books', '/tmp/veefire/Spaced', '/tmp/veefire/CSI', '/tmp/veefire/database'] assert rename.removeFolder(Folder('/tmp/veefire/Spaced')).path == '/tmp/veefire/Spaced' assert rename.removeFolder(Folder('/tmp/veefire/Spaced')) == None assert [ folder.path for folder in rename.folders ] == ['/tmp/veefire/Black Books', '/tmp/veefire/CSI', '/tmp/veefire/database'] def testGetFolder(self) : rename = Rename( self.Tools.databaseDir, self.Tools.filetypesXML ) rename.addFolder( self.folder1 ) rename.addFolder( self.folder1 ) assert rename.getFolder( self.folder1 ) == True assert rename.getFolder( self.folder3 ) == None assert rename.getFolder( Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[1]), self.Tools.databaseDir) ) == None assert rename.getFolder( Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[2]), self.Tools.databaseDir) ) == None def testRemoveFolder(self) : rename = Rename( self.Tools.databaseDir, self.Tools.filetypesXML ) rename.addFolder( self.folder1 ) rename.addFolder( self.folder1 ) assert rename.removeFolder( self.folder1 ) == self.folder1 assert rename.removeFolder( self.folder1 ) == None assert rename.removeFolder( Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[2]), self.Tools.databaseDir) ) == None assert rename.removeFolder( Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[1]), self.Tools.databaseDir) ) == self.folder1 def testGetMatchingShows(self): self.folder1.loadFiles() self.folder2.loadFiles() self.folder3.loadFiles() rename1 = Rename( self.Tools.databaseDir, self.Tools.filetypesXML ) rename2 = Rename( self.Tools.databaseDir, self.Tools.filetypesXML ) rename3 = Rename( self.Tools.databaseDir, self.Tools.filetypesXML ) rename1.addFolder(self.folder1) rename1.addFolder(self.folder2) rename2.addFolder(self.folder1) rename2.addFolder(self.folder3) rename3.addFolder(self.folder3) assert [ fn.CorrectShow.name for fo in rename1.getMatchingShows() for fn in fo.getMatchingShows()] == ['Black Books', 'Black Books', 'C.S.I', 'C.S.I'] assert [ fn.CorrectShow.name for fo in rename2.getMatchingShows() for fn in fo.getMatchingShows()] == ['Black Books', 'Black Books', 'Spaced', 'Spaced'] assert [ fn.CorrectShow.name for fo in rename3.getMatchingShows() for fn in fo.getMatchingShows()] == ['Spaced', 'Spaced'] def testGeneratePreviews(self): self.folder1.loadFiles() self.folder2.loadFiles() self.folder3.loadFiles() rename1 = Rename( self.Tools.databaseDir, self.Tools.filetypesXML ) rename2 = Rename( self.Tools.databaseDir, self.Tools.filetypesXML ) rename3 = Rename( self.Tools.databaseDir, self.Tools.filetypesXML ) rename1.addFolder(self.folder1) rename1.addFolder(self.folder2) rename2.addFolder(self.folder1) rename2.addFolder(self.folder3) rename3.addFolder(self.folder3) rename1.getMatchingShows() rename2.getMatchingShows() rename3.getMatchingShows() assert [ fo for fo in rename1.generatePreviews('ext3') ] == [[('bb.s03e05.avi', 'Black Books - S03E05 - The Travel Writer.avi'), ('blackbooks.s01e02.avi', "Black Books - S01E02 - Manny's First Day.avi")], [('csiS01E11.avi', 'C.S.I - S01E11 - I-15 Murders.avi'), ('CSI.2x12.avi', "C.S.I - S02E12 - You've Got Male.avi")]] assert [ fo for fo in rename2.generatePreviews('ntfs', '%show[%season](%title)') ] == [[('bb.s03e05.avi', 'Black Books[03](The Travel Writer).avi'), ('blackbooks.s01e02.avi', 'Black Books[01](Mannys First Day).avi')], [('Spaced.S02E03.avi', 'Spaced[02](Mettle).avi'), ('Spaced.2x4.avi', 'Spaced[02](Help).avi')]] assert [ fo for fo in rename3.generatePreviews('ext3', '%show - %seasonx%episode - %title') ] == [[('Spaced.S02E03.avi', 'Spaced - 02x03 - Mettle.avi'), ('Spaced.2x4.avi', 'Spaced - 02x04 - Help.avi')]] def testRename(self): self.folder1.loadFiles() rename1 = Rename( self.Tools.databaseDir, self.Tools.filetypesXML ) rename1.addFolder(self.folder1) rename1.addFolder(self.folder2) rename1.getMatchingShows() rename1.generatePreviews('ext3') assert os.listdir(self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] rename1.rename() assert os.listdir(self.folder1.path) == ["Black Books - S01E02 - Manny's First Day.avi", 'Black Books - S03E05 - The Travel Writer.avi'] def testRevert(self): self.folder1.loadFiles() rename1 = Rename( self.Tools.databaseDir, self.Tools.filetypesXML ) rename1.addFolder(self.folder1) rename1.addFolder(self.folder2) rename1.getMatchingShows() rename1.generatePreviews('ext3') assert os.listdir(self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] rename1.rename() assert os.listdir(self.folder1.path) == ["Black Books - S01E02 - Manny's First Day.avi", 'Black Books - S03E05 - The Travel Writer.avi'] rename1.revert() assert os.listdir(self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi']
class testFileName : """ Test FileName Class """ def setUp(self) : self.Tools = Tools() self.Tools.createRootDir() self.Tools.createTempFiles() self.Tools.createDatabaseFiles() self.Tools.createFilesystemXML() self.database = Database(self.Tools.databaseDir) self.database.loadDB() smallville = Show('Smallville', '60', 'dummy', 'dummy') smallville.addAlias(Alias('smallville')) smallville.addEpisode( Episode('10', 'Bizarro', 'dummy'), Season('7') ) self.database.addShow( smallville ) self.files = [ 'blackbooks.s01e02.avi', 'spaced.2x03.avi', 'csi.s02E13.avi', 'black books - 03x02 - Six of One.avi', 'Smallville.S07E10.HDTV.XviD-XOR.avi' ] self.filenames = [ FileName( files, self.database ) for files in self.files ] def tearDown(self): self.Tools.removeTempFiles() def testGetPattern(self): dummydb = Database() dummyFN = FileName( 'dummy', dummydb ) assert [ fn.getPattern() for fn in self.filenames ] == \ [ dummyFN.pattern1, dummyFN.pattern2, dummyFN.pattern1, dummyFN.pattern2, dummyFN.pattern1 ] def testGetSeason(self): assert [ fn.getSeason() for fn in self.filenames ] == \ [ '1', '2', '2', '3', '7' ] def testGetEpisode(self): assert [ fn.getEpisode() for fn in self.filenames ] == \ [ '2', '3', '13', '2', '10' ] def testGetMatchingShows(self): assert [ fn.getMatchingShows().name for fn in self.filenames ] == \ [ 'Black Books', 'Spaced', 'C.S.I', 'Black Books', 'Smallville' ] def testGeneratePreview(self): result = [] for fn in self.filenames : fn.getMatchingShows() result.append( fn.generatePreview(self.Tools.filetypesXML, 'ext3', '%show - %seasonx%episode - %title ( %arc - %airdate )' ) ) assert result == [ ('blackbooks.s01e02.avi', "Black Books - 01x02 - Manny's First Day ( none - 6 October 2000 ).avi"), ('spaced.2x03.avi', 'Spaced - 02x03 - Mettle ( none - 9 March 2001 ).avi'), ('csi.s02E13.avi', 'C.S.I - 02x13 - Identity Crisis ( none - 17 January 2002 ).avi'), ('black books - 03x02 - Six of One.avi', 'Black Books - 03x02 - Elephants and Hens ( none - 18 March 2004 ).avi'), ('Smallville.S07E10.HDTV.XviD-XOR.avi', 'Smallville - 07x10 - Bizarro ( none - dummy ).avi')] result = [] for fn in self.filenames : fn.getMatchingShows() result.append( fn.generatePreview(self.Tools.filetypesXML, 'ntfs', '%show - %seasonE%episode - %title ( %arc - %airdate )' ) ) assert result == [('blackbooks.s01e02.avi', 'Black Books - 01E02 - Mannys First Day ( none - 6 October 2000 ).avi'), ('spaced.2x03.avi', 'Spaced - 02E03 - Mettle ( none - 9 March 2001 ).avi'), ('csi.s02E13.avi', 'C.S.I - 02E13 - Identity Crisis ( none - 17 January 2002 ).avi'), ('black books - 03x02 - Six of One.avi', 'Black Books - 03E02 - Elephants and Hens ( none - 18 March 2004 ).avi'), ('Smallville.S07E10.HDTV.XviD-XOR.avi', 'Smallville - 07E10 - Bizarro ( none - dummy ).avi')] def testGetShowDetails(self): testShows = [ fn.getShowDetails( self.Tools.filetypesXML, fn.getMatchingShows() ) for fn in self.filenames ] assert [ len(ts.seasons) for ts in testShows ] == [1, 1, 1, 1, 1] assert [ len(ts.seasons[0].episodes) for ts in testShows ] == [1, 1, 1, 1, 1] correctShow1 = Show( 'Black Books', '30', 'imdbtvbackend', 'tt0262150' ) correctShow1.addEpisode( Episode( '2', "Manny's First Day", '6 October 2000', 'none'), Season('1') ) correctShow2 = Show( 'Spaced', '60', 'imdbtvbackend', 'tt0187664' ) correctShow2.addEpisode( Episode( '3', 'Mettle', '9 March 2001', 'none'), Season('2') ) correctShow3 = Show( 'C.S.I', '60', 'imdbtvbackend', 'tt0247082' ) correctShow3.addEpisode( Episode( '13', 'Identity Crisis', '17 January 2002', 'none'), Season('2') ) def compareShows(show, other) : if show.name != other.name or show.duration != other.duration or show.backend != other.backend or show.url != other.url : assert False elif show.seasons[0].name != other.seasons[0].name : assert False elif show.seasons[0].episodes[0].name != other.seasons[0].episodes[0].name or show.seasons[0].episodes[0].title != other.seasons[0].episodes[0].title or show.seasons[0].episodes[0].airdate != other.seasons[0].episodes[0].airdate or show.seasons[0].episodes[0].arc != other.seasons[0].episodes[0].arc : assert False else : return True assert compareShows( testShows[0], correctShow1 ) assert compareShows( testShows[1], correctShow2 ) assert compareShows( testShows[2], correctShow3 ) def testGenerateFileName(self): #FIXME: More than one Style, different file suffixes, arcs. # generateFileName(Style=None) correctShow1 = Show( 'Black Books', '30', 'imdbtvbackend', 'tt0262150' ) correctShow1.addEpisode( Episode( '2', "A test's test' & a test / # a test", '6 October 2000', 'none'), Season('1') ) correctShow2 = Show( 'Spaced', '60', 'imdbtvbackend', 'tt0187664' ) correctShow2.addEpisode( Episode( '3', "A test's test' & a test / # a test", '9 March 2001', 'none'), Season('2') ) correctShow3 = Show( 'C.S.I', '60', 'imdbtvbackend', 'tt0247082' ) correctShow3.addEpisode( Episode( '13', "Identity Crisis / # 4587", '17 January 2002', 'none'), Season('2') ) self.FN = FileName('', self.database) self.FN.fileSuffix = '.avi' fileName1 = self.FN.generateFileName( correctShow1, self.Tools.filetypesXML, 'ext3', '%show.S%seasonE%episode.%title.%arc.%airdate' ) fileName2 = self.FN.generateFileName( correctShow2, self.Tools.filetypesXML, 'ntfs', '%show.S%seasonE%episode.%title.%arc.%airdate' ) fileName3 = self.FN.generateFileName( correctShow3, self.Tools.filetypesXML, 'ext3', '%show.S%seasonE%episode.%title.%arc.%airdate' ) assert fileName1 == "Black Books.S01E02.A test's test' & a test or # a test.none.6 October 2000.avi" assert fileName2 == "Spaced.S02E03.A tests test and a test or No. a test.none.9 March 2001.avi" assert fileName3 == "C.S.I.S02E13.Identity Crisis or # 4587.none.17 January 2002.avi" def testRenameFile(self) : self.folder1 = Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[0]), self.Tools.databaseDir) self.folder1.loadFiles() self.filename1 = FileName( 'blackbooks.s01e02.avi', self.database ) self.filename1.getMatchingShows() self.filename1.generatePreview(self.Tools.filetypesXML, 'ext3', '%show - %seasonx%episode - %title ( %arc - %airdate )') assert os.listdir(self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] self.filename1.renameFile(self.folder1.path) assert os.listdir(self.folder1.path) == ['bb.s03e05.avi', "Black Books - 01x02 - Manny's First Day ( none - 6 October 2000 ).avi"] def testRevertFile(self) : self.folder1 = Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[0]), self.Tools.databaseDir) self.folder1.loadFiles() self.filename1 = FileName( 'blackbooks.s01e02.avi', self.database ) self.filename1.getMatchingShows() self.filename1.generatePreview(self.Tools.filetypesXML, 'ext3', '%show - %seasonx%episode - %title ( %arc - %airdate )') assert os.listdir(self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] self.filename1.renameFile(self.folder1.path) assert os.listdir(self.folder1.path) == ['bb.s03e05.avi', "Black Books - 01x02 - Manny's First Day ( none - 6 October 2000 ).avi"] self.filename1.revertFile(self.folder1.path) assert os.listdir(self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi']
class testFolder : """ Test Folder Class """ def setUp(self) : self.Tools = Tools() self.Tools.createRootDir() self.Tools.createTempFiles() self.Tools.createDatabaseFiles() self.Tools.createFilesystemXML() self.database = Database(self.Tools.databaseDir) self.database.loadDB() self.folder1 = Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[0]), self.Tools.databaseDir) self.folder2 = Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[1]), self.Tools.databaseDir) self.folder3 = Folder(os.path.join(self.Tools.rootDir, self.Tools.testDirs[2]), self.Tools.databaseDir) def tearDown(self): self.Tools.removeTempFiles() def testLoadFiles(self): self.folder1.loadFiles() self.folder2.loadFiles() self.folder3.loadFiles() assert [ fn.fileName for fn in self.folder1.fileNames ] == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] assert [ fn.fileName for fn in self.folder2.fileNames ] == ['csiS01E11.avi', 'CSI.2x12.avi'] assert [ fn.fileName for fn in self.folder3.fileNames ] == ['Spaced.S02E03.avi', 'Spaced.2x4.avi'] def testGetMatchingShows(self): self.folder1.loadFiles() self.folder2.loadFiles() self.folder3.loadFiles() assert [ fn.CorrectShow.name for fn in self.folder1.getMatchingShows() ] == ['Black Books', 'Black Books'] assert [ fn.CorrectShow.name for fn in self.folder2.getMatchingShows() ] == ['C.S.I', 'C.S.I'] assert [ fn.CorrectShow.name for fn in self.folder3.getMatchingShows() ] == ['Spaced', 'Spaced'] def testGeneratePreviews(self): self.folder1.loadFiles() self.folder2.loadFiles() self.folder3.loadFiles() self.folder1.getMatchingShows() self.folder2.getMatchingShows() self.folder3.getMatchingShows() assert [ fn for fn in self.folder1.generatePreviews(self.Tools.filetypesXML, 'ext3', '%show - S0%sesonE0%episode - %title') ] == [('bb.s03e05.avi', 'Black Books - S0%sesonE005 - The Travel Writer.avi'), ('blackbooks.s01e02.avi', "Black Books - S0%sesonE002 - Manny's First Day.avi")] assert [ fn for fn in self.folder2.generatePreviews(self.Tools.filetypesXML, 'ntfs', '%show - S0%sesonE0%episode - %title') ] == [('csiS01E11.avi', 'C.S.I - S0%sesonE011 - I-15 Murders.avi'), ('CSI.2x12.avi', 'C.S.I - S0%sesonE012 - Youve Got Male.avi')] assert [ fn for fn in self.folder3.generatePreviews(self.Tools.filetypesXML, 'ext3', '%show - S0%sesonE0%episode - %title') ] == [('Spaced.S02E03.avi', 'Spaced - S0%sesonE003 - Mettle.avi'), ('Spaced.2x4.avi', 'Spaced - S0%sesonE004 - Help.avi')] def testRename(self): self.folder1.loadFiles() self.folder1.getMatchingShows() self.folder1.generatePreviews(self.Tools.filetypesXML, 'ext3', '%show - S0%sesonE0%episode - %title') assert os.listdir(self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] self.folder1.rename() assert os.listdir(self.folder1.path) == ["Black Books - S0%sesonE002 - Manny's First Day.avi", 'Black Books - S0%sesonE005 - The Travel Writer.avi'] def testRevert(self): self.folder1.loadFiles() self.folder1.getMatchingShows() self.folder1.generatePreviews(self.Tools.filetypesXML, 'ext3', '%show - S0%sesonE0%episode - %title') assert os.listdir(self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi'] self.folder1.rename() assert os.listdir(self.folder1.path) == ["Black Books - S0%sesonE002 - Manny's First Day.avi", 'Black Books - S0%sesonE005 - The Travel Writer.avi'] self.folder1.revert() assert os.listdir(self.folder1.path) == ['bb.s03e05.avi', 'blackbooks.s01e02.avi']