Example #1
0
 def test_merge_shortcuts(self):
     shortcut = Shortcut("32,28")
     existing_shortcut = Shortcut("32,28")
     existing_shortcut.id = 2
     merged_shortcut = merge_shortcuts(shortcut, existing_shortcut)
     self.assertEqual(merged_shortcut.id, 2)
     self.assertEqual(merged_shortcut.keycodes, "32,28")
Example #2
0
    def test_merge_buttons(self):
        program = "test_program"
        old_name = "test_old"
        new_name = "test_button"
        button_id = "test_button_id"
        shortcuts = [Shortcut("32,28"), Shortcut("32,30"), Shortcut("32,29")]
        existing_shortcut1 = Shortcut("32,28")
        existing_shortcut1.id = 1
        existing_shortcut2 = Shortcut("32,29")
        existing_shortcut2.id = 2
        existing_shortcuts = [existing_shortcut1, existing_shortcut2]
        template = Template("121", 100, 100)
        button = Button(button_id, program, new_name, [template], shortcuts)
        existing_button = Button(button_id, program, old_name, [],
                                 existing_shortcuts)
        merged_button = merge_buttons(button, existing_button)
        self.assertEqual(len(merged_button.shortcuts), 3)
        self.assertEqual(len(merged_button.templates), 1)
        self.assertEqual(merged_button.templates[0], template)
        self.assertEqual(merged_button.name, new_name)

        self.assertEqual(merged_button.shortcuts[0].id, 1)
        self.assertEqual(merged_button.shortcuts[0].keycodes, "32,28")
        self.assertEqual(merged_button.shortcuts[1].id, None)
        self.assertEqual(merged_button.shortcuts[1].keycodes, "32,30")
        self.assertEqual(merged_button.shortcuts[2].id, 2)
        self.assertEqual(merged_button.shortcuts[2].keycodes, "32,29")
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_merge_shortcuts_with_existing(self):
     shortcuts = [Shortcut("32,28"), Shortcut("32,30"), Shortcut("32,29")]
     existing_shortcut1 = Shortcut("32,28")
     existing_shortcut1.id = 1
     existing_shortcut2 = Shortcut("32,29")
     existing_shortcut2.id = 2
     existing_shortcuts = [existing_shortcut1, existing_shortcut2]
     merged_shortcuts = merge_shortcuts_with_existing(
         shortcuts, existing_shortcuts)
     self.assertEqual(len(merged_shortcuts), 3)
     self.assertEqual(merged_shortcuts[0].id, 1)
     self.assertEqual(merged_shortcuts[0].keycodes, "32,28")
     self.assertEqual(merged_shortcuts[1].id, None)
     self.assertEqual(merged_shortcuts[1].keycodes, "32,30")
     self.assertEqual(merged_shortcuts[2].id, 2)
     self.assertEqual(merged_shortcuts[2].keycodes, "32,29")
Example #7
0
    def test_load_buttons_from_config(self):
        directory = os.path.dirname(os.path.abspath(__file__))
        buttons = load_buttons_from_config(directory,
                                           'data/buttons_config.json')

        self.assertEqual(2, len(buttons))
        first_button = buttons[0]
        second_button = buttons[1]
        self.assertEqual(first_button.program, "chrome")
        self.assertEqual(second_button.program, "chrome2")
        self.assertEqual(
            first_button.shortcuts,
            [Shortcut("32,28"), Shortcut("32,78")])
        self.assertEqual(second_button.shortcuts, [Shortcut("32,28")])
        self.assertEqual(first_button.templates, [
            Template(self.new_tab_template.tobytes(), 24, 324),
            Template(self.new_win_template.tobytes(), 24, 324)
        ])
        self.assertEqual(second_button.templates,
                         [Template(self.new_win_template.tobytes(), 24, 324)])
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)