Changeset 2884

Show
Ignore:
Timestamp:
03/06/07 17:06:28 (2 years ago)
Author:
nate
Message:

Added more unit tests to dObject. Added another test to dColors when I discovered I was missing code coverage (thank you coverage.py). Figured out how to exclude the if name... clauses. Still need to think of what to test with the randomColor function... Anyway, the numbers for code coverage are improving.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/dObject.py

    r2879 r2884  
    231231 
    232232    def _getClass(self): 
    233         try: 
    234             return self.__class__ 
    235         except AttributeError: 
    236             return None 
     233        return self.__class__ 
    237234 
    238235 
     
    269266            return "?" 
    270267     
    271     def _setName(self, value): 
    272         self._name = str(value) 
     268    def _setName(self, val): 
     269        if not isinstance(val, types.StringTypes): 
     270            raise TypeError, 'Name must be a string.' 
     271        self._name = val 
    273272         
    274273         
     
    295294 
    296295    def _setPreferenceManager(self, val): 
     296        if not isinstance(val, dPref): 
     297            raise TypeError, 'PreferenceManager must be a dPref object' 
    297298        self._preferenceManager = val 
    298299 
  • trunk/tests/unitTests/Test_dColors.py

    r2870 r2884  
    129129        """tupleToHex should fail with more than 3 elements in the tuple""" 
    130130        self.assertRaises(dColors.LengthError, dColors.tupleToHex, (1,1,1,1)) 
     131     
     132    def testTupleToHexNonIntegerInput(self): 
     133        """tupleToHex should fail if anyone of the elements is a non-integer""" 
     134        self.assertRaises(dColors.IntegerTypeError, dColors.tupleToHex, ("string", 1, 1)) 
     135        self.assertRaises(dColors.IntegerTypeError, dColors.tupleToHex, (1, "string", 1)) 
     136        self.assertRaises(dColors.IntegerTypeError, dColors.tupleToHex, (1, 1, "string")) 
    131137     
    132138    def testHexToTupleBadHexInput(self): 
     
    249255 
    250256 
     257 
    251258#used for running this module bare without the test suite 
    252259if __name__ == "__main__": 
  • trunk/tests/unitTests/Test_dObject.py

    r2879 r2884  
    103103        self.assertEqual(a, obj.Class) 
    104104 
     105class TestNameProperty(BaseTestdObject): 
     106    """ 
     107    Test List: 
     108        - Set dObject.Name to n.  dObject.Name should be equal to n. (round trip test) 
     109        - dObject.Name should return '?' if no name is assigned 
     110        - dObject.Name should fail when given a non-string input 
     111    """ 
     112     
     113    def testRoundTrip(self): 
     114        """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) 
     117     
     118    def testNoNameSet(self): 
     119        """dObject.Name should return '?' if no name is assigned""" 
     120        self.assertEqual('?', self.dObject.Name) 
     121     
     122    def testFailOnNonStringInput(self): 
     123        """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) 
     127 
     128class TestParentProperty(BaseTestdObject): 
     129    """ 
     130    Test List: 
     131        - Set dObject.Parent to n. dObject.Parent should be equal to n. (round trip test) 
     132        - dObject.Parent should return None if there is no parent 
     133    """ 
     134     
     135    def testRoundTrip(self): 
     136        """Set dObject.Parent to n. dObject.Parent should be equal to n. (round trip test)""" 
     137        test = dObject() 
     138        test.Parent = self.dObject 
     139        self.assertEqual(test.Parent, self.dObject) 
     140     
     141    def testNoParentSet(self): 
     142        """dObject.Parent should return None if there is no parent""" 
     143        self.assertEqual(self.dObject.Parent, None) 
     144 
     145class TestPreferenceManagerProperty(BaseTestdObject): 
     146    """ 
     147    Test List: 
     148        - Set dObject.PreferenceManager to n. dObject.PreferenceManagier should be equal to n. (round trip test) 
     149        - dObject.PreferenceManager should fail when set to an object not of type dPref 
     150        - initial conditon test??? 
     151    """ 
     152     
     153    def testRoundTrip(self): 
     154        """Set dObject.PreferenceManager to n. dObject.PreferenceManagier should be equal to n. (round trip test)""" 
     155        from dabo.dPref import dPref 
     156        testDPref = dPref() 
     157        self.dObject.PreferenceManager = testDPref 
     158        self.assertEqual(testDPref, self.dObject.PreferenceManager) 
     159     
     160    def testSetFailOnNondPrefValue(self): 
     161        """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) 
     165     
     166    #TODO: NEED A TEST HERE FOR INITIAL CONDITION 
     167 
     168class TestSuperClassProperty(BaseTestdObject): 
     169    """ 
     170    Test List: 
     171        - Set dObject.SuperClass should fail with any input 
     172        - a.SuperClass should return class Dummy when a = dObject() 
     173        - a.SuperClass should return class dObject when a = someObject and someObject subclasses dObject 
     174    """ 
     175     
     176    def testSetAlwaysFails(self): 
     177        """Set dObject.SuperClass should fail with any input""" 
     178        def setSuperClass(val): 
     179            self.dObject.SuperClass = val 
     180        self.assertRaises(AttributeError, setSuperClass, 42) 
     181        self.assertRaises(AttributeError, setSuperClass, "string") 
     182        self.assertRaises(AttributeError, setSuperClass, ("tuple", 12, 23)) 
     183        self.assertRaises(AttributeError, setSuperClass, dObject) 
     184        self.assertRaises(AttributeError, setSuperClass, Dummy) 
     185     
     186    def testGetNoSubclass(self): 
     187        """a.SuperClass should return class Dummy when a = dObject()""" 
     188        self.assertEqual(Dummy, self.dObject.SuperClass) 
     189     
     190    def testGetWithSubclass(self): 
     191        """a.SuperClass should return class dObject when a = someObject and someObject subclasses dObject""" 
     192        class someObject(dObject): 
     193            pass 
     194        a = someObject() 
     195        self.assertEqual(dObject, a.SuperClass) 
     196 
    105197 
    106198#used for running this module bare without the test suite 
  • trunk/tests/unitTests/masterTestSuite.py

    r2882 r2884  
    1313coverage.erase() 
    1414coverage.start() 
     15 
     16coverage.exclude('if __name__ == "__main__":') 
    1517 
    1618import dabo 
     
    3335 
    3436coverage.stop() 
    35 coverage.report([dabo.dColors, dabo.dObject]) 
     37coverage.report([dabo.dColors, dabo.dObject, dabo])