diff --git a/command_line_assistant/commands/record.py b/command_line_assistant/commands/record.py deleted file mode 100644 index 1394e16..0000000 --- a/command_line_assistant/commands/record.py +++ /dev/null @@ -1,66 +0,0 @@ -"""Module to handle the record command. - -Note: - This needs more refinement, script session can't be combined with other arguments -""" - -import logging -from argparse import Namespace -from pathlib import Path - -from command_line_assistant.handlers import handle_script_session -from command_line_assistant.utils.cli import BaseCLICommand, SubParsersAction - -logger = logging.getLogger(__name__) - - -class RecordCommand(BaseCLICommand): - """Class that represents the record command.""" - - def __init__(self, output_file: str) -> None: - """Constructor of the class. - - Args: - output_file (str): The file to write the output. - """ - self._output_file = output_file - super().__init__() - - def run(self) -> int: - """Main entrypoint for the command to run. - - Returns: - int: Status code of the execution. - """ - handle_script_session(Path(self._output_file)) - return 0 - - -def register_subcommand(parser: SubParsersAction): - """ - Register this command to argparse so it's available for the root parser. - - Args: - parser (SubParsersAction): Root parser to register command-specific arguments - """ - record_parser = parser.add_parser( - "record", - help="Start a recording session for script output.", - ) - record_parser.add_argument( - "--output-file", help="The place where to store the output file." - ) - - record_parser.set_defaults(func=_command_factory) - - -def _command_factory(args: Namespace) -> RecordCommand: - """Internal command factory to create the command class - - Args: - args (Namespace): The arguments processed with argparse. - - Returns: - RecordCommand: Return an instance of class - """ - return RecordCommand(args.output_file) diff --git a/command_line_assistant/initialize.py b/command_line_assistant/initialize.py index 35adce1..d703d45 100644 --- a/command_line_assistant/initialize.py +++ b/command_line_assistant/initialize.py @@ -3,7 +3,7 @@ import sys from argparse import ArgumentParser, Namespace -from command_line_assistant.commands import history, query, record +from command_line_assistant.commands import history, query from command_line_assistant.rendering.decorators.colors import ColorDecorator from command_line_assistant.rendering.decorators.text import EmojiDecorator from command_line_assistant.rendering.renders.text import TextRenderer @@ -27,7 +27,6 @@ def register_subcommands() -> ArgumentParser: # and call `register_subcommand()` on each one. query.register_subcommand(commands_parser) # type: ignore history.register_subcommand(commands_parser) # type: ignore - record.register_subcommand(commands_parser) # type: ignore return parser diff --git a/tests/commands/test_record.py b/tests/commands/test_record.py deleted file mode 100644 index 5a0122d..0000000 --- a/tests/commands/test_record.py +++ /dev/null @@ -1,104 +0,0 @@ -from argparse import ArgumentParser -from pathlib import Path -from unittest.mock import patch - -import pytest - -from command_line_assistant.commands.record import RecordCommand, register_subcommand - - -@pytest.fixture -def record_command(): - """Fixture to create a RecordCommand instance.""" - test_output_file = "/tmp/test_output.txt" - return RecordCommand(test_output_file) - - -@pytest.fixture -def parser(): - """Fixture to create an ArgumentParser instance.""" - parser = ArgumentParser() - return parser.add_subparsers() - - -def test_init(record_command): - """Test initialization of RecordCommand.""" - assert record_command._output_file == "/tmp/test_output.txt" - - -@patch("command_line_assistant.commands.record.handle_script_session") -def test_run(mock_handle_script_session, record_command): - """Test the run method of RecordCommand.""" - record_command.run() - - # Verify handle_script_session was called with correct path - mock_handle_script_session.assert_called_once_with(Path("/tmp/test_output.txt")) - - -@patch("command_line_assistant.commands.record.handle_script_session") -def test_run_with_empty_output_file(mock_handle_script_session): - """Test the run method with empty output file.""" - record_command = RecordCommand("") - record_command.run() - - # Verify handle_script_session was called with empty path - mock_handle_script_session.assert_called_once_with(Path("")) - - -@patch("command_line_assistant.commands.record.handle_script_session") -def test_run_with_error(mock_handle_script_session, record_command): - """Test the run method when handle_script_session raises an exception.""" - mock_handle_script_session.side_effect = Exception("Script session error") - - with pytest.raises(Exception) as exc_info: - record_command.run() - - assert str(exc_info.value) == "Script session error" - mock_handle_script_session.assert_called_once() - - -def test_register_subcommand(parser): - """Test registration of subcommand in parser.""" - # Register subcommand - register_subcommand(parser) - - # Create parent parser to test argument parsing - parent_parser = ArgumentParser() - subparsers = parent_parser.add_subparsers() - register_subcommand(subparsers) - - # Parse args with record command - args = parent_parser.parse_args(["record"]) - - # Verify the command creates correct RecordCommand instance - command = args.func(args) - assert isinstance(command, RecordCommand) - - -@pytest.mark.parametrize( - ("output_file", "expected_path"), - [ - ("/tmp/test.txt", Path("/tmp/test.txt")), - ("", Path("")), - ("/var/log/output.log", Path("/var/log/output.log")), - ], -) -@patch("command_line_assistant.commands.record.handle_script_session") -def test_record_command_different_paths( - mock_handle_script_session, output_file, expected_path -): - """Test RecordCommand with different output file paths.""" - command = RecordCommand(output_file) - command.run() - mock_handle_script_session.assert_called_once_with(expected_path) - - -def test_record_command_attributes(): - """Test RecordCommand instance attributes.""" - output_file = "/tmp/test_output.txt" - command = RecordCommand(output_file) - - assert hasattr(command, "_output_file") - assert command._output_file == output_file - assert hasattr(command, "run") - assert callable(command.run) diff --git a/tests/test_initialize.py b/tests/test_initialize.py index 781635e..a7030ac 100644 --- a/tests/test_initialize.py +++ b/tests/test_initialize.py @@ -43,7 +43,6 @@ def test_initialize_with_query_command(argv, stdin): patch("sys.argv", argv), patch("command_line_assistant.commands.query.register_subcommand"), patch("command_line_assistant.commands.history.register_subcommand"), - patch("command_line_assistant.commands.record.register_subcommand"), patch("command_line_assistant.initialize.read_stdin", lambda: stdin), patch("argparse.ArgumentParser.parse_args") as mock_parse, ): @@ -62,26 +61,6 @@ def test_initialize_with_history_command(): patch("sys.argv", ["c", "history", "--clear"]), patch("command_line_assistant.commands.query.register_subcommand"), patch("command_line_assistant.commands.history.register_subcommand"), - patch("command_line_assistant.commands.record.register_subcommand"), - patch("command_line_assistant.initialize.read_stdin", lambda: None), - patch("argparse.ArgumentParser.parse_args") as mock_parse, - ): - mock_parse.return_value.func = mock_command - result = initialize() - - assert result == 0 - mock_command.assert_called_once() - - -def test_initialize_with_record_command(): - """Test initialize with record command""" - mock_command = Mock(return_value=MockCommand()) - - with ( - patch("sys.argv", ["c", "record"]), - patch("command_line_assistant.commands.query.register_subcommand"), - patch("command_line_assistant.commands.history.register_subcommand"), - patch("command_line_assistant.commands.record.register_subcommand"), patch("command_line_assistant.initialize.read_stdin", lambda: None), patch("argparse.ArgumentParser.parse_args") as mock_parse, ): @@ -139,7 +118,6 @@ def test_initialize_bad_stdin(capsys): (["c"], "query"), # Default to query (["c", "query"], "query"), (["c", "history"], "history"), - (["c", "record"], "record"), ], ) def test_initialize_command_selection(argv, expected_command): @@ -151,7 +129,6 @@ def test_initialize_command_selection(argv, expected_command): patch("command_line_assistant.initialize.read_stdin", lambda: None), patch("command_line_assistant.commands.query.register_subcommand"), patch("command_line_assistant.commands.history.register_subcommand"), - patch("command_line_assistant.commands.record.register_subcommand"), patch("argparse.ArgumentParser.parse_args") as mock_parse, ): mock_parse.return_value.func = mock_command