Changeset 2887
- Timestamp:
- 03/06/2007 11:50:06 PM (2 years ago)
- Files:
-
- trunk/dabo/dObject.py (modified) (1 diff)
- trunk/tests/unitTests/Test_dObject.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/dObject.py
r2885 r2887 269 269 if not isinstance(val, types.StringTypes): 270 270 raise TypeError, 'Name must be a string.' 271 if not len(val.split()) == 1: 272 raise KeyError, 'Name must not contain any spaces' 271 273 self._name = val 272 274 trunk/tests/unitTests/Test_dObject.py
r2886 r2887 19 19 def setUp(self): 20 20 self.dObject = dObject() 21 22 def setProperty(self, propertyInfo): 23 """setProperty(self, (object.property, val))""" 24 exec("%s = %s" % propertyInfo) 21 25 22 26 class TestApplicationProperty(BaseTestdObject): … … 29 33 def testSetApplication(self): 30 34 """Setting dObject.Application should fail""" 31 def setApplication(app): 32 self.dObject.Application = app 33 self.assertRaises(AttributeError, setApplication, 42) 35 self.assertRaises(AttributeError, self.setProperty, ("self.dObject.Application", "42")) 34 36 35 37 def testGetApplication(self): … … 47 49 def testSetBaseClass(self): 48 50 """Setting dObject.BaseClass should fail for all inputs""" 49 def setBaseClass(self): 50 self.dObject.BaseClass = 42 51 self.assertRaises(AttributeError, setBaseClass, 42) 51 self.assertRaises(AttributeError, self.setProperty, ("self.dObject.BaseClass", "42")) 52 52 53 53 def testGetBaseClassNoSubclass(self): … … 74 74 def testBasePrefFailOnNonString(self): 75 75 """setting dObject.BasePrefKey should fail if value is not a string""" 76 def setBasePrefKey(val): 77 self.dObject.BasePrefKey = val 78 self.assertRaises(TypeError, setBasePrefKey, 42) 76 self.assertRaises(TypeError, self.setProperty, ("self.dObject.BasePrefKey", "42")) 79 77 80 78 class TestClassProperty(BaseTestdObject): … … 88 86 def testSetClassShouldFail(self): 89 87 """setting dObject.Class should fail for all inputs""" 90 def setClass(val): 91 self.dObject.Class = val 92 self.assertRaises(AttributeError, setClass, 42) 88 self.assertRaises(AttributeError, self.setProperty, ("self.dObject.Class", "42")) 93 89 94 90 def testGetClassNoSubclass(self): … … 109 105 - dObject.Name should return '?' if no name is assigned 110 106 - dObject.Name should fail when given a non-string input 107 - dObject.Name should fail when given an input with spaces 111 108 """ 112 109 113 110 def testRoundTrip(self): 114 111 """Set dObject.Name to n. dObject.Name should be equal to n. (round trip test)""" 115 self.dObject.Name = "Test Name"116 self.assertEqual("Test Name", self.dObject.Name)112 self.dObject.Name = "TestName" 113 self.assertEqual("TestName", self.dObject.Name) 117 114 118 115 def testNoNameSet(self): … … 122 119 def testFailOnNonStringInput(self): 123 120 """dObject.Name should fail when given a non-string input""" 124 def setName(val): 125 self.dObject.Name = val 126 self.assertRaises(TypeError, setName, 42) 121 self.assertRaises(TypeError, self.setProperty, ("self.dObject.Name", '42')) 122 123 def testFailOnSpaceInput(self): 124 """dObject.Name should fail when given an input with spaces""" 125 self.assertRaises(KeyError, self.setProperty, ("self.dObject.Name", '"Name With Spaces"')) 127 126 128 127 class TestParentProperty(BaseTestdObject): … … 160 159 def testSetFailOnNondPrefValue(self): 161 160 """dObject.PreferenceManager should fail when set to an object not of type dPref""" 162 def setPreferenceManager(val): 163 self.dObject.PreferenceManager = val 164 self.assertRaises(TypeError, setPreferenceManager, 42) 161 self.assertRaises(TypeError, self.setProperty, ("self.dObject.PreferenceManager", "42")) 165 162 166 163 #TODO: NEED A TEST HERE FOR INITIAL CONDITION 167 164 165 class TestGetAbsoluteName(BaseTestdObject): 166 """ 167 Test List: 168 - When Parent is set to None, dObject.getAbsoluteName = dObject.Name 169 - dObject.getAbsoluteName should correctly add Parents to the dObject Name. 170 """ 171 172 def testParentIsNone(self): 173 """When Parent is set to None, dObject.getAbsoluteName = dObject.Name""" 174 self.dObject.Name = "SomeName" 175 self.assertEqual(self.dObject.Name, self.dObject.getAbsoluteName()) 176 177 def testParentTree(self): 178 """dObject.getAbsoluteName should correctly add Parents to the dObject Name.""" 179 objectList = [] 180 for x in range(10): 181 objectList.append(dObject()) 182 objectList[x].Name = "Object%s" % (x,) 183 if x > 0: 184 objectList[x].Parent = objectList[x-1] 185 result = ".".join([object.Name for object in objectList]) 186 self.assertEqual(result, objectList[-1].getAbsoluteName()) 168 187 169 188 #used for running this module bare without the test suite
