ran code reformat
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user