def test_Dataheap_VideoGrabber_001_search_01(self): """Test 'search' method from MythTV.VideoGrabber using 'searchVideos'. """ from MythTV import MythDB, RecordedArtwork, Video, VideoGrabber with add_log_flags(): self.mydb = MythDB() title = self.testenv['VIDTITLE'] cast = self.testenv['VIDCAST'] inetrefstr = self.testenv['VIDINETREF'] lang = self.testenv['VIDLANGUAGE'] # remove grabber from inetref: try: inetref = inetrefstr.split('_')[-1] except IndexError: inetref = inetrefstr vids = self.mydb.searchVideos( title = title ) vid = next(vids) # print("%s : %s" %(vid.title, type(vid.title))) self.assertTrue(isinstance(vid, Video)) grab = VideoGrabber("Movie", lang = lang, db = self.mydb) metadatalistgen = grab.search(vid.title, subtitle=None, tolerance=1) mlist = list(metadatalistgen) inetref_found = False for m in mlist: if (m.inetref == inetref): inetref_found = True break self.assertTrue(inetref_found)
def test_Methodheap_MythXML_002_01(self): """Test MythXML.getHosts() with logging.""" with add_log_flags(): m_instance = MythXML() hosts = m_instance.getHosts() bename = self.testenv['BACKENDNAME'] self.assertTrue(bename in hosts)
def test_Dataheap_VideoGrabber_002_importMetadata_02(self): """Test 'VideoGrabber.grabInetref' method and 'Video.importMetadata' methods using predefined values. See 'mythvidexport.py' as well. See MythtTV trac tickets #12243 and #12245. Note: Use a TV series with season and episode. """ from MythTV import MythDB, Video, VideoGrabber with add_log_flags(): self.mydb = MythDB() alf_metadata = { u'title' : u'Alf', u'subtitle' : u'Wedding Bell Blues', u'season' : 2, u'episode' : 4, u'inetref' : '78020'} grab = VideoGrabber('TV', lang='en', db=self.mydb) metadata = grab.grabInetref( alf_metadata['inetref'], alf_metadata['season'], alf_metadata['episode']) # print(metadata.collectionref) # ---> '78020' self.assertEqual(metadata.collectionref, alf_metadata[u'inetref']) # run the grabber again, but based on a 'VideoMetadata' object new_metadata = grab.grabInetref(metadata) # check if collected metadata are the equal self.assertEqual(new_metadata, metadata)
def test_Dataheap_VideoGrabber_001_sortedSearch_01(self): """Test 'sortedSearch' method from MythTV.VideoGrabber using predefined values. """ from MythTV import MythDB, RecordedArtwork, Video, VideoGrabber with add_log_flags(): self.mydb = MythDB() title = self.testenv['VIDTITLE_DE'] cast = self.testenv['VIDCAST_DE'] inetrefstr = self.testenv['VIDINETREF_DE'] lang = self.testenv['VIDLANGUAGE_DE'] # remove grabber from inetref: try: inetref = inetrefstr.split('_')[-1] except IndexError: inetref = inetrefstr grab = VideoGrabber("Movie", lang=lang, db=self.mydb) metadatalist = grab.sortedSearch(title, subtitle=None, tolerance=2) inetref_found = False for m in metadatalist: if (m.inetref == inetref): inetref_found = True break self.assertTrue(inetref_found)
def test_Methodheap_MythXML_002_02(self): """Test MythXML.getKeys() with logging.""" a = False with add_log_flags(): m_instance = MythXML() keys_list = m_instance.getKeys() self.assertTrue(u'MenuTheme' in keys_list) a = (len(tailandgrep('/tmp/my_logfile', 3, r'/Myth/GetKeys')) > 0) self.assertTrue(a)
def test_Methodheap_MythXML_002_03(self): """Test MythXML.getSetting() with logging.""" a = False with add_log_flags(): m_instance = MythXML() port = m_instance.getSetting('BackendServerPort', default='1111') self.assertTrue(int(port), 6543) a = (len(tailandgrep('/tmp/my_logfile', 3, r'BackendServerPort')) > 0) self.assertTrue(a)
def test_Methodheap_MythXML_002_08(self): """Test MythXML.getExpiring() with logging.""" a = False with add_log_flags(): m_instance = MythXML() rec_list = m_instance.getExpiring() rec = next(rec_list) self.assertTrue(len(rec.title) > 0) a = (len(tailandgrep('/tmp/my_logfile', 3, r'GetExpiringList')) > 0) self.assertTrue(a)
def test_MSearch_002_03(self): """Test MSearch.searchMythFE() logging.""" a = False with add_log_flags(): m_instance = MSearch() g_generator = m_instance.searchMythFE() u_dict = next(g_generator) self.assertTrue('location' in u_dict) self.assertIsNotNone(u_dict['location']) self.assertTrue('MediaRenderer' in u_dict['st']) a = (len(tailandgrep('/tmp/my_logfile', 1, u_dict['st'])) > 0) self.assertTrue(a)
def setUp(self): # create a file with this name if it does not exist self.frtitle = self.testenv["VIDFRTITLE"] # Le Dernier Métro" self.frfilename = self.testenv["VIDFRFILENAME"] self.frpath = self.testenv["VIDFRPATH"] self.frfullpath = os.path.join(self.frpath, self.frfilename) with add_log_flags(): self.mydb = MythDB() self.master_backend_ip = self.mydb.settings['NULL']['MasterServerIP'] shcmd = 'head -c 10M </dev/urandom > "%s"' % self.frfullpath cmd = "ssh mythtv@%s '%s'" % (self.master_backend_ip, shcmd) print(cmd) self.result = subprocess.call(cmd, shell=True) # will be checked later
def test_Methodheap_MythXML_002_06(self): """Test MythXML.getChannelIcon() with logging.""" a = False b = False with add_log_flags(): m_instance = MythXML() icon = m_instance.getChannelIcon(self.testenv['RECCHANID']) with open('/tmp/icon', 'wb') as f: f.write(icon) os.system('file /tmp/icon >> /tmp/my_logfile') a = (len(tailandgrep('/tmp/my_logfile', 2, 'JPEG|PNG')) > 0) self.assertTrue(a) b = (len(tailandgrep('/tmp/my_logfile', 3, r'GetChannelIcon')) > 0) self.assertTrue(b)
def test_Methodheap_MythXML_002_09(self): """Test MythXML.getPreviewImage().""" a = False with add_log_flags(): m_instance = MythXML() rec_chanid = self.testenv['DOWNCHANID'] rec_starttime = self.testenv['DOWNSTARTTIME'] preview = m_instance.getPreviewImage(str(rec_chanid), rec_starttime) with open('/tmp/preview', 'wb') as f: f.write(preview) out1 = System.system('file /tmp/preview') a = (len(tailandgrep('/tmp/my_logfile', 8, 'JPEG|PNG')) > 0) self.assertTrue(a)
def test_Dataheap_VideoGrabber_001_grabInetref_01(self): """Test 'grabInetref' and 'toXML' methods from MythTV.VideoGrabber using predefined values. """ from MythTV import MythDB, RecordedArtwork, Video, VideoGrabber with add_log_flags(): self.mydb = MythDB() title = self.testenv['VIDTITLE_DE'] cast = self.testenv['VIDCAST_DE'] inetrefstr = self.testenv['VIDINETREF_DE'] lang = self.testenv['VIDLANGUAGE_DE'] # remove grabber from inetref: try: inetref = inetrefstr.split('_')[-1] except IndexError: inetref = inetrefstr grab = VideoGrabber("Movie", lang=lang, db=self.mydb) metadatalist = grab.sortedSearch(title, subtitle=None, tolerance=2) details = grab.grabInetref(metadatalist[0].inetref) # details has lists of dicts for # 'certifications', 'categories', 'countries', 'studios', 'people', 'images' names = [n.name for n in details.people] self.assertTrue(cast in names) tree = etree.XML(u'<metadata></metadata>') tree.append(details.toXML()) xml_str = etree.tostring ( tree , pretty_print = True , xml_declaration = True , encoding = "UTF-8" , standalone = "yes" ) xml_file = open("/tmp/details.xml", "wb") xml_file.write(xml_str) xml_file.close() # read xml file and check for cast root = etree.parse(r'/tmp/details.xml').getroot() cast_found = False for name in root.findall('item/people/person'): if (name.attrib['name'] == cast): cast_found = True self.assertTrue(cast_found)
def test_Methodheap_MythXML_002_04(self): """Test MythXML.getProgramGuide() with logging.""" a = False with add_log_flags(): now_0 = pdtime.now() now_4 = now_0 + pddelta(hours=4) m_instance = MythXML() guide_list = m_instance.getProgramGuide(now_0.isoformat(), now_4.isoformat(), self.testenv['RECCHANID'], numchan=None) prog = next(guide_list) self.assertTrue(len(prog.title) > 0) a = (len(tailandgrep('/tmp/my_logfile', 20, r'GetProgramGuide')) > 0) self.assertTrue(a)
def test_Methodheap_MythXML_002_010(self): """Test MythXML.getRecorded() during standard time and daylight saving time. """ preview_cet_is_pic = False preview_cest_is_pic = False with add_log_flags(): m_instance = MythXML() progs = m_instance.getRecorded() try: found_cet = False found_cest = False while True: p = next(progs) if not found_cet: if (p.starttime > self.t1_cet and p.starttime < self.t2_cet): pcet = p found_cet = True if not found_cest: if (p.starttime > self.t1_cest and p.starttime < self.t2_cest): pcest = p found_cest = True if (found_cet and found_cest): break except StopIteration: raise preview_cet = m_instance.getPreviewImage(str(pcet.chanid), pcet.recstartts) with open('/tmp/preview_cet', 'wb') as f: f.write(preview_cet) out_cet = System.system('file /tmp/preview_cet') preview_cet_is_pic = (len( tailandgrep('/tmp/my_logfile', 2, 'JPEG|PNG')) > 0) preview_cest = m_instance.getPreviewImage(str(pcest.chanid), pcest.recstartts) with open('/tmp/preview_cest', 'wb') as f: f.write(preview_cest) out_cest = System.system('file /tmp/preview_cest') preview_cest_is_pic = (len( tailandgrep('/tmp/my_logfile', 2, 'JPEG|PNG')) > 0) self.assertTrue(preview_cet_is_pic) self.assertTrue(preview_cest_is_pic)
def test_MSearch_002_01(self): """Test MSearch.search() logging.""" a = False b = False c = False with add_log_flags(): m_instance = MSearch() g_generator = m_instance.search() u_dict = next(g_generator) self.assertTrue('location' in u_dict) self.assertIsNotNone(u_dict['location']) a = (len( tailandgrep('/tmp/my_logfile', 3, r'Port 1900 opened for UPnP search')) > 0) b = (len(tailandgrep('/tmp/my_logfile', 4, r'running UPnP search')) > 0) c = (len(tailandgrep('/tmp/my_logfile', 6, u_dict['st'])) > 0) self.assertTrue(a) self.assertTrue(b) self.assertTrue(c)
def test_logging_OptParse_002_01(self): """Test if 'OptParse' works with MythLog.""" # set default values acc. source code m_dblog = False m_loglevel = LOGLEVEL.INFO m_verbose = LOGMASK.GENERAL m_logfile = stdout with add_log_flags(): m = MythLog('simple_test') #print ("m._LEVEL = %d" %m._LEVEL) #print ("m._MASK = %d" %m._MASK) #print ("m._DBLOG = %s" %m._DBLOG) #print (sys.argv) parser = OptionParser(prog="simple_test") # silence warnings in unittest about missing '-v' option: parser.add_option('-v', action='store_true', dest='uv', default=False, help='Use to set verbosity in unittest') # load MYthTV's extension m.loadOptParse(parser) opts, args = parser.parse_args() # check the options provided by 'additional_args': m_dblog = opts.nodblog # the option is named '--nodblog', stored in 'nodblog' m_loglevel = m._LEVEL m_verbose = m._MASK m_logfile = m._LOGFILE self.assertEqual(m_dblog, True) self.assertEqual(m_loglevel, LOGLEVEL.DEBUG) self.assertEqual( m_verbose, LOGMASK.ALL) ### XXX RER '-v' from unittest collides with this self.assertTrue(os.path.exists("/tmp/my_logfile"))
def test_Dataheap_VideoGrabber_002_importMetadata_01(self): """Test 'VideoGrabber.grabInetref' method and 'Video.importMetadata' methods using predefined values. See 'mythvidexport.py' as well. See MythtTV trac tickets #12243 and #12245. Note: Use a video with French accents in title and cast. """ from MythTV import MythDB, Video, VideoGrabber with add_log_flags(): title = u"Le Dernier Métro" castlist = [u"Catherine Deneuve", u"Gérard Depardieu", u"Andréa Ferréol"] inetstr = "tmdb3.py_1716" lang = "fr" filename = title + u".mkv" # create a new Video instance self.mydb = MythDB() vid = Video(db=self.mydb).create ({'title' : title, 'filename': filename, 'host' : self.mydb.getMasterBackend()}) # grab details from www.themoviedb.org grab = VideoGrabber('MOVIE', lang=lang, db=self.mydb) metadata = grab.grabInetref(inetstr) #print(type(metadata)) --> <class 'MythTV.system.VideoMetadata'> # import metadata into Video instance vid.importMetadata(metadata) #print(vid.cast[1].cast) ### ---> Gérard Depardieu # create a list of cast members from metadata vidcastmembers = [c.cast for c in vid.cast] # check for members in cast list self.assertTrue(self.is_sublist(castlist, vidcastmembers)) # delete previously created Video object in database vid.delete() #print(metadata.inetref) # --> 1716 self.assertEqual(metadata.inetref, inetstr.split('_')[-1]) # run the grabber again, but based on a 'VideoMetadata' object new_metadata = grab.grabInetref(metadata) # check if collected metadata are the equal self.assertEqual(new_metadata, metadata)
def test_Logging_argparse_002_01(self): """Test if 'argparse' works with MythLog.""" # set default values acc. source code m_dblog = True m_loglevel = LOGLEVEL.INFO m_verbose = LOGMASK.GENERAL m_logfile = stdout with add_log_flags(): m = MythLog('simple_test') parser = argparse.ArgumentParser(prog="simple_test") # load MYthTV's extension m.loadArgParse(parser) # unittest : first arguements are the test class or the verbosity flag # filter out arguements for unittesting: test_args = add_log_flags.additional_args # according 'add_log_flags', test_args should be: # ['--nodblog', '--loglevel', 'debug', '--verbose', 'all', '--logfile', '/tmp/my_logfile'] args = parser.parse_args(test_args) #print(test_args) #print(args) # check the options provided by 'additional_args': m_dblog = m._DBLOG m_loglevel = m._LEVEL m_verbose = m._MASK m_logfile = m._LOGFILE self.assertEqual(m_dblog, False) self.assertEqual(m_loglevel, LOGLEVEL.DEBUG) self.assertEqual(m_verbose, LOGMASK.ALL) self.assertTrue(os.path.exists("/tmp/my_logfile"))
def setUp(self): with add_log_flags(): # connect to frontend and prepare a recording to play self.fe = Frontend("%s" % (self.testenv['FRONTENDIP']), 6546) self.p = "%s %s" % (self.testenv['RECCHANID'], self.testenv['RECSTARTTIMEUTC'].strip('Z'))
def setUp(self): with add_log_flags(): self.mydb = MythDB() self.mybe = MythBE(db=self.mydb)
def setUp(self): with add_log_flags(): self.mydb = MythDB()