Changeset 3048

Show
Ignore:
Timestamp:
04/10/07 14:01:57 (1 year ago)
Author:
nate
Message:

Added 27 more tests for the dTextBoxMixin coverage. Still have most of the public interface for dTextBox left to do.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/NateBranch/tests/unitTests/ui/UIwx/Test_dTextBox.py

    r3047 r3048  
    1717 
    1818import datetime 
     19import decimal 
    1920 
    2021#We want the dApp and mainForm to persist through the settings for speed sake 
     
    5354            - When dataType == datetime.date, Passing a string value in ISO 8601 format causes convertStringValueToDataType to return a datetime.date object with the correct date. 
    5455            - When dataType == datetime.date, Passing a string value not in ISO 8601 format causes convertStringValueToDataType to raise a ValueError. 
    55             - NEED TO ADD DOMAIN CHECKING TESTS!!!! 
     56            - When dataType == datetime.date, convertStringValueToDataType will raise a ValueError if not 0 <= year < 10000 
     57            - When dataType == datetime.date, convertStringValueToDataType will raise a ValueError if the year is not an integer 
     58            - When dataType == datetime.date, convertStringValueToDataType will raise a ValueError if not 0 <= month < 10000 
     59            - When dataType == datetime.date, convertStringValueToDataType will raise a ValueError if the month is not an integer 
     60            - When dataType == datetime.date, convertStringValueToDataType will raise a ValueError if the day is not in the domain of the month (i.e 0 < day < 29 for February) 
     61            - When dataType == datetime.date, convertStringValueToDataType will raise a ValueError if the day is not an integer 
    5662        For dataType == datetime.date: 
    5763            - When dataType == datetime.datetime, Passing a string value in ISO 8601 format causes convertStringValueToDataType to return a datetime.datetime object with the correct date and time. 
    5864            - When dataType == datetime.datetime, Passing a string value not in ISO 8601 format causes convertStringValueToDataType to raise a ValueError. 
    59             - NEED TO ADD DOMAIN CHECKING TESTS!!!! 
     65            - When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if not 0 <= year < 10000 
     66            - When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if the year is not an integer 
     67            - When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if not 0 <= month < 10000 
     68            - When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if the month is not an integer 
     69            - When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if the day is not in the domain of the month (i.e 0 < day < 29 for February) 
     70            - When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if the day is not an integer 
     71            - When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if not 0 <= hour < 24 
     72            - When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if the hour is not an integer 
     73            - When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if not 0 <= minute < 60 
     74            - When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if the minute is not an integer 
     75            - When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if not 0 <= second < 60 
    6076        For dataType == datetime.date: 
    6177            - When dataType == datetime.time, Passing a string value in ISO 8601 format causes convertStringValueToDataType to return a datetime.date object with the correct time. 
    6278            - When dataType == datetime.time, Passing a string value not in ISO 8601 format causes convertStringValueToDataType to raise a ValueError. 
    63             - NEED TO ADD DOMAIN CHECKING TESTS!!!! 
     79            - When dataType == datetime.time, convertStringValueToDataType will raise a ValueError if not 0 <= hour < 24 
     80            - When dataType == datetime.time, convertStringValueToDataType will raise a ValueError if the hour is not an integer 
     81            - When dataType == datetime.time, convertStringValueToDataType will raise a ValueError if not 0 <= minute < 60 
     82            - When dataType == datetime.time, convertStringValueToDataType will raise a ValueError if the minute is not an integer 
     83            - When dataType == datetime.time, convertStringValueToDataType will raise a ValueError if not 0 <= second < 60 
     84        For dataType == decimal.Decimal: 
     85            - When dataType == decimal.Decimal, passing an integer or a decimal value to covertStringValueToDataType will return a decimal.Decimal object 
     86            - When dataType == decimal.Decimal, convertStringValueToDataType will raise a ValueError if the string cannot be converted to a decimal 
     87        For when dataType == others: 
     88            - When dataType == str or unicode, convertStringValueToDataType will return a value equal to the value passed 
     89            - If the string value can be converted to a specific type, convertStringValueToDataType will return a value of type dataType 
     90            - If the string value can't be converted to a specific type, convertStringValue will throw a ValueError 
    6491    """ 
    6592     
     
    100127            self.assertRaises(ValueError, self.callfunction, (parameter, datetime.date)) 
    101128     
     129    def testBadDateYearDomain(self): 
     130        """When dataType == datetime.date, convertStringValueToDataType will raise a ValueError if not 0 <= year < 10000""" 
     131        self.assertRaises(ValueError, self.callfunction, ("-0001-04-10", datetime.date)) 
     132        self.assertRaises(ValueError, self.callfunction, ("10000-04-10", datetime.date)) 
     133     
     134    def testDateNonIntegerYearInput(self): 
     135        """When dataType == datetime.date, convertStringValueToDataType will raise a ValueError if the year is not an integer""" 
     136        self.assertRaises(ValueError, self.callfunction, ("2007.5-04-10", datetime.date)) 
     137     
     138    def testBadDateMonthDomain(self): 
     139        """When dataType == datetime.date, convertStringValueToDataType will raise a ValueError if not 0 <= month < 10000""" 
     140        self.assertRaises(ValueError, self.callfunction, ("2007-00-10", datetime.date)) 
     141        self.assertRaises(ValueError, self.callfunction, ("2007-13-10", datetime.date)) 
     142     
     143    def testDateNonIntegerMonthInput(self): 
     144        """When dataType == datetime.date, convertStringValueToDataType will raise a ValueError if the month is not an integer""" 
     145        self.assertRaises(ValueError, self.callfunction, ("2007-04.5-10", datetime.date)) 
     146     
     147    def testBadDateDayDomain(self): 
     148        """When dataType == datetime.date, convertStringValueToDataType will raise a ValueError if the day is not in the domain of the month (i.e 0 < day < 29 for February)""" 
     149        self.assertRaises(ValueError, self.callfunction, ("2007-02-29", datetime.date)) 
     150        self.assertRaises(ValueError, self.callfunction, ("2007-04-31", datetime.date)) 
     151        self.assertRaises(ValueError, self.callfunction, ("2007-12-32", datetime.date)) 
     152        self.assertRaises(ValueError, self.callfunction, ("2007-01--01", datetime.date)) 
     153     
     154    def testDateNonIntegerDayInput(self): 
     155        """When dataType == datetime.date, convertStringValueToDataType will raise a ValueError if the day is not an integer""" 
     156        self.assertRaises(ValueError, self.callfunction, ("2007-02-14.5", datetime.date)) 
     157     
    102158     
    103159    #tests for datetime.datetime dataType 
     
    116172            self.assertRaises(ValueError, self.callfunction, (parameter, datetime.datetime)) 
    117173     
     174    def testBadDatetimeYearDomain(self): 
     175        """When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if not 0 <= year < 10000""" 
     176        self.assertRaises(ValueError, self.callfunction, ("-0001-04-10", datetime.datetime)) 
     177        self.assertRaises(ValueError, self.callfunction, ("10000-04-10", datetime.datetime)) 
     178     
     179    def testDatetimeNonIntegerYearInput(self): 
     180        """When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if the year is not an integer""" 
     181        self.assertRaises(ValueError, self.callfunction, ("2007.5-04-10", datetime.datetime)) 
     182     
     183    def testBadDatetimeMonthDomain(self): 
     184        """When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if not 0 <= month < 10000""" 
     185        self.assertRaises(ValueError, self.callfunction, ("2007-00-10", datetime.datetime)) 
     186        self.assertRaises(ValueError, self.callfunction, ("2007-13-10", datetime.datetime)) 
     187     
     188    def testDatetimeNonIntegerMonthInput(self): 
     189        """When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if the month is not an integer""" 
     190        self.assertRaises(ValueError, self.callfunction, ("2007-04.5-10", datetime.datetime)) 
     191     
     192    def testBadDatetimeDayDomain(self): 
     193        """When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if the day is not in the domain of the month (i.e 0 < day < 29 for February)""" 
     194        self.assertRaises(ValueError, self.callfunction, ("2007-02-29", datetime.datetime)) 
     195        self.assertRaises(ValueError, self.callfunction, ("2007-04-31", datetime.datetime)) 
     196        self.assertRaises(ValueError, self.callfunction, ("2007-12-32", datetime.datetime)) 
     197        self.assertRaises(ValueError, self.callfunction, ("2007-01--01", datetime.datetime)) 
     198     
     199    def testDatetimeNonIntegerDayInput(self): 
     200        """When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if the day is not an integer""" 
     201        self.assertRaises(ValueError, self.callfunction, ("2007-02-14.5", datetime.datetime)) 
     202     
     203    def testBadDatetimeHourDomain(self): 
     204        """When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if not 0 <= hour < 24""" 
     205        self.assertRaises(ValueError, self.callfunction, ("2007-04-10T-01:02:03", datetime.datetime)) 
     206        self.assertRaises(ValueError, self.callfunction, ("2007-04-10T24:02:03", datetime.datetime)) 
     207     
     208    def testDatetimeNonIntegerHourInput(self): 
     209        """When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if the hour is not an integer""" 
     210        self.assertRaises(ValueError, self.callfunction, ("2007-04-10T12.3:02:03", datetime.datetime)) 
     211     
     212    def testBadDatetimeMinuteDomain(self): 
     213        """When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if not 0 <= minute < 60""" 
     214        self.assertRaises(ValueError, self.callfunction, ("2007-04-10T12:-01:30", datetime.datetime)) 
     215        self.assertRaises(ValueError, self.callfunction, ("2007-04-10T12:60:30", datetime.datetime)) 
     216     
     217    def testDatetimeNonIntegerMinuteInput(self): 
     218        """When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if the minute is not an integer""" 
     219        self.assertRaises(ValueError, self.callfunction, ("2007-04-10T12:30.5:15", datetime.datetime)) 
     220     
     221    def testBadDatetimeSecondDomain(self): 
     222        """When dataType == datetime.datetime, convertStringValueToDataType will raise a ValueError if not 0 <= second < 60""" 
     223        self.assertRaises(ValueError, self.callfunction, ("2007-04-10T08:07:-01", datetime.datetime)) 
     224        self.assertRaises(ValueError, self.callfunction, ("2007-04-10T09:08:60", datetime.datetime)) 
     225     
    118226     
    119227    #tests for datetime.time dataType 
     
    131239        for parameter in testValues: 
    132240            self.assertRaises(ValueError, self.callfunction, (parameter, datetime.time)) 
    133  
     241     
     242    def testBadTimeHourDomain(self): 
     243        """When dataType == datetime.time, convertStringValueToDataType will raise a ValueError if not 0 <= hour < 24""" 
     244        self.assertRaises(ValueError, self.callfunction, ("-01:02:03", datetime.time)) 
     245        self.assertRaises(ValueError, self.callfunction, ("24:02:03", datetime.time)) 
     246     
     247    def testTimeNonIntegerHourInput(self): 
     248        """When dataType == datetime.time, convertStringValueToDataType will raise a ValueError if the hour is not an integer""" 
     249        self.assertRaises(ValueError, self.callfunction, ("12.3:02:03", datetime.time)) 
     250     
     251    def testBadTimeMinuteDomain(self): 
     252        """When dataType == datetime.time, convertStringValueToDataType will raise a ValueError if not 0 <= minute < 60""" 
     253        self.assertRaises(ValueError, self.callfunction, ("12:-01:30", datetime.time)) 
     254        self.assertRaises(ValueError, self.callfunction, ("12:60:30", datetime.time)) 
     255     
     256    def testTimeNonIntegerMinuteInput(self): 
     257        """When dataType == datetime.time, convertStringValueToDataType will raise a ValueError if the minute is not an integer""" 
     258        self.assertRaises(ValueError, self.callfunction, ("12:30.5:15", datetime.time)) 
     259     
     260    def testBadTimeSecondDomain(self): 
     261        """When dataType == datetime.time, convertStringValueToDataType will raise a ValueError if not 0 <= second < 60""" 
     262        self.assertRaises(ValueError, self.callfunction, ("08:07:-01", datetime.time)) 
     263        self.assertRaises(ValueError, self.callfunction, ("09:08:60", datetime.time)) 
     264     
     265     
     266    #test for decimal.Decimal dataType 
     267    def testDecimalValidInput(self): 
     268        """When dataType == decimal.Decimal, passing an integer or a decimal value to covertStringValueToDataType will return a decimal.Decimal object""" 
     269        value = self.testTextBox.convertStringValueToDataType("24.5263", decimal.Decimal) 
     270        self.assertEqual(value, decimal.Decimal("24.5263")) 
     271        value = self.testTextBox.convertStringValueToDataType("42", decimal.Decimal) 
     272        self.assertEqual(value, decimal.Decimal("42")) 
     273     
     274    def testDecimalBadInput(self): 
     275        """When dataType == decimal.Decimal, convertStringValueToDataType will raise a ValueError if the string cannot be converted to a decimal""" 
     276        testValues = ["Not a number", "1,000", "1,200.154", "35,58"] 
     277        for parameter in testValues: 
     278            self.assertRaises(ValueError, self.callfunction, (parameter, decimal.Decimal)) 
     279     
     280     
     281    #test for other dataTypes 
     282    def testStringValidInput(self): 
     283        """When dataType == str or unicode, convertStringValueToDataType will return a value equal to the value passed""" 
     284        value = self.testTextBox.convertStringValueToDataType("string", str) 
     285        self.assertEqual(value, "string") 
     286        value = self.testTextBox.convertStringValueToDataType("string", unicode) 
     287        self.assertEqual(value, "string") 
     288     
     289    def testOtherTypeValidInput(self): 
     290        """If the string value can be converted to a specific type, convertStringValueToDataType will return a value of type dataType""" 
     291        value = self.testTextBox.convertStringValueToDataType("123", list) 
     292        self.assertEqual(value, ['1', '2', '3']) 
     293        value = self.testTextBox.convertStringValueToDataType("1234567", int) 
     294        self.assertEqual(value, 1234567) 
     295     
     296    def testOtherTypeBadInput(self): 
     297        """If the string value can't be converted to a specific type, convertStringValue will throw a ValueError""" 
     298        self.assertRaises(ValueError, self.callfunction, ("not a int", int)) 
     299        self.assertRaises(ValueError, self.callfunction, ("[1, 2, 3]", dict)) 
    134300 
    135301