diff --git a/SmartManager/App/command.py b/SmartManager/App/command.py index 47d4016..dfda53a 100644 --- a/SmartManager/App/command.py +++ b/SmartManager/App/command.py @@ -47,7 +47,7 @@ def match(self, textrepr: str) -> bool: return True def execute(self, controller): - controller.userinterface.show_output("Invaild Command!!") + controller.userinterface.show_output("Invalid Command!!") class WelcomeCommand(Command): diff --git a/tests/test_app.py b/tests/test_app.py deleted file mode 100644 index c9a9540..0000000 --- a/tests/test_app.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_app(): - assert True \ No newline at end of file diff --git a/tests/test_command.py b/tests/test_command.py new file mode 100644 index 0000000..9b6bc79 --- /dev/null +++ b/tests/test_command.py @@ -0,0 +1,28 @@ +# File: tests/test_command.py +from test_mocking import controller +from SmartManager.App.command import Command, HelpCommand, QuitCommand, InvalidCommand + +def test_empty_command(controller): + assert not controller.command.match("") + +def test_add_command(): + Command.add(HelpCommand()) + assert isinstance(Command.commands[-1], HelpCommand) + +def test_help_command_execution(capsys, controller): + command = HelpCommand() + command.execute(controller) + captured = capsys.readouterr() + assert "Here is list of valid Commands:\n\n" in captured.out + assert "Commands:\n" in captured.out + +def test_invalid_command_execution(capsys, controller): + command = InvalidCommand() + command.execute(controller) + captured = capsys.readouterr() + assert "Invalid Command!!" in captured.out + +def test_quit_command_execution(controller): + command = QuitCommand() + command.execute(controller) + assert not controller.isrunning() diff --git a/tests/test_controller.py b/tests/test_controller.py new file mode 100644 index 0000000..5793f60 --- /dev/null +++ b/tests/test_controller.py @@ -0,0 +1,29 @@ +# File: tests/test_controller.py +from test_mocking import controller +from SmartManager.App.command import HelpCommand, InvalidCommand + +def test_get_command_valid_input(controller, monkeypatch): + monkeypatch.setattr('builtins.input', lambda _: 'help') + cmd = controller.get_command() + assert isinstance(cmd, HelpCommand) + +def test_get_command_invalid_input(controller, monkeypatch): + monkeypatch.setattr('builtins.input', lambda _: 'invalid') + cmd = controller.get_command() + assert isinstance(cmd, InvalidCommand) + +def test_initial_state(controller): + assert not controller.isrunning() + +def test_run_and_quit(controller): + controller.run() + assert controller.isrunning() + + controller.quit() + assert not controller.isrunning() + +def test_welcome_execution(capsys, controller): + controller.welcome() + + captured = capsys.readouterr() + assert "Welcome To Smart Manager" in captured.out diff --git a/tests/test_mocking.py b/tests/test_mocking.py new file mode 100644 index 0000000..c76c87d --- /dev/null +++ b/tests/test_mocking.py @@ -0,0 +1,19 @@ +from SmartManager.App.controller import Controller +from SmartManager.App.command import Command, CommandInterface +from SmartManager.App.datahandler import Datahandler +from SmartManager.App.interface import CLI + +import pytest + +@pytest.fixture +def controller(): + controller = Controller() + controller.userinterface = CLI() + controller.command = Command() + controller.datahandler = Datahandler() + return controller + +def test_controller(controller): + assert isinstance(controller.command, CommandInterface) + assert isinstance(controller.userinterface, CLI) + assert isinstance(controller.datahandler, Datahandler) \ No newline at end of file