Example #1
0
 def test_collect_button_statistics_not_exists_in_database_added_with_hitcount_1(
         self):
     program = "test_program"
     id = "test_button_id"
     button = Button(id, program, "", [], [])
     self.statistic_collector.collect_button_statistics(button)
     self.mock_button_stat_repository.find_button_stat_by_button.assert_called_with(
         button)
     self.mock_button_stat_repository.save.assert_called_with(
         ButtonStat(button, 1))
Example #2
0
 def test_collect_button_statistics_exists_added_with_inc_hitcount(self):
     program = "test_program"
     id = "test_button_id"
     button = Button(id, program, "", [], [])
     self.mock_button_stat_repository.find_button_stat_by_button = MagicMock(
         return_value=ButtonStat(button, 1))
     self.statistic_collector.collect_button_statistics(button)
     self.mock_button_stat_repository.find_button_stat_by_button.assert_called_with(
         button)
     self.mock_button_stat_repository.save.assert_called_with(
         ButtonStat(button, 2))
Example #3
0
 def test_collect_shortcut_statistics_exists_added_with_inc_hitcount(self):
     keycodes = "37,42"
     program = "test_program"
     shortcut = Shortcut(keycodes)
     id = "test_button_id"
     shortcut.button = Button(id, program, "", [], [])
     self.mock_shortcut_stat_repository.find_shortcut_stat_by_keycode_and_program = MagicMock(
         return_value=ShortcutStat(shortcut, 1))
     self.statistic_collector.collect_shortcut_statistics(shortcut)
     self.mock_shortcut_stat_repository.find_shortcut_stat_by_keycode_and_program.assert_called_with(
         keycodes, program)
     self.mock_shortcut_stat_repository.save.assert_called_with(
         ShortcutStat(shortcut, 2))
Example #4
0
    def test_collect_shortcut_statistics_not_exists_in_database_added_with_hitcount_1(
            self):
        keycodes = "37,42"
        program = "test_program"
        id = "test_button_id"
        shortcut = Shortcut(keycodes)
        shortcut.button = Button(id, program, "", [], [])

        self.statistic_collector.collect_shortcut_statistics(shortcut)
        self.mock_shortcut_stat_repository.find_shortcut_stat_by_keycode_and_program.assert_called_with(
            keycodes, program)
        self.mock_shortcut_stat_repository.save.assert_called_with(
            ShortcutStat(shortcut, 1))
Example #5
0
 def test_collect_button_effectiveness_statistic_one_shortcut(self):
     program = "test_program"
     keycodes = "37,42"
     id = "test_button_id"
     shortcut = Shortcut(keycodes)
     button = Button(id, program, "", [], [shortcut])
     shortcut.button = button
     self.mock_button_stat_repository.find_button_stat_by_button = MagicMock(
         return_value=ButtonStat(button, 7))
     self.mock_shortcut_stat_repository.find_shortcut_stat_by_keycode_and_program = MagicMock(
         return_value=ShortcutStat(shortcut, 3))
     effectiveness = self.statistic_collector.calculate_button_effectiveness_statistic(
         button)
     self.assertEqual(effectiveness, 30.0)
Example #6
0
 def test_first_template_not_matching(self):
     button_template = Template(
         numpy.empty(self.array_shape, dtype=numpy.uint8).tobytes(), 24,
         324)
     button_templates = [button_template, button_template]
     button = Button("test_button_id", "test_program", "test_button_name",
                     button_templates, [])
     buttons = [button]
     self.mock_button_reposotory.find_buttons_by_program = MagicMock(
         return_value=buttons)
     self.mock_template_matcher.get_template_location = MagicMock(
         side_effect=[None, self.mock_template_location])
     found_button = self.button_matcher.find_button_on_clicked_position(
         Click(40, 50), None, None)
     self.assertEqual(button, found_button)
Example #7
0
 def setUp(self):
     self.mock_button_reposotory = AbstractButtonRepository(None)
     self.directory = os.path.dirname(os.path.abspath(__file__))
     self.array_shape = (24, 324)
     button_template = numpy.empty(self.array_shape, dtype=numpy.uint8)
     button_templates = [Template(button_template.tobytes(), 24, 324)]
     self.button = Button("test_button_id", "test_program",
                          "test_button_name", button_templates, [])
     buttons = [self.button]
     self.mock_button_reposotory.find_all_buttons = MagicMock(
         return_value=buttons)
     self.mock_button_reposotory.find_buttons_by_program = MagicMock(
         return_value=buttons)
     self.mock_template_matcher = AbstractTemplateMatcher()
     self.mock_template_location = (40, 50)
     self.mock_template_matcher.get_template_location = MagicMock(
         return_value=self.mock_template_location)
     self.button_matcher = ButtonMatcher(self.mock_template_matcher,
                                         self.mock_button_reposotory)
Example #8
0
 def test_collect_button_effectiveness_statistic_many_shortcuts(self):
     program = "test_program"
     keycodes1 = "37,42"
     keycodes2 = "37,45"
     id = "test_button_id"
     shortcut1 = Shortcut(keycodes1)
     shortcut2 = Shortcut(keycodes2)
     button = Button(id, program, "", [], [shortcut1, shortcut2])
     shortcut1.button = button
     shortcut2.button = button
     self.mock_button_stat_repository.find_button_stat_by_button = MagicMock(
         return_value=ButtonStat(button, 5))
     self.mock_shortcut_stat_repository.find_shortcut_stat_by_keycode_and_program = MagicMock(
         side_effect=[
             ShortcutStat(shortcut1, 3),
             ShortcutStat(shortcut2, 2)
         ])
     effectiveness = self.statistic_collector.calculate_button_effectiveness_statistic(
         button)
     self.assertEqual(effectiveness, 50.0)