From b5c669c2a9928ed1184ab7d23ae0c2c4de451ef3 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 31 Oct 2014 17:58:47 -0400 Subject: expand the tests --- t/mop_test.py | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/t/mop_test.py b/t/mop_test.py index 125b170..1b5b6c8 100644 --- a/t/mop_test.py +++ b/t/mop_test.py @@ -50,8 +50,8 @@ class MopTest(unittest.TestCase): superclass=mop.Class.base_object_class() ) - Point.add_attribute(Point.attribute_class().new(name="x")) - Point.add_attribute(Point.attribute_class().new(name="y")) + Point.add_attribute(Point.attribute_class().new(name="x", default=0)) + Point.add_attribute(Point.attribute_class().new(name="y", default=0)) Point.add_method(Point.method_class().new( name="x", @@ -61,24 +61,52 @@ class MopTest(unittest.TestCase): name="y", body=lambda self: self.metaclass.get_all_attributes()["y"].get_value(self) )) + Point.add_method(Point.method_class().new( + name="set_x", + body=lambda self, new_value: self.metaclass.get_all_attributes()["x"].set_value(self, new_value) + )) Point.finalize() + assert Point.metaclass is mop.Class + assert Point.isa(mop.Object) + assert Point.get_superclass() is mop.Object + assert Point.get_mro() == [ Point, mop.Object ] + point = Point.new(x=1, y=2) + assert point.isa(Point) + assert point.metaclass is Point assert point.x() == 1 assert point.y() == 2 + point.set_x(10) + assert point.x() == 10 + + point2 = Point.new(x=3, y=4) + assert point is not point2 + assert point.x() == 10 + assert point.y() == 2 + assert point2.x() == 3 + assert point2.y() == 4 Point3D = Point.metaclass.new( name="Point3D", superclass=Point, ) - Point3D.add_attribute(Point3D.attribute_class().new(name="z")) + Point3D.add_attribute(Point3D.attribute_class().new(name="z", default=0)) Point3D.add_method(Point3D.method_class().new( name="z", body=lambda self: self.metaclass.get_all_attributes()["z"].get_value(self) )) Point3D.finalize() + assert Point3D.metaclass is mop.Class + assert Point3D.isa(mop.Object) + assert Point3D.get_superclass() is Point + assert Point3D.get_mro() == [ Point3D, Point, mop.Object ] + point3d = Point3D.new(x=3, y=4, z=5) + assert point3d.isa(Point3D) + assert point3d.isa(Point) + assert point3d.isa(mop.Object) assert point3d.x() == 3 assert point3d.y() == 4 assert point3d.z() == 5 @@ -90,3 +118,10 @@ class MopTest(unittest.TestCase): assert point3d.isa(Point) assert not point.isa(Point3D) assert point3d.isa(Point3D) + + point_default = Point.new() + assert point_default.x() == 0 + assert point_default.y() == 0 + point3d_default = Point3D.new() + assert point3d_default.x() == 0 + assert point3d_default.y() == 0 -- cgit v1.2.3