def setUp(self):
     print "Setup processor"
     self.gapDuration = 1
     blocking = False
     # button - PLUS
     # all types of usage should results in this same task
     plusAction = Action("plus-id", "plus-task", isCancelable = False)
     self.plusButton = Button("PLUS-BUTTON", plusAction, plusAction, plusAction)        
     # button - FORWARD
     # when clicked once then next song should be played, when double-clicked then next album should be played 
     # and when hold then next play-list should be played 
     nextSongAction = Action("next-song-id", "next-song-task", fireDelay = (self.gapDuration * self.actionDelayFactor))
     nextAlbumAction = Action("next-album-id", "next-album-task", fireDelay = (self.gapDuration * self.actionDelayFactor))
     nextPlaylistAction = Action("next-playlist-id", "next-playlist-task", minimalRepeatTrigger = 1)
     self.forwardButton = Button("FORWARD-BUTTON", nextSongAction, nextAlbumAction, nextPlaylistAction)      
     # button - MENU
     # when clicked once then general mode menu task should be executed, when hold current mode menu task should be executed
     globalModeAction = Action("global-menu-id", "global-menu-task", fireDelay = (self.gapDuration * self.actionDelayFactor))
     currentMenuAction = Action ("current-menu-id", "current-menu-task", minimalRepeatTrigger = 1)
     self.menuButton = Button("MENU-BUTTON", globalModeAction, globalModeAction, currentMenuAction)
     # button - PLAY
     # when clicked once then play/pause task should be executed, when hold for at least 5 rounds power off task should be executed
     playPauseAction = Action("play-pause-id", "play-pause-task", fireDelay = (self.gapDuration * self.actionDelayFactor))
     powerOffAction = Action("power-off-id", "power-off-task", minimalRepeatTrigger = 5)
     self.playButton = Button("PLAY-BUTTON", playPauseAction , playPauseAction, powerOffAction)
     # configuration
     buttons = {}
     buttons[self.plusButton.id] = self.plusButton
     buttons[self.forwardButton.id] = self.forwardButton
     buttons[self.menuButton.id] = self.menuButton
     buttons[self.playButton.id] = self.playButton  
     self.processorQueue = Queue()
     self.actualWorkerQueue = Queue()
     self.expectedWorkerQueue = Queue()
     # processor        
     self.processor = Processor(buttons, self.processorQueue, self.actualWorkerQueue)
class ProcessorTest(unittest.TestCase):
    
    __test__ = True
    
    actionDelayFactor = 1.1
    testDelayFactor = 1.2    
    
    def setUp(self):
        print "Setup processor"
        self.gapDuration = 1
        blocking = False
        # button - PLUS
        # all types of usage should results in this same task
        plusAction = Action("plus-id", "plus-task", isCancelable = False)
        self.plusButton = Button("PLUS-BUTTON", plusAction, plusAction, plusAction)        
        # button - FORWARD
        # when clicked once then next song should be played, when double-clicked then next album should be played 
        # and when hold then next play-list should be played 
        nextSongAction = Action("next-song-id", "next-song-task", fireDelay = (self.gapDuration * self.actionDelayFactor))
        nextAlbumAction = Action("next-album-id", "next-album-task", fireDelay = (self.gapDuration * self.actionDelayFactor))
        nextPlaylistAction = Action("next-playlist-id", "next-playlist-task", minimalRepeatTrigger = 1)
        self.forwardButton = Button("FORWARD-BUTTON", nextSongAction, nextAlbumAction, nextPlaylistAction)      
        # button - MENU
        # when clicked once then general mode menu task should be executed, when hold current mode menu task should be executed
        globalModeAction = Action("global-menu-id", "global-menu-task", fireDelay = (self.gapDuration * self.actionDelayFactor))
        currentMenuAction = Action ("current-menu-id", "current-menu-task", minimalRepeatTrigger = 1)
        self.menuButton = Button("MENU-BUTTON", globalModeAction, globalModeAction, currentMenuAction)
        # button - PLAY
        # when clicked once then play/pause task should be executed, when hold for at least 5 rounds power off task should be executed
        playPauseAction = Action("play-pause-id", "play-pause-task", fireDelay = (self.gapDuration * self.actionDelayFactor))
        powerOffAction = Action("power-off-id", "power-off-task", minimalRepeatTrigger = 5)
        self.playButton = Button("PLAY-BUTTON", playPauseAction , playPauseAction, powerOffAction)
        # configuration
        buttons = {}
        buttons[self.plusButton.id] = self.plusButton
        buttons[self.forwardButton.id] = self.forwardButton
        buttons[self.menuButton.id] = self.menuButton
        buttons[self.playButton.id] = self.playButton  
        self.processorQueue = Queue()
        self.actualWorkerQueue = Queue()
        self.expectedWorkerQueue = Queue()
        # processor        
        self.processor = Processor(buttons, self.processorQueue, self.actualWorkerQueue)

    def validateQueuesEqual(self,queue1, queue2):
        list1 = []
        list2 = []
        element = queue1.get()
        while element is not None:
            list1.append(element)
            element = queue1.get()
        element = queue2.get()    
        while element is not None:
            list2.append(element)
            element = queue2.get()
        self.assertEqual(list1, list2)
    
    def tearDown(self):
        self.processor= None
        self.configuration = None

    def clickButton(self, button, repeat):
        ''' Simulates button click on the remote '''
        self.processorQueue(button.id, repeat)
        print "Sleeping for %s before finishing current click ..." % (self.gapDuration)
        time.sleep(self.gapDuration)
        print "Done"
    
    def sleepBeforeTest(self):
        time.sleep(self.gapDuration * self.testDelayFactor)
                
    def testPlusButtonClick(self):        
        self.processorQueue.put(Event(self.plusButton.id, 0))
        self.processorQueue.put(None)        
        self.expectedWorkerQueue.put(self.plusButton.click.task)
        self.sleepBeforeTest()
        self.processor.process()
        
        TODO: fix all these tests starting from his one !!!