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