This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |