SHARE
TWEET

Untitled

a guest Aug 13th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### December 2010 ###
  2.  
  3. ### Question 2 ###
  4.  
  5. import unittest
  6. from list_to_lower import list_to_lower, BadTypeException
  7.  
  8. class TestListToLower(unittest.TestCase):
  9.    
  10.     def setUp(self):
  11.         ''' Set up an empty list. '''
  12.  
  13.         self.my_list = []
  14.        
  15.     def tearDown(self):
  16.         ''' Clean up.'''
  17.  
  18.         self.my_list = None
  19.    
  20.     def testListToLowerEmptyList(self):
  21.         ''' Test list_to_lower on an empty list. '''
  22.        
  23.         assert list_to_lower(self.my_list) == []
  24.        
  25.     def testListToLowerTypicalList(self):
  26.         ''' Test list_to_lower on a typical list of strings with mixed cases. '''
  27.        
  28.         self.my_list = ['Ab', 'aB', 'aabBb']
  29.         assert list_to_lower(self.my_list) == ['ab', 'ab', 'aabbb']
  30.        
  31.     def testListToLowerBadTypes(self):
  32.         ''' Test list_to_lower on a list that contains bad types (i.e. an int).
  33.         '''
  34.        
  35.         self.my_list = ['a', 3]
  36.         try:
  37.             list_to_lower(self.my_list)
  38.         except BadTypeException, error:
  39.             assert error.message == 'Non-string object found.'
  40.         except:
  41.             assert False
  42.                
  43. if __name__ == '__main__':
  44.    
  45.     suite = unittest.TestLoader().loadTestsFromTestCase(TestListToLower)
  46.     unittest.TextTestRunner(verbosity=2).run(suite)
RAW Paste Data
Top