general code/comment clean up.
This commit is contained in:
@@ -38,11 +38,11 @@ class Visitor(metaclass=ABCMeta):
|
||||
|
||||
class Visitee(object):
|
||||
"""
|
||||
A base class for objects that wish to be able to visit a Visitor class.
|
||||
A base class for objects that wish to be able to be visited by a Visitor class.
|
||||
"""
|
||||
def accept(self, visitor):
|
||||
"""
|
||||
Visit a visitor with this class instance.
|
||||
Have a visitor visit this class instance.
|
||||
|
||||
@param visitor: The visitor to visit.
|
||||
@type visitor: Visitor
|
||||
|
||||
@@ -20,7 +20,7 @@ class Factory(object, metaclass=ABCMeta):
|
||||
pass
|
||||
|
||||
|
||||
class AbstractFactory(object):
|
||||
class AbstractFactory(Factory):
|
||||
"""
|
||||
Abstract Factory Class.
|
||||
"""
|
||||
|
||||
@@ -7,9 +7,9 @@ class Prototype(object):
|
||||
Prototype design pattern abstract class.
|
||||
"""
|
||||
|
||||
def copy(self, **attributes):
|
||||
def prototype(self, **attributes):
|
||||
"""
|
||||
Copy this object and optionally update attributes.
|
||||
Copy the prototype this object and optionally update attributes.
|
||||
|
||||
@param attributes: Keyword arguments of any attributes you wish to update.
|
||||
@return: A copy of this object with the updated attributes.
|
||||
@@ -22,3 +22,4 @@ class Prototype(object):
|
||||
setattr(obj, attribute, attributes[attribute])
|
||||
|
||||
return obj
|
||||
|
||||
|
||||
@@ -26,52 +26,52 @@ class PrototypeTestCase(TestCase):
|
||||
self.__point_class = Point
|
||||
self.maxDiff = None
|
||||
|
||||
def test_copy_instances(self):
|
||||
def test_prototype_instances(self):
|
||||
"""
|
||||
Test that copy returns a new instance.
|
||||
Test that prototype returns a new instance.
|
||||
|
||||
@raise AssertionError: If the test fails.
|
||||
"""
|
||||
point_one = self.__point_class(5, 5)
|
||||
point_two = point_one.copy()
|
||||
point_two = point_one.prototype()
|
||||
|
||||
self.assertEquals(point_one.__class__, point_two.__class__)
|
||||
self.assertNotEquals(id(point_one), id(point_two))
|
||||
|
||||
def test_identical_copy(self):
|
||||
def test_identical_prototype(self):
|
||||
"""
|
||||
Test the copy method without updating any attributes.
|
||||
Test the prototype method without updating any attributes.
|
||||
|
||||
@raise AssertionError: If the test fails.
|
||||
"""
|
||||
point_one = self.__point_class(5, 5)
|
||||
point_two = point_one.copy()
|
||||
point_two = point_one.prototype()
|
||||
|
||||
self.assertEquals(point_one.__dict__, point_two.__dict__)
|
||||
|
||||
def test_update_attributes_copy(self):
|
||||
def test_update_attributes_prototype(self):
|
||||
"""
|
||||
Test the copy method with updated attributes.
|
||||
Test the prototype method with updated attributes.
|
||||
|
||||
@raise AssertionError: If the test fails.
|
||||
"""
|
||||
point_one = self.__point_class(10, 10)
|
||||
point_two = point_one.copy(x=15, y=20)
|
||||
point_three = point_two.copy()
|
||||
point_two = point_one.prototype(x=15, y=20)
|
||||
point_three = point_two.prototype()
|
||||
|
||||
self.assertEquals(point_one.__dict__, {'x': 10, 'y': 10})
|
||||
self.assertEquals(point_two.__dict__, {'x': 15, 'y': 20})
|
||||
self.assertEquals(point_three.__dict__, point_two.__dict__)
|
||||
|
||||
def test_add_attributes_copy(self):
|
||||
def test_add_attributes_prototype(self):
|
||||
"""
|
||||
Test the copy method with completely new attributes.
|
||||
Test the prototype method with completely new attributes.
|
||||
|
||||
@raise AssertionError: If the test fails.
|
||||
"""
|
||||
point_one = self.__point_class(15, 15)
|
||||
point_two = point_one.copy(z=20)
|
||||
point_three = point_two.copy()
|
||||
point_two = point_one.prototype(z=20)
|
||||
point_three = point_two.prototype()
|
||||
|
||||
self.assertEquals(point_one.x, point_two.x)
|
||||
self.assertEquals(point_one.y, point_two.y)
|
||||
@@ -80,9 +80,9 @@ class PrototypeTestCase(TestCase):
|
||||
self.assertEquals(point_two.z, 20)
|
||||
self.assertEquals(point_three.__dict__, point_two.__dict__)
|
||||
|
||||
def test_add_function_copy(self):
|
||||
def test_add_function_prototype(self):
|
||||
"""
|
||||
Test the copy method with a new instance method.
|
||||
Test the prototype method with a new instance method.
|
||||
|
||||
@raise AssertionError: If the test fails.
|
||||
"""
|
||||
@@ -91,8 +91,8 @@ class PrototypeTestCase(TestCase):
|
||||
def distance_to(this, other):
|
||||
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()
|
||||
point_two = point_one.prototype(distance_to=distance_to)
|
||||
point_three = point_two.prototype()
|
||||
|
||||
self.assertFalse(hasattr(point_one, 'distance_to'))
|
||||
self.assertTrue(hasattr(point_two, 'distance_to'))
|
||||
|
||||
Reference in New Issue
Block a user