Exemplo n.º 1
0
 def test_addCommandToSqlStore_whenAddingCommand_shouldBeInStore(
         self) -> None:
     command_store = SqlCommandStore(':memory:')
     self.assertEqual(0, command_store.get_num_commands())
     command_str = "some command string"
     directory_path = 'directory/path'
     command = Command(command_str, directory_context=directory_path)
     command_store.add_command(command)
     self.assertTrue(command_store.has_command(command))
     self.assertFalse(
         command_store.has_command(Command("some other command")))
     self.assertEqual(1, command_store.get_num_commands())
Exemplo n.º 2
0
 def test_store_add_whenCommandHasContext_shouldInsertWithContext(
         self) -> None:
     command_store = SqlCommandStore(':memory:')
     self.assertEqual(0, command_store.get_num_commands())
     command_str = "some command string"
     context_path = 'some/directory/context'
     command1 = Command(command_str, 10.0, 1, 'command info', context_path)
     command_str2 = "some second command"
     command2 = Command(command_str2, 10.0, 1, 'command info', context_path)
     command_store.add_command(command1)
     command_store.add_command(command2)
     self.assertEqual(2, command_store.get_num_commands())
Exemplo n.º 3
0
 def test_add_command_whenSameContextAddedTwice_shouldUpdateTheEntryCount(
         self) -> None:
     command_store = SqlCommandStore(':memory:')
     self.assertEqual(0, command_store.get_num_commands())
     command_str = "some command string"
     context_path = 'some/directory/context'
     command1 = Command(command_str, 11.0, 1, 'command info 1',
                        context_path)
     command_store.add_command(command1)
     command_store.add_command(command1)
     results = command_store.get_command_with_context(context_path, [])
     self.assertEqual(1, command_store.get_num_commands())
     self.assertEqual(1, len(results))
     self.assertEqual(context_path, results[0].get_directory_context())
Exemplo n.º 4
0
 def test_addCommand_whenMultipleCommandsAndQueryParams_shouldReturnAppropriateMatchingQuery(
         self) -> None:
     store = SqlCommandStore(':memory:')
     self.assertEqual(0, store.get_num_commands())
     command_str1 = "some command string"
     directory_path1 = 'directory/path'
     command1 = Command(command_str1,
                        last_used=1,
                        directory_context=directory_path1)
     command_str2 = "some different command"
     command_str3 = "different command"
     command2 = Command(command_str2,
                        last_used=2,
                        directory_context=directory_path1)
     command3 = Command(command_str3,
                        last_used=3,
                        directory_context=directory_path1)
     store.add_command(command1)
     store.add_command(command2)
     store.add_command(command3)
     commands = store.get_command_with_context(directory_path1,
                                               ['different'])
     self.assertEqual(2, len(commands))
     result_command = commands[0]
     # Newer on first
     self.assertEqual(command3.get_unique_command_id(),
                      result_command.get_unique_command_id())
Exemplo n.º 5
0
 def test_addCommand_whenCommandsDeleted_shouldNotShowupInResultsforDirSearch(
         self) -> None:
     store = SqlCommandStore(':memory:')
     self.assertEqual(0, store.get_num_commands())
     command_str1 = "some command string"
     directory_path1 = 'directory/path'
     command1 = Command(command_str1,
                        last_used=1,
                        directory_context=directory_path1)
     command_str2 = "some different command"
     command2 = Command(command_str2,
                        last_used=2,
                        directory_context=directory_path1)
     store.add_command(command1)
     store.add_command(command2)
     commands = store.get_command_with_context(directory_path1, [])
     self.assertEqual(2, len(commands))
     store.delete_command(command_str1)
     commands = store.get_command_with_context(directory_path1, [])
     self.assertEqual(1, len(commands))
     self.assertEqual(commands[0].get_unique_command_id(),
                      command2.get_unique_command_id())
     store.add_command(command1)
     store.delete_command(command_str2)
     commands = store.get_command_with_context(directory_path1, [])
     self.assertEqual(1, len(commands))
     self.assertEqual(commands[0].get_unique_command_id(),
                      command1.get_unique_command_id())
     self.assertEqual(commands[0].get_count_seen(), 1)
Exemplo n.º 6
0
 def test_addCommand_whenSameCommandAndContext_shouldReturnAppropriateCount(
         self) -> None:
     store = SqlCommandStore(':memory:')
     self.assertEqual(0, store.get_num_commands())
     command_str = "some command string"
     directory_path = 'directory/path'
     command = Command(command_str, directory_context=directory_path)
     store.add_command(command)
     store.add_command(command)
     store.add_command(command)
     store.add_command(command)
     self.assertTrue(store.has_command(command))
     self.assertEqual(1, store.get_num_commands())
     commands = store.get_command_with_context(directory_path, [])
     self.assertEqual(1, len(commands))
     result_command = commands[0]
     self.assertEqual(4, result_command.get_count_seen())
Exemplo n.º 7
0
 def test_add_commands_whenCommandAdded2Time_shouldReflectInCount(
         self) -> None:
     command_store = SqlCommandStore(':memory:')
     self.assertEqual(0, command_store.get_num_commands())
     command_str = "some command string"
     context_path = 'some/directory/context'
     context_path2 = 'notqueried/dir'
     command1 = Command(command_str, 11.0, 1, 'command info 1',
                        context_path)
     command_str2 = "some second command"
     command2 = Command(command_str2, 12.0, 2, 'command info 2',
                        context_path2)
     command_store.add_command(command1)
     command_store.add_command(command2)
     results = command_store.get_command_with_context(context_path, [])
     self.assertEqual(2, command_store.get_num_commands())
     self.assertEqual(1, len(results))
     self.assertEqual(context_path, results[0].get_directory_context())
Exemplo n.º 8
0
 def test_get_commands_from_context_whenContextQueried_shouldReturn2Commands(
         self) -> None:
     command_store = SqlCommandStore(':memory:')
     self.assertEqual(0, command_store.get_num_commands())
     command_str = "some command string"
     context_path = 'some/directory/context'
     command1 = Command(command_str, 11.0, 1, 'command info 1',
                        context_path)
     command_str2 = "some second command"
     command2 = Command(command_str2, 12.0, 2, 'command info 2',
                        context_path)
     command_store.add_command(command1)
     command_store.add_command(command2)
     results = command_store.get_command_with_context(context_path, [])
     self.assertEqual(2, command_store.get_num_commands())
     self.assertEqual(2, len(results))
     self.assertEqual(command_str2, results[0].get_unique_command_id())
     self.assertEqual(command_str, results[1].get_unique_command_id())
     self.assertEqual(context_path, results[0].get_directory_context())
     self.assertEqual(context_path, results[1].get_directory_context())
Exemplo n.º 9
0
    def test_search_commands_sorted(self) -> None:
        command_store = SqlCommandStore(':memory:')
        self.assertEqual(0, command_store.get_num_commands())
        command_str = "some command string"
        command = Command(command_str, 10.0, 1)
        command_store.add_command(command)
        command_str2 = "somelater command string"
        command2 = Command(command_str2, 20.0, 1)
        command_store.add_command(command2)

        result = command_store.search_commands(["some"],
                                               starts_with=False,
                                               sort=True)
        self.assertEqual(result[0].get_unique_command_id(),
                         command2.get_unique_command_id())
        self.assertEqual(result[1].get_unique_command_id(),
                         command.get_unique_command_id())
Exemplo n.º 10
0
 def test_addCommand_when2Commands_shouldReturnAppropriateTimeOrder(
         self) -> None:
     store = SqlCommandStore(':memory:')
     self.assertEqual(0, store.get_num_commands())
     command_str1 = "some command string"
     directory_path1 = 'directory/path'
     command1 = Command(command_str1,
                        last_used=1,
                        directory_context=directory_path1)
     command_str2 = "some different command"
     command2 = Command(command_str2,
                        last_used=2,
                        directory_context=directory_path1)
     store.add_command(command1)
     store.add_command(command2)
     commands = store.get_command_with_context(directory_path1, [])
     self.assertEqual(2, len(commands))
     result_command = commands[0]
     # Newer on first
     self.assertEqual(command2.get_unique_command_id(),
                      result_command.get_unique_command_id())
Exemplo n.º 11
0
 def test_SqlCommandStore_isEmpty(self) -> None:
     command_store = SqlCommandStore(':memory:')
     self.assertEqual(0, command_store.get_num_commands())