Home | History | Annotate | Download | only in crosperf
      1 #!/usr/bin/env python2
      2 #
      3 # Copyright 2014 Google Inc. All Rights Reserved.
      4 """Unit tests for config.py"""
      5 
      6 from __future__ import print_function
      7 
      8 import config
      9 
     10 import unittest
     11 
     12 
     13 class ConfigTestCase(unittest.TestCase):
     14   """Class for the config unit tests."""
     15 
     16   def test_config(self):
     17     # Verify that config exists, that it's a dictionary, and that it's
     18     # empty.
     19     self.assertTrue(type(config.config) is dict)
     20     self.assertEqual(len(config.config), 0)
     21 
     22     # Verify that attempting to get a non-existant key out of the
     23     # dictionary returns None.
     24     self.assertIsNone(config.GetConfig('rabbit'))
     25     self.assertIsNone(config.GetConfig('key1'))
     26 
     27     config.AddConfig('key1', 16)
     28     config.AddConfig('key2', 32)
     29     config.AddConfig('key3', 'third value')
     30 
     31     # Verify that after 3 calls to AddConfig we have 3 values in the
     32     # dictionary.
     33     self.assertEqual(len(config.config), 3)
     34 
     35     # Verify that GetConfig works and gets the expected values.
     36     self.assertIs(config.GetConfig('key2'), 32)
     37     self.assertIs(config.GetConfig('key3'), 'third value')
     38     self.assertIs(config.GetConfig('key1'), 16)
     39 
     40     # Re-set config.
     41     config.config.clear()
     42 
     43     # Verify that config exists, that it's a dictionary, and that it's
     44     # empty.
     45     self.assertTrue(type(config.config) is dict)
     46     self.assertEqual(len(config.config), 0)
     47 
     48 
     49 if __name__ == '__main__':
     50   unittest.main()
     51