def _get_score(self, filename, criteria_str): packets = parse_tests_data(filename) validator = DiscardInitialSecondsValidator( validator=CountTrackingIDValidator(criteria_str, device=link), device=link) vlog = validator.check(packets) return vlog.score
def _get_number_errors(self, filename): packets = parse_tests_data(filename) validator = MtbSanityValidator(device=link, device_info=self.fake_device_info) vlog = validator.check(packets) number_errors, _ = vlog.metrics[1].value return number_errors
def test_discard_initial_seconds(self): """Test that discard_initial_seconds() cuts at the proper packet. Note: to print the final_state_packet, use the following statements: import mtb print mtb.make_pretty_packet(final_state_packet) """ packets = parse_tests_data('noise_stationary_extended.dat') validator = DiscardInitialSecondsValidator( validator=CountTrackingIDValidator('== 1', device=link), device=link) validator.init_check(packets) packets = validator._discard_initial_seconds(packets, 1) final_state_packet = packets[0] self.assertTrue(len(final_state_packet) == 11) # Assert the correctness of the 1st finger data in the order of # SLOT, TRACKING_ID, POSITION_X, POSITION_Y, PRESSURE self.assertTrue(final_state_packet[0][MTB.EV_VALUE] == 2) self.assertTrue(final_state_packet[1][MTB.EV_VALUE] == 2427) self.assertTrue(final_state_packet[2][MTB.EV_VALUE] == 670) self.assertTrue(final_state_packet[3][MTB.EV_VALUE] == 361) self.assertTrue(final_state_packet[4][MTB.EV_VALUE] == 26) # Assert the correctness of the 2nd finger data in the order of # SLOT, TRACKING_ID, POSITION_X, POSITION_Y, PRESSURE self.assertTrue(final_state_packet[5][MTB.EV_VALUE] == 3) self.assertTrue(final_state_packet[6][MTB.EV_VALUE] == 2426) self.assertTrue(final_state_packet[7][MTB.EV_VALUE] == 670) self.assertTrue(final_state_packet[8][MTB.EV_VALUE] == 368) self.assertTrue(final_state_packet[9][MTB.EV_VALUE] == 21) # EVENT TIME self.assertTrue( final_state_packet[0][MTB.EV_TIME] == 1412021965.723953)
def _get_score(self, filename, device): validator = ReportRateValidator(self.criteria, device=device, chop_off_pauses=False) packets = parse_tests_data(filename) vlog = validator.check(packets) score = vlog.score return score
def test_click_data(self): """Test that the validator handles None distances well. In this test, distance1 = None and distance2 = None. This results in ratio = infinity. There should be no error incurred. """ packets = parse_tests_data('2f_clicks_test_hysteresis.dat') validator = HysteresisValidator(self.criteria, device=link) vlog = validator.check(packets) self.assertEqual(vlog.metrics[0].value, float('infinity'))
def _get_score(self, filename, device): validator = NoLevelJumpValidator(self.criteria, device=device, slots=[ 0, ]) packets = parse_tests_data(filename, gesture_dir=self.gesture_dir) vlog = validator.check(packets) score = vlog.score return score
def _test_physical_clicks(self, gesture_dir, files, expected_score): gesture_path = os.path.join(unittest_path_lumpy, gesture_dir) for filename, fingers in files.items(): packets = parse_tests_data(os.path.join(gesture_path, filename)) validator = PhysicalClickValidator(self.criteria, fingers=fingers, device=self.device) vlog = validator.check(packets) actual_score = vlog.score self.assertTrue(actual_score == expected_score)
def test_stationary_tap(self): filenames = { '1f_click.dat': 1.718284027744, '1f_clickb.dat': 0.577590781705 } for filename, expected_max_distance in filenames.items(): packets = parse_tests_data(filename) validator = StationaryTapValidator(self.criteria, device=lumpy) vlog = validator.check(packets) actual_max_distance = vlog.metrics[0].value self.assertAlmostEqual(actual_max_distance, expected_max_distance)
def test_noise_line_with_all_fingers_left(self): """In this test case, all fingers left. The final_state_packet is [].""" packets = parse_tests_data('noise_line.dat') validator = DiscardInitialSecondsValidator( ReportRateValidator('>= 60')) validator.init_check(packets) packets = validator._discard_initial_seconds(packets, 1) validator.validator.init_check(packets) list_syn_time = validator.validator.packets.get_list_syn_time([]) self.assertEqual(len(packets), 84) self.assertEqual(len(list_syn_time), 84)
def test_hysteresis(self): """Test that the hysteresis causes an initial jump.""" filenames = { 'center_to_right_normal_link.dat': 4.6043458, 'center_to_right_slow_link.dat': 16.8671278 } for filename, expected_value in filenames.items(): packets = parse_tests_data(filename) validator = HysteresisValidator(self.criteria, device=link) vlog = validator.check(packets) self.assertAlmostEqual(vlog.metrics[0].value, expected_value)
def test_report_rate_without_slot(self): """Test report rate without specifying any slot.""" filename_report_rate_pair = [ ('2f_scroll_diagonal.dat', 40.31), ('one_finger_with_slot_0.dat', 148.65), ('two_close_fingers_merging_changed_ids_gaps.dat', 53.12), ] for filename, expected_report_rate in filename_report_rate_pair: validator = ReportRateValidator(self.criteria, device=dontcare, chop_off_pauses=False) validator.check(parse_tests_data(filename)) actual_report_rate = round(validator.report_rate, 2) self.assertAlmostEqual(actual_report_rate, expected_report_rate)
def test_report_rate_with_slot(self): """Test report rate with slot=1""" # Compute actual_report_rate filename = ('stationary_finger_strongly_affected_by_2nd_moving_finger_' 'with_gaps.dat') validator = ReportRateValidator(self.criteria, device=dontcare, finger=1, chop_off_pauses=False) validator.check(parse_tests_data(filename)) actual_report_rate = validator.report_rate # Compute expected_report_rate first_syn_time = 2597.682925 last_syn_time = 2604.543335 num_packets = 592 - 1 expected_report_rate = num_packets / (last_syn_time - first_syn_time) self.assertAlmostEqual(actual_report_rate, expected_report_rate)
def _test_report_rate_metrics(self, filename, expected_values): packets = parse_tests_data(filename) validator = ReportRateValidator(self.criteria, device=lumpy, chop_off_pauses=False) vlog = validator.check(packets) # Verify that there are 3 metrics number_metrics = 3 self.assertEqual(len(vlog.metrics), number_metrics) # Verify the values of the 3 metrics. for i in range(number_metrics): actual_value = vlog.metrics[i].value if isinstance(actual_value, tuple): self.assertEqual(actual_value, expected_values[i]) else: self.assertAlmostEqual(actual_value, expected_values[i])
def test_log_details_and_metrics(self): """Test the axes in _log_details_and_metrics""" # gesture_dir: tests/data/linearity gesture_dir = 'linearity' filenames_axes = { 'two_finger_tracking.right_to_left.slow-lumpy-fw_11.27-robot-' '20130227_204458.dat': [AXIS.X], 'one_finger_to_edge.center_to_top.slow-lumpy-fw_11.27-robot-' '20130227_203228.dat': [AXIS.Y], 'two_finger_tracking.bottom_left_to_top_right.normal-lumpy-' 'fw_11.27-robot-20130227_204902.dat': [AXIS.X, AXIS.Y], } for filename, expected_axes in filenames_axes.items(): packets = parse_tests_data(filename, gesture_dir=gesture_dir) # get the direction of the gesture direction = [filename.split('-')[0].split('.')[1]] self.validator.check(packets, direction) actual_axes = sorted(self.validator.list_coords.keys()) self.assertEqual(actual_axes, expected_axes)
def test_get_snapshot_after_discarding_init_packets(self): """Test that get_snapshot() handles non-ready packet properly after discard_initial_seconds(). A non-ready packet is one that the attributes such as X, Y, and Z are not all ready. """ packets = parse_tests_data( 'non_ready_events_in_final_state_packet.dat') validator = DiscardInitialSecondsValidator( validator=CountTrackingIDValidator('== 1', device=link), device=link) validator.init_check(packets) packets = validator._discard_initial_seconds(packets, 1) final_state_packet = packets[0] self.assertTrue(len(final_state_packet) == 4) # Assert the correctness of the finger data in the order of # SLOT, TRACKING_ID, and POSITION_Y self.assertTrue(final_state_packet[0][MTB.EV_VALUE] == 0) self.assertTrue(final_state_packet[1][MTB.EV_VALUE] == 102) self.assertTrue(final_state_packet[2][MTB.EV_VALUE] == 1316) # EVENT TIME self.assertTrue( final_state_packet[0][MTB.EV_TIME] == 1412888977.716634)
def _test_range(self, filename, expected_short_of_range_px): filepath = os.path.join(unittest_path_lumpy, filename) packets = parse_tests_data(filepath) validator = RangeValidator(conf.range_criteria, device=self.device) # Extract the gesture variation from the filename variation = (filename.split('/')[-1].split('.')[1], ) # Determine the axis based on the direction in the gesture variation axis = ( self.device.axis_x if validator.is_horizontal(variation) else self.device.axis_y if validator.is_vertical(variation) else None) self.assertTrue(axis is not None) # Convert from pixels to mms. expected_short_of_range_mm = self.device.pixel_to_mm_single_axis( expected_short_of_range_px, axis) vlog = validator.check(packets, variation) # There is only one metric in the metrics list. self.assertEqual(len(vlog.metrics), 1) actual_short_of_range_mm = vlog.metrics[0].value self.assertEqual(actual_short_of_range_mm, expected_short_of_range_mm)
def _get_drumroll_metrics(self, filename, criteria, device): packets = parse_tests_data(filename, gesture_dir=unittest_path_lumpy) validator = DrumrollValidator(criteria, device=device) metrics = validator.check(packets).metrics return metrics
def _test_drumroll(self, filename, criteria, device): packets = parse_tests_data(filename) validator = DrumrollValidator(criteria, device=device) vlog = validator.check(packets) return vlog.score
def test_physical_clicks_by_finger_IDs(self): """Test that some physical clicks may come with or without correct finger IDs. """ # files is a dictionary of { # filename: (number_fingers, (actual clicks, expected clicks))} files = { # An incorrect case with 1 finger: the event sequence comprises # Event: ABS_MT_TRACKING_ID, value 284 # Event: ABS_MT_TRACKING_ID, value -1 # Event: BTN_LEFT, value 1 # Event: BTN_LEFT, value 0 # In this case, the BTN_LEFT occurs when there is no finger. '1f_click_incorrect_behind_tid.dat': (1, (0, 1)), # A correct case with 1 finger: the event sequence comprises # Event: ABS_MT_TRACKING_ID, value 284 # Event: BTN_LEFT, value 1 # Event: ABS_MT_TRACKING_ID, value -1 # Event: BTN_LEFT, value 0 # In this case, the BTN_LEFT occurs when there is no finger. '1f_click.dat': (1, (1, 1)), # An incorrect case with 2 fingers: the event sequence comprises # Event: ABS_MT_TRACKING_ID, value 18 # Event: BTN_LEFT, value 1 # Event: BTN_LEFT, value 0 # Event: ABS_MT_TRACKING_ID, value 19 # Event: ABS_MT_TRACKING_ID, value -1 # Event: ABS_MT_TRACKING_ID, value -1 # In this case, the BTN_LEFT occurs when there is only 1 finger. '2f_clicks_incorrect_before_2nd_tid.dat': (2, (0, 1)), # An incorrect case with 2 fingers: the event sequence comprises # Event: ABS_MT_TRACKING_ID, value 18 # Event: ABS_MT_TRACKING_ID, value 19 # Event: ABS_MT_TRACKING_ID, value -1 # Event: ABS_MT_TRACKING_ID, value -1 # Event: BTN_LEFT, value 1 # Event: BTN_LEFT, value 0 # In this case, the BTN_LEFT occurs when there is only 1 finger. '2f_clicks_incorrect_behind_2_tids.dat': (2, (0, 1)), # A correct case with 2 fingers: the event sequence comprises # Event: ABS_MT_TRACKING_ID, value 18 # Event: ABS_MT_TRACKING_ID, value 19 # Event: BTN_LEFT, value 1 # Event: ABS_MT_TRACKING_ID, value -1 # Event: ABS_MT_TRACKING_ID, value -1 # Event: BTN_LEFT, value 0 # In this case, the BTN_LEFT occurs when there is only 1 finger. '2f_clicks.dat': (2, (1, 1)), } for filename, (fingers, expected_value) in files.items(): packets = parse_tests_data(filename) validator = PhysicalClickValidator(self.criteria, fingers=fingers, device=dontcare) vlog = validator.check(packets) metric_name = self.mnprops.CLICK_CHECK_TIDS.format(fingers) for metric in vlog.metrics: if metric.name == metric_name: self.assertEqual(metric.value, expected_value)
def _get_max_distance(self, filename, criteria, device): packets = parse_tests_data(filename) validator = StationaryFingerValidator(criteria, device=device) vlog = validator.check(packets) return vlog.metrics[0].value
def _test_count_tracking_id(self, filename, criteria, device): packets = parse_tests_data(filename) validator = CountTrackingIDValidator(criteria, device=device) vlog = validator.check(packets) return vlog.score
def _test_no_gap(self, filename, criteria, device, slot): file_subpath = os.path.join(self.GAPS_SUBDIR, filename) packets = parse_tests_data(file_subpath) validator = NoGapValidator(criteria, device=device, slot=slot) vlog = validator.check(packets) return vlog.score