Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Add Tests In CodeBase (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelDobariya38 authored Jan 10, 2024
2 parents 313535b + 71f516b commit bf67341
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
2 changes: 1 addition & 1 deletion SmartManager/App/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions tests/test_app.py

This file was deleted.

28 changes: 28 additions & 0 deletions tests/test_command.py
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()
29 changes: 29 additions & 0 deletions tests/test_controller.py
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
19 changes: 19 additions & 0 deletions tests/test_mocking.py
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)

0 comments on commit bf67341

Please sign in to comment.