From 3b9bff2ef1826987d95815ff03c235052cea9aae Mon Sep 17 00:00:00 2001 From: mike Date: Sat, 17 Oct 2009 17:47:58 +0000 Subject: LP 439980 : Code review changes : renamed is_identical to __eq__, relaxed action insertion constraints, added fixed meta-props for addons --- (limited to 'tests/propertiestests.py') diff --git a/tests/propertiestests.py b/tests/propertiestests.py index 03e7814..0b8251a 100644 --- a/tests/propertiestests.py +++ b/tests/propertiestests.py @@ -17,6 +17,7 @@ import unittest import uuid import os +import copy from sugar.tutorius.constraints import * from sugar.tutorius.properties import * @@ -84,14 +85,14 @@ class BasePropertyTest(unittest.TestCase): assert obj.prop == 2, "Unable to set a value on base class" - def test_is_identical(self): + def test_eq_(self): class klass(TPropContainer): prop = TutoriusProperty() obj = klass() obj2 = klass() - assert obj.is_identical(obj2), "Base property containers should be identical" + assert obj == obj2, "Base property containers should be identical" class AdvancedPropertyTest(unittest.TestCase): def test_properties_groups(self): @@ -104,11 +105,6 @@ class AdvancedPropertyTest(unittest.TestCase): property = TutoriusProperty() data = TutoriusProperty() - class klass2(TPropContainer): - property = TutoriusProperty() - message = TutoriusProperty() - data = TutoriusProperty() - class klass3(TPropContainer): property = TutoriusProperty() message = TutoriusProperty() @@ -125,7 +121,7 @@ class AdvancedPropertyTest(unittest.TestCase): obj1.message = "Initial message" obj1.data = [132, 208, 193, 142] - obj2 = klass2() + obj2 = klass1() obj2.property = 12 obj2.message = "Initial message" obj2.data = [132, 208, 193, 142] @@ -143,16 +139,20 @@ class AdvancedPropertyTest(unittest.TestCase): # Ensure that both obj1 and obj2 are identical (they have the same list of # properties and they have the same values - assert obj1.is_identical(obj2), "Identical objects were considered as different" + assert obj1 == obj1, "Identical objects were considered as different" # Ensure that obj1 is different from obj3, since obj3 has an extra property - assert obj1.is_identical(obj3) == False, "Objects should not be identical since obj3 has more props" - assert obj3.is_identical(obj1) == False, "Objects should not be identical since obj3 has more properties" + assert not (obj1 == obj3), "Objects should not be identical since obj3 has more props" + assert not (obj3 == obj1), "Objects should not be identical since obj3 has more properties" # Ensure that properties of different type are considered as different - assert obj1.is_identical(obj4) == False, "Properties of different type should not be equal" + assert not (obj1 == obj4), "Properties of different type should not be equal" def test_addon_properties(self): + """Test an addon property. + + This tests creates a class with a single addon property (klass1) and + assigns a new addon to it (inner1).""" class klass1(TPropContainer): addon = TAddonProperty() @@ -168,12 +168,12 @@ class AdvancedPropertyTest(unittest.TestCase): obj2 = klass1() obj2.addon = inner1("Hi!") - assert obj1.is_identical(obj2), "Identical objects with addon proeprties were treated as different" + assert obj1 == obj2, "Identical objects with addon properties were treated as different" obj3 = klass1() obj3.addon = inner1("Hello!") - assert obj1.is_identical(obj3) == False, "Objects with addon property having a different value should be considered different" + assert not (obj1 == obj3), "Objects with addon property having a different value should be considered different" def test_addonlist_properties(self): class klass1(TPropContainer): @@ -200,11 +200,11 @@ class AdvancedPropertyTest(unittest.TestCase): obj2 = klass1() obj2.addon_list = [inner1('Hi!', 12), inner1('Hello.', [1,2])] - assert obj1.is_identical(obj2), "Addon lists with the same containers were considered different" + assert obj1 == obj2, "Addon lists with the same containers were considered different" obj3 = klass1() obj3.addon_list = [inner1('Hi!', 12), inner2('Hello.', [1,2])] - assert obj1.is_identical(obj3) == False, "Differently named proeprties should be considered different in the addon list tests" + assert not (obj1 == obj3), "Differently named properties should be considered different in the addon list tests" class TIntPropertyTest(unittest.TestCase): def test_int_property(self): -- cgit v0.9.1