ran code reformat

This commit is contained in:
tylerlaberge
2016-07-31 18:51:32 -04:00
parent 245b7bf2ba
commit 11f63418df
13 changed files with 49 additions and 33 deletions

View File

@@ -12,6 +12,7 @@ class ChainLink(object, metaclass=ABCMeta):
"""
Abstract ChainLink object as part of the Chain of Responsibility pattern.
"""
def __init__(self):
"""
Initialize a new ChainLink instance.
@@ -52,6 +53,7 @@ class Chain(object, metaclass=ABCMeta):
"""
Abstract Chain class as part of the Chain of Responsibility pattern.
"""
def __init__(self, chainlink):
"""
Initialize a new Chain instance.
@@ -76,4 +78,4 @@ class Chain(object, metaclass=ABCMeta):
"""
The method to call when the chain could not handle a request.
"""
pass
pass

View File

@@ -12,12 +12,14 @@ 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.
"""
def action(self, name, *args, **kwargs):
"""
Delegates which method to be called for a desired action.
@@ -37,6 +39,7 @@ class Command(object, metaclass=ABCMeta):
"""
Abstract Command class as part of the Command pattern.
"""
def __init__(self, receiver):
"""
Initialize a new command instance.
@@ -65,6 +68,7 @@ class Invoker(object, metaclass=ABCMeta):
"""
Abstract Invoker class as part of the Command pattern.
"""
def __init__(self, valid_commands):
"""
Initialize a new Invoker instance.

View File

@@ -7,6 +7,7 @@ class Director(object, metaclass=ABCMeta):
Part of the builder pattern.
"""
def __init__(self):
"""
Initialize a new Director.
@@ -39,6 +40,7 @@ class Builder(object):
Part of the builder pattern.
"""
def __init__(self, constructed_object):
"""
Initialize a new Builder.

View File

@@ -7,6 +7,7 @@ class Factory(object, metaclass=ABCMeta):
All Factories should inherit this class and overwrite the create method.
"""
@abstractmethod
def create(self, **kwargs):
"""
@@ -23,6 +24,7 @@ class AbstractFactory(object):
"""
Abstract Factory Class.
"""
def __init__(self):
"""
Initialize the abstract factory.

View File

@@ -6,6 +6,7 @@ class Reusable(object):
"""
An abstract reusable class.
"""
def __init__(self):
"""
Initialize a new Reusable instance.
@@ -24,6 +25,7 @@ class Pool(object, metaclass=Singleton):
"""
An Object Pool design pattern implementation.
"""
def __init__(self, reusable_class, *args, **kwargs):
"""
Initialize a new object pool instance.

View File

@@ -6,6 +6,7 @@ class Prototype(object):
"""
Prototype design pattern abstract class.
"""
def copy(self, **attributes):
"""
Copy this object and optionally update attributes.
@@ -21,6 +22,3 @@ class Prototype(object):
setattr(obj, attribute, attributes[attribute])
return obj

View File

@@ -1,4 +1,5 @@
from unittest import TestCase
from pypatterns.behavioral.chain import ChainException, ChainLink, Chain
@@ -6,10 +7,12 @@ class ChainLinkTestCase(TestCase):
"""
Unit testing class for the ChainLink class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class ConcreteChainLinkThree(ChainLink):
def handle(self, request):
@@ -71,10 +74,12 @@ class ChainTestCase(TestCase):
"""
Unit testing class for the Chain class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class ConcreteChainLinkThree(ChainLink):
def handle(self, request):

View File

@@ -1,4 +1,5 @@
from unittest import TestCase
from pypatterns.behavioral.command import InvalidActionException, InvalidInvokerCommandException, \
Receiver, Command, Invoker
@@ -7,12 +8,13 @@ class ReceiverTestCase(TestCase):
"""
Unit testing class for the Receiver class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class Thermostat(Receiver):
class Thermostat(Receiver):
def raise_temp(self, amount):
return "Temperature raised by {0} degrees".format(amount)
@@ -44,10 +46,12 @@ class CommandTestCase(TestCase):
"""
Unit testing class for the Command class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class Thermostat(Receiver):
def raise_temp(self, amount):
return "Temperature raised by {0} degrees".format(amount)
@@ -56,7 +60,6 @@ class CommandTestCase(TestCase):
return "Temperature lowered by {0} degrees".format(amount)
class RaiseTempCommand(Command):
def __init__(self, receiver, amount=5):
super().__init__(receiver)
self.amount = amount
@@ -68,7 +71,6 @@ class CommandTestCase(TestCase):
return self._receiver.action('lower_temp', self.amount)
class LowerTempCommand(Command):
def __init__(self, receiver, amount=5):
super().__init__(receiver)
self.amount = amount
@@ -100,10 +102,12 @@ class InvokerTestCase(TestCase):
"""
Unit testing class for the Invoker class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class Thermostat(Receiver):
def raise_temp(self, amount):
return "Temperature raised by {0} degrees".format(amount)
@@ -134,7 +138,6 @@ class InvokerTestCase(TestCase):
return self._receiver.action('raise_temp', self.amount)
class Worker(Invoker):
def __init__(self):
super().__init__([LowerTempCommand, RaiseTempCommand])
@@ -158,8 +161,8 @@ class InvokerTestCase(TestCase):
@raise AssertionError: If the test fails.
"""
class Light(Receiver):
class Light(Receiver):
def turn_on(self):
return "Light turned on"
@@ -167,7 +170,6 @@ class InvokerTestCase(TestCase):
return "Light turned off"
class TurnOnLightCommand(Command):
def execute(self):
return self._receiver.action('turn_on')

View File

@@ -1,16 +1,19 @@
from unittest import TestCase
from pypatterns.creational.builder import Director, Builder
from abc import ABCMeta, abstractmethod
from pypatterns.creational.builder import Director, Builder
class BuilderTestCase(TestCase):
"""
Unit testing class for the Builder class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class Building(object):
def __init__(self):
self.floor = None
@@ -20,7 +23,6 @@ class BuilderTestCase(TestCase):
return 'Floor: {0.floor} | Size: {0.size}'.format(self)
class HomeBuilder(Builder, metaclass=ABCMeta):
def __init__(self):
super().__init__(Building())
self._register('floor', self._build_floor)
@@ -35,7 +37,6 @@ class BuilderTestCase(TestCase):
pass
class HouseBuilder(HomeBuilder):
def _build_floor(self):
self.constructed_object.floor = 'One'
@@ -43,7 +44,6 @@ class BuilderTestCase(TestCase):
self.constructed_object.size = 'Big'
class FlatBuilder(HomeBuilder):
def _build_floor(self):
self.constructed_object.floor = 'More than one'
@@ -76,10 +76,12 @@ class DirectorTestCase(TestCase):
"""
Unit testing class for the Director class
"""
def setUp(self):
"""
Initialize testing data.
"""
class Building(object):
def __init__(self):
self.floor = None

View File

@@ -1,4 +1,5 @@
from unittest import TestCase
from pypatterns.creational.factory import Factory, AbstractFactory
@@ -6,27 +7,25 @@ class FactoryTestCase(TestCase):
"""
Unit testing class for the Factory class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class Cat(object):
class Cat(object):
def speak(self):
return 'Meow'
class Dog(object):
def speak(self):
return 'Woof'
class CatFactory(Factory):
def create(self, **kwargs):
return Cat()
class DogFactory(Factory):
def create(self, **kwargs):
return Dog()
@@ -55,10 +54,12 @@ class AbstractFactoryTestCase(TestCase):
"""
Unit testing class for the AbstractFactory class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class Cat(object):
def speak(self):
return 'Meow'
@@ -76,7 +77,6 @@ class AbstractFactoryTestCase(TestCase):
return Dog()
class AnimalFactory(AbstractFactory):
def __init__(self):
super().__init__()
self._register('cat', CatFactory)
@@ -103,4 +103,3 @@ class AbstractFactoryTestCase(TestCase):
self.assertEquals('Meow', cat.speak())
self.assertEquals('Woof', dog.speak())

View File

@@ -1,5 +1,6 @@
from copy import deepcopy
from unittest import TestCase
from copy import deepcopy
from pypatterns.creational.pool import Reusable, Pool
@@ -7,12 +8,13 @@ class ReusableTestCase(TestCase):
"""
Unit testing class for the reusable class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class Dog(Reusable):
class Dog(Reusable):
def __init__(self):
self.sound = "woof"
super(Dog, self).__init__()
@@ -52,19 +54,19 @@ class PoolTestCase(TestCase):
"""
Unit testing class for the Pool class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class Dog(Reusable):
class Dog(Reusable):
def __init__(self, sound, name):
self.sound = sound
self.name = name
super(Dog, self).__init__()
class DogPool(Pool):
def __init__(self):
super(DogPool, self).__init__(Dog, 'woof', 'george')
@@ -118,14 +120,12 @@ class PoolTestCase(TestCase):
dog_pool_two = self.dog_pool_class()
class Cat(Reusable):
def __init__(self, sound, name):
self.sound = sound
self.name = name
super().__init__()
class CatPool(Pool):
def __init__(self):
super().__init__(Cat, 'meow', 'tom')

View File

@@ -1,5 +1,6 @@
from math import sqrt
from unittest import TestCase
from pypatterns.creational.prototype import Prototype
@@ -7,12 +8,13 @@ class PrototypeTestCase(TestCase):
"""
Unit testing class for the Prototype class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class Point(Prototype):
class Point(Prototype):
def __init__(self, x, y):
self.x = x
self.y = y
@@ -87,7 +89,7 @@ class PrototypeTestCase(TestCase):
point_one = self.__point_class(20, 25)
def distance_to(this, other):
return sqrt((this.x - other.x)**2 + (this.y - other.y)**2)
return sqrt((this.x - other.x) ** 2 + (this.y - other.y) ** 2)
point_two = point_one.copy(distance_to=distance_to)
point_three = point_two.copy()
@@ -97,7 +99,3 @@ class PrototypeTestCase(TestCase):
self.assertEquals(point_two.distance_to(point_one), 0)
self.assertTrue(hasattr(point_three, 'distance_to'))
self.assertEquals(point_three.distance_to(point_two), 0)

View File

@@ -1,6 +1,6 @@
from abc import ABCMeta, ABC
from unittest import TestCase
from abc import ABCMeta, ABC
from tests.utils.dummy import dummy_class_factory