def test_set_text(self): """Test set_text method.""" mock_text = "abcd" self.display.text = mock_text clear_message = parse_message(0x04, 21, -1, (0, 0)) text_message = parse_message(0x04, 17, -1, parse_data(mock_text + '\0', 'string')) self.assertEqual(self.conn.send_list[0], clear_message) self.assertEqual(self.conn.send_list[1], text_message)
def test_set_text(self): """Test set_text method.""" mock_text = "abcd" self.display.text = mock_text clear_message = parse_message(0x04, 21, -1, (0, 0)) text_message = parse_message(0x04, 17, -1, parse_data(mock_text, 'string')) self.assertEqual(self.send_q.get(), clear_message) self.assertEqual(self.send_q.get(), text_message)
def request_topology(self, module_id: int = BROADCAST_ID) -> None: """Request module topology :return: json serialized topology request message :rtype: str """ self._conn.send_nowait( parse_message(0x07, 0, module_id, (0, 0, 0, 0, 0, 0, 0, 0))) self._conn.send_nowait( parse_message(0x2A, 0, module_id, (0, 0, 0, 0, 0, 0, 0, 0)))
def test_get_torque(self): """Test set_torque method with none input.""" _ = self.motor.torque sent_messages = [] while self.conn.send_list: sent_messages.append(self.conn.send_list.pop()) self.assertTrue( parse_message(0x03, 0, -1, (Motor.FIRST_TORQUE, None, 95, None)) in sent_messages) self.assertTrue( parse_message(0x03, 0, -1, (Motor.SECOND_TORQUE, None, 95, None)) in sent_messages)
def test_get_tune(self): """Test get_tune method with none input.""" _ = self.speaker.tune sent_messages = [] while self.conn.send_list: sent_messages.append(self.conn.send_list.pop()) self.assertTrue( parse_message(0x03, 0, -1, (Speaker.FREQUENCY, None, 95, None)) in sent_messages) self.assertTrue( parse_message(0x03, 0, -1, (Speaker.VOLUME, None, 95, None)) in sent_messages)
def test_get_speed(self): """Test get_speed method with none input.""" _ = self.motor.speed sent_messages = [] while self.conn.send_list: sent_messages.append(self.conn.send_list.pop()) self.assertTrue( parse_message(0x03, 0, -1, (Motor.FIRST_SPEED, None, 95, None)) in sent_messages) self.assertTrue( parse_message(0x03, 0, -1, (Motor.SECOND_SPEED, None, 95, None)) in sent_messages)
def test_set_second_torque(self): """Test set_second_torque method.""" second_torque_value = 50 self.motor.second_torque = second_torque_value sent_messages = [] while self.conn.send_list: sent_messages.append(self.conn.send_list.pop()) self.assertTrue( parse_message(0x03, 0, -1, (Motor.SECOND_TORQUE, None, 95, None)) in sent_messages) self.assertTrue( parse_message( 0x04, 16, -1, parse_data(( 0, second_torque_value), 'int')) in sent_messages)
def test_set_first_torque(self): """Test set_first_torque method.""" first_torque_value = 50 self.motor.first_torque = first_torque_value sent_messages = [] while self.conn.send_list: sent_messages.append(self.conn.send_list.pop()) self.assertTrue( parse_message(0x03, 0, -1, (Motor.FIRST_TORQUE, None, 95, None)) in sent_messages) self.assertTrue( parse_message(0x04, 16, -1, parse_data((first_torque_value, 0), 'int')) in sent_messages)
def test_get_degree(self): """Test get_degree method with none input.""" _ = self.motor.degree sent_messages = [] while self.conn.send_list: sent_messages.append(self.conn.send_list.pop()) self.assertTrue( parse_message(0x03, 0, -1, (Motor.FIRST_DEGREE, None, self.motor.prop_samp_freq, None)) in sent_messages) self.assertTrue( parse_message(0x03, 0, -1, (Motor.SECOND_DEGREE, None, self.motor.prop_samp_freq, None)) in sent_messages)
def test_set_first_degree(self): """Test set_first_degree method.""" first_degree_value = 50 self.motor.first_degree = first_degree_value sent_messages = [] while self.conn.send_list: sent_messages.append(self.conn.send_list.pop()) self.assertTrue( parse_message(0x03, 0, -1, (Motor.FIRST_DEGREE, None, 95, None)) in sent_messages) self.assertTrue( parse_message( 0x04, 19, -1, parse_data(( 0, 2, first_degree_value), 'int')) in sent_messages)
def test_set_second_speed(self): """Test set_second_speed method.""" second_speed_value = 50 self.motor.second_speed = second_speed_value sent_messages = [] while self.conn.send_list: sent_messages.append(self.conn.send_list.pop()) self.assertTrue( parse_message(0x03, 0, -1, (Motor.SECOND_SPEED, None, 95, None)) in sent_messages) self.assertTrue( parse_message( 0x04, 19, -1, parse_data(( 1, 1, second_speed_value), 'int')) in sent_messages)
def test_set_second_degree(self): """Test set_second_degree method.""" second_degree_value = 50 self.motor.second_degree = second_degree_value sent_messages = [] while self.conn.send_list: sent_messages.append(self.conn.send_list.pop()) self.assertTrue( parse_message(0x03, 0, -1, (Motor.SECOND_DEGREE, None, self.motor.prop_samp_freq, None)) in sent_messages) self.assertTrue( parse_message( 0x04, 19, -1, parse_data(( 1, 2, second_degree_value), 'int')) in sent_messages)
def test_set_first_speed(self): """Test set_first_speed method.""" first_speed_value = 50 self.motor.first_speed = first_speed_value sent_messages = [] while self.conn.send_list: sent_messages.append(self.conn.send_list.pop()) self.assertTrue( parse_message(0x03, 0, -1, (Motor.FIRST_SPEED, None, self.motor.prop_samp_freq, None)) in sent_messages) self.assertTrue( parse_message( 0x04, 19, -1, parse_data(( 0, 1, first_speed_value), 'int')) in sent_messages)
def test_send(self): """Test _send_data method""" json_pkt = parse_message(0x03, 0, 1) self.can_task.send(json_pkt) self.assertEqual(self.can_task.bus.recv_buffer.get().data, CanTask.compose_can_msg(json.loads(json_pkt)).data )
def test_get_distance(self): """Test get_distance method.""" _ = self.ultrasonic.distance self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Ultrasonic.DISTANCE, None, self.ultrasonic.prop_samp_freq, None)))
def test_get_blue(self): """Test get_blue method.""" _ = self.env.blue self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Env.BLUE, None, self.env.prop_samp_freq, None)))
def test_get_green(self): """Test set_green method with none input.""" _ = self.led.green self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Led.GREEN, None, self.led.prop_samp_freq, None)))
def test_get_volume(self): """Test get_volume method.""" _ = self.mic.volume self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Mic.VOLUME, None, self.mic.prop_samp_freq, None)))
def test_get_humidity(self): """Test get_humidity method.""" _ = self.env.humidity self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Env.HUMIDITY, None, self.env.prop_samp_freq, None)))
def test_get_red(self): """Test get_red method.""" _ = self.env.red self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Env.RED, None, self.env.prop_samp_freq, None)))
def test_get_blue(self): """Test get blue method with none input.""" _ = self.led.blue self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Led.BLUE, None, self.led.prop_samp_freq, None)))
def test_get_proximity(self): """Test get_proximity method.""" _ = self.ir.proximity self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Ir.PROXIMITY, None, self.ir.prop_samp_freq, None)))
def test_get_red(self): """Test get_red method with none input.""" _ = self.led.red self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Led.RED, None, self.led.prop_samp_freq, None)))
def test_get_double_clicked(self): """Test get_double_clicked method.""" _ = self.button.double_clicked self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Button.DOUBLE_CLICKED, None, 95, None)))
def test_get_degree(self): """Test get_degree method.""" _ = self.dial.degree self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Dial.DEGREE, None, self.dial.prop_samp_freq, None)))
def test_get_green(self): """Test get_green method.""" _ = self.env.green self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Env.GREEN, None, self.env.prop_samp_freq, None)))
def test_set_tune(self): """Test set_tune method.""" expected_values = frequency, volume = (500, 30) self.speaker.tune = expected_values sent_messages = [] while self.conn.send_list: sent_messages.append(self.conn.send_list.pop()) self.assertTrue( parse_message(0x03, 0, -1, (Speaker.FREQUENCY, None, 95, None)) in sent_messages) self.assertTrue( parse_message(0x03, 0, -1, (Speaker.VOLUME, None, 95, None)) in sent_messages) self.assertTrue( parse_message(0x04, 16, -1, parse_data(expected_values, 'float')) in sent_messages)
def test_get_angular_vel_z(self): """Test get_angular_vel_z method.""" _ = self.gyro.angular_vel_z self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Gyro.ANGULAR_VEL_Z, None, 95, None)) )
def test_get_acceleration_z(self): """Test get_acceleration_z method.""" _ = self.gyro.acceleration_z self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Gyro.ACCELERATION_Z, None, 95, None)) )
def test_get_yaw(self): """Test get_yaw method.""" _ = self.gyro.yaw self.assertEqual( self.conn.send_list[0], parse_message(0x03, 0, -1, (Gyro.YAW, None, 95, None)) )