def test_hasChannel_False(self): channels = [] for x in range(0,5): channels.append(Channel( {'chanid':x, 'channum':'%d'%x, 'callsign':'WXYZ', 'name':'NBC9', 'icon':'nbc.jpg', 'cardid':4})) when(self.domainCache).getChannels().thenReturn(channels) self.assertFalse(self.tuner.hasChannel(Channel(dict(channum='6'))))
def test_constructor_IconMissing(self): channel = Channel({ 'chanid': 9, 'channum': '23_1', 'callsign': 'WXYZ', 'name': 'NBC9', 'cardid': 4 }) log.debug(channel) self.assertTrue(channel.getIconPath() is None)
def test_store_When_channel_has_iconpath_but_filename_misspelled_Then_do_nothing(self): # Setup channel = Channel({'name':'Bogus Channel', 'icon': 'bogusIcon.png', 'chanid': '9', 'callsign': 'WXYZ'}) downloader = MythChannelIconResolver(self.conn) # Test - download icons for first 5 channels dest = os.path.sep.join([tempfile.gettempdir(), str(channel.getChannelId()) + channel.getCallSign() + str(time.time()) + ".png"]) downloader.store(channel, dest) # Verify self.assertFalse(os.path.exists(dest))
def test_getSortableChannelNumber_When_channel_number_is_already_sortable_Then_return_channel_number( self): channel = Channel({ 'chanid': 9, 'channum': '23', 'callsign': 'WXYZ', 'name': 'NBC9', 'cardid': 4 }) log.debug('Sortable channel number = %s' % channel.getSortableChannelNumber()) self.assertEqual(23, channel.getSortableChannelNumber())
def loadChannels(self): if self.channels is None: self.channels = Channel.mergeChannels(self.domainCache.getChannels()) self.channels.sort(key=Channel.getSortableChannelNumber) self.channelsById = odict() for c in self.channels: self.channelsById[c.getChannelId()] = c
def getChannels(self): """ @return: cached list of viewable channels across all tuners. @rtype: Channel[] """ sql = """ select ch.chanid, ch.channum, ch.callsign, ch.name, ch.icon, ci.cardid from channel ch, cardinput ci where ch.channum is not null and ch.channum != '' and ch.visible = 1 and ch.sourceid = ci.sourceid order by ch.chanid """ self.cursor.execute(sql) rows = map(lambda r: self.toDict(self.cursor, r), self.cursor.fetchall()) from mythbox.mythtv.domain import Channel channels = map(lambda rd: Channel(rd), rows) return channels
def test_getSortableChannelNumber_When_channel_number_doesnt_seem_like_a_number_Then_return_channel_id( self): number = Channel({ 'chanid': 9, 'channum': '23/4', 'callsign': 'WXYZ', 'name': 'NBC9', 'cardid': 4 }).getSortableChannelNumber() log.debug('Sortable channel number = %s' % number) self.assertEqual(9, number)
def test_getSortableChannelNumber_When_channel_number_contains_dot_Then_return_channel_number_as_float( self): number = Channel({ 'chanid': 9, 'channum': '23.4', 'callsign': 'WXYZ', 'name': 'NBC9', 'cardid': 4 }).getSortableChannelNumber() log.debug('Sortable channel number = %s' % number) self.assertEqual(23.4, number)
def test_constructor(self): channel = Channel({ 'chanid': 9, 'channum': '23_1', 'callsign': 'WXYZ', 'name': 'NBC9', 'icon': 'nbc.jpg', 'cardid': 4 }) log.debug(channel) self.assertTrue(channel)
def test_store_When_channel_has_iconpath_but_filename_misspelled_Then_do_nothing( self): # Setup channel = Channel({ 'name': 'Bogus Channel', 'icon': 'bogusIcon.png', 'chanid': '9', 'callsign': 'WXYZ' }) downloader = MythChannelIconResolver(self.conn) # Test - download icons for first 5 channels dest = os.path.sep.join([ tempfile.gettempdir(), str(channel.getChannelId()) + channel.getCallSign() + str(time.time()) + ".png" ]) downloader.store(channel, dest) # Verify self.assertFalse(os.path.exists(dest))
def test_getChannels_CachingWorks(self): channels = [] for x in range(0,5): channels.append(Channel( {'chanid':x, 'channum':'%d'%x, 'callsign':'WXYZ', 'name':'NBC9', 'icon':'nbc.jpg', 'cardid':4})) when(self.domainCache).getChannels().thenReturn(channels) for x in range(10): channels = self.tuner.getChannels() verify(self.domainCache, 1).getChannels()
def test_store_When_channel_has_no_icon_Then_do_nothing(self): # Setup channel = Channel({ 'name': 'Bogus Channel', 'icon': None, 'chanid': '9', 'callsign': 'WXYZ' }) conn = Mock() downloader = MythChannelIconResolver(conn) # Test downloader.store(channel, 'bogusDestDir') # Verify verifyZeroInteractions(conn)
def testConstructor(self): fanArt = Mock() when(fanArt).pickPoster(any()).thenReturn(None) kwargs = {} kwargs['settings'] = Mock() kwargs['translator'] = Mock() kwargs['mythChannelIconCache'] = Mock() kwargs['platform'] = Mock() kwargs['fanArt'] = fanArt args = () win = LiveTvWindow(*args, **kwargs) channels = [] for i in range(10): c = Channel({ 'chanid':i, 'channum': '%d' % (i*2), 'name': 'name%d' % i, 'callsign':'callsign%d'%i }) channels.append(c) db = Mock() when(db).getChannels().thenReturn(channels) programs = [] for i in range(10): p = TVProgram({ 'title': 'title%d' % i, 'chanid':i, 'description':'desc%d'%i, 'category':'cat%d'%i}, translator=Mock()) programs.append(p) when(db).getTVGuideDataFlattened(any(), any(), any()).thenReturn(programs) dbFactory = Mock() when(dbFactory).create().thenReturn(db) from mythbox import pool pool.pools['dbPool'] = pool.Pool(dbFactory) win.onInit() win.onClick(self, 600)
ONE_DAY = datetime.timedelta(days=1) ONE_WEEK = datetime.timedelta(weeks=1) SORT_BY = odict.odict([ ('Date', { 'translation_id': m.DATE, 'sorter': lambda x: x.starttimeAsTime() }), ('Title', { 'translation_id': m.TITLE, 'sorter': lambda x: '%s %s' % (x.title(), x.starttimeAsTime()) }), ('Channel', { 'translation_id': m.CHANNEL, 'sorter': lambda x: Channel.sortableChannelNumber(x.getChannelNumber(), 0) }) ]) class UpcomingRecordingsWindow(BaseWindow): def __init__(self, *args, **kwargs): BaseWindow.__init__(self, *args, **kwargs) [ setattr(self, k, v) for k, v in kwargs.iteritems() if k in ( 'settings', 'translator', 'platform', 'fanArt', 'cachesByName', 'upcoming',
def test_getSortableChannelNumber_When_channel_number_is_already_sortable_Then_return_channel_number(self): channel = Channel({'chanid':9, 'channum':'23', 'callsign':'WXYZ', 'name':'NBC9', 'cardid':4}) log.debug('Sortable channel number = %s' % channel.getSortableChannelNumber()) self.assertEqual(23, channel.getSortableChannelNumber())
from mythbox.util import catchall_ui, run_async, catchall log = logging.getLogger('mythbox.ui') ID_PROGRAMS_LISTBOX = 600 ID_REFRESH_BUTTON = 250 ID_SORT_BY_BUTTON = 251 ID_SORT_ASCENDING_TOGGLE = 252 ONE_DAY = datetime.timedelta(days=1) ONE_WEEK = datetime.timedelta(weeks=1) SORT_BY = odict.odict([ ('Date', {'translation_id': m.DATE, 'sorter' : lambda x: x.starttimeAsTime() }), ('Title', {'translation_id': m.TITLE, 'sorter' : lambda x: '%s %s' % (x.title(), x.starttimeAsTime())}), ('Channel',{'translation_id': m.CHANNEL, 'sorter' : lambda x: Channel.sortableChannelNumber(x.getChannelNumber(), 0)})]) class UpcomingRecordingsWindow(BaseWindow): def __init__(self, *args, **kwargs): BaseWindow.__init__(self, *args, **kwargs) [setattr(self,k,v) for k,v in kwargs.iteritems() if k in ('settings','translator','platform','fanArt','cachesByName', 'upcoming', )] [setattr(self,k,v) for k,v in self.cachesByName.iteritems() if k in ('mythChannelIconCache','domainCache', )] self.programs = [] # [RecordedProgram] self.channelsById = None # {int:Channel} self.tunersById = None # {int:Tuner} self.listItemsByProgram = odict.odict() # {Program:ListItem} self.programsByListItem = odict.odict() # {ListItem:Program} self.sortBy = self.settings.get('upcoming_sort_by') self.sortAscending = self.settings.getBoolean('upcoming_sort_ascending')
def test_constructor_IconMissing(self): channel = Channel({'chanid':9, 'channum':'23_1', 'callsign':'WXYZ', 'name':'NBC9', 'cardid':4}) log.debug(channel) self.assertTrue(channel.getIconPath() is None)
from mythbox.util import catchall_ui, run_async, catchall log = logging.getLogger('mythbox.ui') ID_PROGRAMS_LISTBOX = 600 ID_REFRESH_BUTTON = 250 ID_SORT_BY_BUTTON = 251 ID_SORT_ASCENDING_TOGGLE = 252 ONE_DAY = datetime.timedelta(days=1) ONE_WEEK = datetime.timedelta(weeks=1) SORT_BY = odict.odict([ ('Date', {'translation_id': m.DATE, 'sorter' : lambda x: x.starttimeAsTime() }), ('Title', {'translation_id': m.TITLE, 'sorter' : lambda x: '%s %s' % (x.title(), x.starttimeAsTime())}), ('Channel',{'translation_id': m.CHANNEL, 'sorter' : lambda x: Channel.sortableChannelNumber(x.getChannelNumber(), 0)})]) class UpcomingRecordingsWindow(BaseWindow): def __init__(self, *args, **kwargs): BaseWindow.__init__(self, *args, **kwargs) [setattr(self,k,v) for k,v in kwargs.iteritems() if k in ('settings','translator','platform','fanArt','cachesByName', 'upcoming', )] [setattr(self,k,v) for k,v in self.cachesByName.iteritems() if k in ('mythChannelIconCache','domainCache', )] self.programs = [] # [RecordedProgram] self.channelsById = None # {int:Channel} self.tunersById = None # {int:Tuner} self.listItemsByProgram = odict.odict() # {Program:ListItem} self.programsByListItemKey = odict.odict() # {ListItem:Program} self.sortBy = self.settings.get('upcoming_sort_by') self.sortAscending = self.settings.getBoolean('upcoming_sort_ascending')
def loadGuide(self): """ Method to load and display the tv guide information. If this is the first time being called, it initializes the tv guide parameters. """ log.debug('Loading tv guide..') if self.prevFocus: for c in self.gridCells: if c.control == self.prevFocus: self.prevButtonInfo = c self.prevFocus = None break if not self.initialized: self.channel_x = 60 self.channel_h = 40 self.channel_w = 340 - 120 + WIDTH_CHANNEL_ICON self.channel_dx = 5 self.time_y = 140 self.time_h = 40 self.guide_x = 310 self.guide_dx = 12 self.guide_dy = 1 self.guide_y = self.time_y + self.time_h + self.guide_dy self.guide_w = 1220 - 280 self.guide_h = 530 - 140 - self.time_h - self.guide_dy # calculate pixels per hour used repeatedly self.widthPerHour = self.guide_w / self.hoursPerPage # calculate channels per page based on guide height # self.channelsPerPage = int(self.guide_h / (self.guide_dy+self.channel_h) ) log.debug("channelSpan=%d" % self.channelsPerPage) # allocate the remainder to vertical spacing between channels # TODO: Fix gaps betweek rows: #remainder = self.guide_h // (self.guide_dy+self.channel_h) remainder = 0 log.debug('remainder = ' + str(remainder)) self.guide_dy += (remainder / self.channelsPerPage) # retrieve, consolidate, and sort channels self.channels = Channel.mergeChannels(self.domainCache.getChannels()) self.channels.sort(key=Channel.getSortableChannelNumber) self.pager = Pager(len(self.channels), self.channelsPerPage) self.setChannel(int(self.settings.get('tv_guide_last_selected'))) self.setTime(datetime.now() - timedelta(minutes=30)) self.initialized = True self._render() if not self.prevButtonInfo: # set focus to the first control on the screen if len(self.gridCells) > 0: self.prevFocus = self.gridCells[0].control self.setFocus(self.prevFocus) else: raise Exception, self.translator.get(m.NO_EPG_DATA)
def loadGuide(self, skipChannels=False): """ Method to load and display the tv guide information. If this is the first time being called, it initializes the tv guide parameters. """ log.debug('Loading tv guide..') if self.prevFocus: for c in self.gridCells: if c.control == self.prevFocus: self.prevButtonInfo = c self.prevFocus = None break if not self.initialized: self.channel_x = 60 self.channel_h = 40 self.channel_w = 340 - 120 + WIDTH_CHANNEL_ICON self.channel_dx = 5 self.time_y = 140 self.time_h = 40 self.guide_x = 310 self.guide_dx = 12 self.guide_dy = 1 self.guide_y = self.time_y + self.time_h + self.guide_dy self.guide_w = 1220 - 280 self.guide_h = 530 - 140 - self.time_h - self.guide_dy # calculate pixels per hour used repeatedly self.widthPerHour = self.guide_w / self.hoursPerPage # calculate channels per page based on guide height # self.channelsPerPage = int(self.guide_h / (self.guide_dy+self.channel_h) ) log.debug("channelSpan=%d" % self.channelsPerPage) # allocate the remainder to vertical spacing between channels # TODO: Fix gaps betweek rows: #remainder = self.guide_h // (self.guide_dy+self.channel_h) remainder = 0 log.debug('remainder = ' + str(remainder)) self.guide_dy += (remainder / self.channelsPerPage) # retrieve, consolidate, and sort channels self.channels = Channel.mergeChannels( self.domainCache.getChannels()) self.channels.sort(key=Channel.getSortableChannelNumber) self.pager = Pager(len(self.channels), self.channelsPerPage) self.setChannel(int(self.settings.get('tv_guide_last_selected'))) self.setTime(datetime.now() - timedelta(minutes=30)) self.initialized = True self._render(skipChannels) if not self.prevButtonInfo: # set focus to the first control on the screen if len(self.gridCells) > 0: self.prevFocus = self.gridCells[0].control self.setFocus(self.prevFocus) else: raise Exception, self.translator.get(m.NO_EPG_DATA)