Skip to content

Commit

Permalink
leverage fixture and test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
wesker-albert committed Aug 1, 2023
1 parent dbbba0f commit 91c7d45
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 338 deletions.
22 changes: 11 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ disable = [
]

[tool.pylint-per-file-ignores]
"./tests/" = "missing-function-docstring,missing-class-docstring,missing-module-docstring,line-too-long"
"./tests/" = "missing-function-docstring,missing-class-docstring,missing-module-docstring,line-too-long,no-member,attribute-defined-outside-init,logging-too-many-args"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
31 changes: 12 additions & 19 deletions tests/actions/test_connect.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
from unittest.mock import ANY, Mock
from unittest.mock import ANY

from cibo.actions.connect import Connect
from tests.conftest import ClientFactory, ConnectActionFactory


def test_aliases():
connect = Connect(Mock(), Mock(), Mock())
class TestConnectAction(ClientFactory, ConnectActionFactory):
def test_aliases(self):
assert not self.connect.aliases()

assert not connect.aliases()
def test_required_args(self):
assert not self.connect.required_args()

def test_process(self):
self.connect.process(self.mock_client, None, [])

def test_required_args():
connect = Connect(Mock(), Mock(), Mock())

assert not connect.required_args()


def test_process():
output = Mock()
connect = Connect(Mock(), Mock(), output)
client = Mock()

connect.process(client, None, [])

output.private.assert_called_once_with(client, ANY, justify="center")
self.output.private.assert_called_once_with(
self.mock_client, ANY, justify="center"
)
69 changes: 26 additions & 43 deletions tests/actions/test_disconnect.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,39 @@
from unittest.mock import Mock

from cibo.actions.disconnect import Disconnect
from cibo.client import Client
from tests.conftest import ClientFactory, DisconnectActionFactory


def test_aliases():
connect = Disconnect(Mock(), Mock(), Mock())
class TestDisconnectAction(ClientFactory, DisconnectActionFactory):
def test_aliases(self):
assert not self.disconnect.aliases()

assert not connect.aliases()
def test_required_args(self):
assert not self.disconnect.required_args()

def test_process_not_logged_in(self):
self.mock_client.player = Mock()

def test_required_args():
connect = Disconnect(Mock(), Mock(), Mock())
self.disconnect.process(self.mock_client, None, [])

assert not connect.required_args()
self.mock_client.player.send.assert_not_called()
self.output.private.assert_not_called()

def test_process_no_player(self):
self.disconnect.process(self.mock_client, None, [])

def test_process_not_logged_in(mock_client: Client):
output = Mock()
connect = Disconnect(Mock(), Mock(), output)
self.output.private.assert_not_called()

mock_client.player = Mock()
def test_process(self):
self.mock_client.player = Mock()
self.mock_client.player.name = "John"
self.mock_client.player.current_room_id = 1
self.mock_client.is_logged_in.return_value = True

connect.process(mock_client, None, [])
self.disconnect.process(self.mock_client, None, [])

mock_client.player.send.assert_not_called()
output.private.assert_not_called()


def test_process_no_player(mock_client: Client):
output = Mock()
connect = Disconnect(Mock(), Mock(), output)

connect.process(mock_client, None, [])

output.private.assert_not_called()


def test_process(mock_client: Client):
output = Mock()
connect = Disconnect(Mock(), Mock(), output)

mock_client.player = Mock()
mock_client.player.name = "John"
mock_client.player.current_room_id = 1
mock_client.is_logged_in.return_value = True

connect.process(mock_client, None, [])

mock_client.player.save.assert_called_once()
output.local.assert_called_once_with(
1,
"You watch in horror as [cyan]John[/] proceeds to slowly eat their own head. They eventually disappear into nothingness.",
[mock_client],
)
self.mock_client.player.save.assert_called_once()
self.output.local.assert_called_once_with(
1,
"You watch in horror as [cyan]John[/] proceeds to slowly eat their own head. They eventually disappear into nothingness.",
[self.mock_client],
)
33 changes: 11 additions & 22 deletions tests/actions/test_error.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
from unittest.mock import Mock
from tests.conftest import ClientFactory, ErrorActionFactory

from cibo.actions.error import Error

class TestErrorAction(ClientFactory, ErrorActionFactory):
def test_aliases(self):
assert not self.error.aliases()

def test_aliases():
error = Error(Mock(), Mock(), Mock())
def test_required_args(self):
assert self.error.required_args() == ["message"]

assert not error.aliases()
def test_process(self):
self.error.process(self.mock_client, None, ["Something unexpected happened!"])


def test_required_args():
error = Error(Mock(), Mock(), Mock())

assert error.required_args() == ["message"]


def test_process():
output = Mock()
error = Error(Mock(), Mock(), output)
client = Mock()

error.process(client, None, ["Something unexpected happened!"])

output.private.assert_called_once_with(
client, "[bright_red]Something unexpected happened![/]"
)
self.output.private.assert_called_once_with(
self.mock_client, "[bright_red]Something unexpected happened![/]"
)
30 changes: 9 additions & 21 deletions tests/actions/test_prompt.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
from unittest.mock import Mock
from tests.conftest import ClientFactory, PromptActionFactory

from cibo.actions.prompt import Prompt
from cibo.client import Client

class TestPromptAction(ClientFactory, PromptActionFactory):
def test_aliases(self):
assert not self.prompt.aliases()

def test_aliases():
prompt = Prompt(Mock(), Mock(), Mock())
def test_required_args(self):
assert not self.prompt.required_args()

assert not prompt.aliases()
def test_process(self):
self.prompt.process(self.mock_client, None, [])


def test_required_args():
prompt = Prompt(Mock(), Mock(), Mock())

assert not prompt.required_args()


def test_process(client: Client):
output = Mock()
output.prompt = Mock()
prompt = Prompt(Mock(), Mock(), output)

prompt.process(client, None, [])

output.prompt.assert_called_once_with(client)
self.output.prompt.assert_called_once_with(self.mock_client)
Loading

0 comments on commit 91c7d45

Please sign in to comment.