def test_addEvent_None(self):
        kp = KeyPlayer("")
        kp._addEvent(None)
        dq = deque()
        dq.append(None)

        self.assertEqual(dq,kp.eventQueue)
    def test_loadEventList(self):
        lst = []
        lst.append("a")
        lst.append("b")
        lst.append("c")
        kp = KeyPlayer("")
        kp.loadEventList(lst)

        self.assertEqual(len(kp.eventQueue), 3)
        self.assertEqual(kp.eventQueue.pop(), "c")
        self.assertEqual(kp.eventQueue.pop(), "b")
        self.assertEqual(kp.eventQueue.pop(), "a")
    def play(self, keyList, clickList):
        kp = KeyPlayer()
        kp.loadEventList(keyList)

        cp = ClickPlayer()
        cp.loadEventList(clickList)

        try:
            t1 = threading.Thread(target=kp.play)
            t2 = threading.Thread(target=cp.play)
            t1.start()
            t2.start()

            t1.join()
            t2.join()
        #    print "starting thread!"
        #kp.play()
            #thread.start_new_thread( kp.play, ())
        except:
            print "Error: unable to start KeyPlayer thread."
 def _launchKeyPlayer(self):
     filename = self._promptForFile()
     keyPlayer = KeyPlayer(filename)
     keyPlayer.play()
 def test_unpackEvent_invalid_values_map(self):
     kp = KeyPlayer("")
     with self.assertRaises(KeyError) as cm:
         event = {'time': 1, 'key': 'a'}
         kp._unpackEvent(event)
 def test_unpackEvent_valid_values_map(self):
     kp = KeyPlayer("")
     event = {'time': 1, 'key': 'a', 'eventType': 'up'}
     self.assertEqual((1,'a','up'),kp._unpackEvent(event))
 def test_unpackEvent_None_map(self):
     kp = KeyPlayer("")
     event = {}
     self.assertEqual(None,kp._unpackEvent(event))
 def test_unpackEvent_valid_values_list(self):
     kp = KeyPlayer("")
     self.assertEqual((1,'a','up'),kp._unpackEvent([1.0,'a','up']))
     self.assertEqual((1.0,'a','down'),kp._unpackEvent([1.0,'a','down']))
    def test_unpackEvent_invalid_values_list(self):
        kp = KeyPlayer("")
        with self.assertRaises(IndexError) as cm:
            kp._unpackEvent(["time"])
        self.assertEqual('list index out of range',str(cm.exception))

        with self.assertRaises(IndexError) as cm:
            kp._unpackEvent(["time","key"])
        self.assertEqual('list index out of range',str(cm.exception))

        with self.assertRaises(AssertionError) as cm:
            kp._unpackEvent(["time","key","event"])
        self.assertEqual('time is non-numeric, \'time\'',str(cm.exception))

        with self.assertRaises(AssertionError) as cm:
            kp._unpackEvent([1.0,2,"event"])
        self.assertEqual('key is not a string, 2',str(cm.exception))

        with self.assertRaises(AssertionError) as cm:
            kp._unpackEvent([1.0,'a',3])
        self.assertEqual('eventType is not a string, 3',str(cm.exception))
 def test_unpackEvent_None_list(self):
     kp = KeyPlayer("")
     event = []
     self.assertEqual(None,kp._unpackEvent(event))
 def test_unpackEvent_None(self):
     kp = KeyPlayer("")
     self.assertEqual(None,kp._unpackEvent(None))