Exemplo n.º 1
0
 def test_run(self):        
     ar = Arduino()        
     ar.stop = False
     ar.no_serial = False
     cb = MagicMock()
     ar.ser = MagicMock()
     
     def fake_readline(val):
         return b"l"
     ar.ser.readline = fake_readline
     ar.subscribers = [cb]
     ar.start()
     ar.stop = True
     ar.join()
     cb.assert_called_with("l")
Exemplo n.º 2
0
 def test_send_value(self):
     ar = Arduino()
     ar.ser = MagicMock()
     
     
     
     ar.no_serial = True
     
     ar.previously_sent = None
     ar.send_value("1")        
     self.assertFalse(ar.ser.write.called)
     
     
     ar.no_serial = False
             
     ar.previously_sent = None
     ar.send_value("1")    
     ar.ser.write.assert_called_with(bytes("1", "UTF-8"))
     self.assertEqual(ar.previously_sent, "1")
     ar.ser.write.reset_mock()
     
     ar.previously_sent = "1"
     ar.send_value("1")    
     self.assertFalse(ar.ser.write.called)