class testBackend() : ''' Unit test for :class:`backends.imdbtv.Backend`. ''' def setUp(self) : self.backend = Backend() self.tools = tests.testproperties.Tools() self.tools.createRootDir() self.tools.createDatabaseFiles() 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) self.database1.database[0].clearEpisodes() assert [ show.name for show in content.keys() ] == ['Spaced'] content = self.backend.downloadShowList(self.database2.database) self.database2.database[0].clearEpisodes() assert [ show.name for show in content.keys() ] == ['Black Books'] def testGetShowDetails(self): #self.database1.database[0].clearEpisodes() 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')] self.database1.database[0].clearEpisodes() 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', u'1', u'1', u'Beginnings'), ('Spaced', u'1', u'2', u'Gatherings'), ('Spaced', u'1', u'3', u'Art'), ('Spaced', u'1', u'4', u'Battles'), ('Spaced', u'1', u'5', u'Chaos'), ('Spaced', u'1', u'6', u'Epiphanies'), ('Spaced', u'1', u'7', u'Ends'), ('Spaced', u'2', u'1', u'Back'), ('Spaced', u'2', u'2', u'Change'), ('Spaced', u'2', u'3', u'Mettle'), ('Spaced', u'2', u'4', u'Help'), ('Spaced', u'2', u'5', u'Gone'), ('Spaced', u'2', u'6', u'Dissolution'), ('Spaced', u'2', u'7', u'Leaves')] #self.database2.database[0].clearEpisodes() 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')] self.database2.database[0].clearEpisodes() 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', u'1', u'1', u'Cooking the Books'), ('Black Books', u'1', u'2', u"Manny's First Day"), ('Black Books', u'1', u'3', u'Grapes of Wrath'), ('Black Books', u'1', u'4', u'The Blackout'), ('Black Books', u'1', u'5', u'The Big Lock-Out'), ('Black Books', u'1', u'6', u"He's Leaving Home"), ('Black Books', u'2', u'1', u'The Entertainer'), ('Black Books', u'2', u'2', u'Fever'), ('Black Books', u'2', u'3', u'The Fixer'), ('Black Books', u'2', u'4', u'Blood'), ('Black Books', u'2', u'5', u'Hello Sun'), ('Black Books', u'2', u'6', u'A Nice Change'), ('Black Books', u'3', u'1', u'Manny Come Home'), ('Black Books', u'3', u'2', u'Elephants and Hens'), ('Black Books', u'3', u'3', u'Moo-Ma and Moo-Pa'), ('Black Books', u'3', u'4', u'A Little Flutter'), ('Black Books', u'3', u'5', u'Travel Writer'), ('Black Books', u'3', u'6', u'Party')]
def getShowDetails ( self, showandseasonsdict ) : ''' Download a list of Show object's episodes. :param showandcontentlist: dictionary { Show : content( raw html from web page ) } :type showandcontentlist: :mod:`dict` :returns: Database with api.dbapi.Show objects :rtype: :class:`api.dbapi.Database` ''' updateDB = Database() #TODO: Test for changes in code. for Show, seasons in showandseasonsdict.items() : for season, episodes in seasons.items() : for episode in episodes : assert season == episode["season"] #print episode["episode"] episodenr = episode["episode"].findAll('meta', { "itemprop" : "episodeNumber" })[0]["content"] #print episodenr episodename = episode["episode"].findAll('a', { "itemprop" : "name" })[0]["title"] #print episodename episodeairdate = episode["episode"].findAll('div', { "class" : "airdate" })[0].string.strip() #print episodeairdate Show.addEpisode( Episode( episodenr, episodename, episodeairdate ), Season( season ) ) updateDB.addShow( Show ) # seasons = BeautifulSoup.SoupStrainer('div', { "class" : re.compile("season-filter-all filter-season-[0-9]+") }) # # all = [ tag for tag in BeautifulSoup.BeautifulSoup( content, parseOnlyThese=seasons)] # # for i in xrange( 0, len(all)) : # ## Remove rubbish from the content. # [ tag.extract() for tag in all[i].findAll('hr') ] # [ tag.parent.extract() for tag in all[i].findAll('a', { "name" : re.compile("season-[0-9]+")} )] # # regexp = Regexes() # # for x in all : # for item in x.findAll('div', { "class" : re.compile("filter-all filter-year-[0-9]+")} ) : # ## Extract info in every episode/item, and add to one tuple # merge = regexp.extractEpSeTitle( str(item.find('h3')) ) + regexp.extractAirDate( str( item.find('strong') ) ) # if ( len(merge) == 4 ) : ## If merge is proper # Show.addEpisode( Episode( merge[1], regexp.removeEntities(merge[2]), merge[3] ), Season( merge[0] ) ) # updateDB.addShow( Show ) return updateDB
def setUp(self) : self.backend = Backend() self.tools = tests.testproperties.Tools() self.tools.createRootDir() self.tools.createDatabaseFiles() 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 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 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 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 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 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 setUp(self) : self.Tools = Tools() self.Tools.createRootDir() self.Tools.createDatabaseFiles() self.database = Database(self.Tools.databaseDir)
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 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 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']