From 7501604bbf07613ae2c30d65e8242dfc285644a5 Mon Sep 17 00:00:00 2001 From: tylerlaberge Date: Sun, 28 Aug 2016 20:27:18 -0400 Subject: [PATCH] replaced custom command pattern exceptions with attributeerror exceptions. --- pypatterns/behavioral/command.py | 18 ++---------------- tests/behavioral_tests/test_command.py | 7 +++---- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/pypatterns/behavioral/command.py b/pypatterns/behavioral/command.py index ab9e10f..dbaa2a8 100644 --- a/pypatterns/behavioral/command.py +++ b/pypatterns/behavioral/command.py @@ -1,20 +1,6 @@ from abc import ABCMeta, abstractmethod -class InvalidActionException(Exception): - """ - Exception for when an invalid action is called on a Receiver. - """ - pass - - -class InvalidInvokerCommandException(Exception): - """ - Exception for when an invalid command is given to an Invoker to execute. - """ - pass - - class Receiver(object, metaclass=ABCMeta): """ Abstract receiver class as part of the Command pattern. @@ -33,7 +19,7 @@ class Receiver(object, metaclass=ABCMeta): try: return getattr(self, name)(*args, **kwargs) except AttributeError: - raise InvalidActionException + raise AttributeError('Invalid Action.') class Command(object, metaclass=ABCMeta): @@ -89,7 +75,7 @@ class Invoker(object, metaclass=ABCMeta): @type command: Command """ if command.__class__ not in self._valid_commands: - raise InvalidInvokerCommandException + raise AttributeError('Invalid Command') else: self._history.append(command) return command.execute() diff --git a/tests/behavioral_tests/test_command.py b/tests/behavioral_tests/test_command.py index 179a46e..d092328 100644 --- a/tests/behavioral_tests/test_command.py +++ b/tests/behavioral_tests/test_command.py @@ -1,7 +1,6 @@ from unittest import TestCase -from pypatterns.behavioral.command import InvalidActionException, InvalidInvokerCommandException, \ - Receiver, Command, Invoker +from pypatterns.behavioral.command import Receiver, Command, Invoker class ReceiverTestCase(TestCase): @@ -38,7 +37,7 @@ class ReceiverTestCase(TestCase): @raise AssertionError: If the test fails. """ - with self.assertRaises(InvalidActionException): + with self.assertRaises(AttributeError): self.thermostat.action('foo') @@ -176,7 +175,7 @@ class InvokerTestCase(TestCase): def unexecute(self): return self._receiver.action('turn_off') - with self.assertRaises(InvalidInvokerCommandException): + with self.assertRaises(AttributeError): self.worker.execute(TurnOnLightCommand(Light)) def test_undo(self):