1ed69676d435b7b6983271ed8fab200627a0b966eGeorge Burgess IV#!/usr/bin/env python2 22fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice# 32fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice# Copyright 2014 Google Inc. All Rights Reserved. 4eddb06396dc17fcec418c3aadc234f737b63c876Caroline Tice"""Unit tests for config.py""" 5eddb06396dc17fcec418c3aadc234f737b63c876Caroline Tice 6eddb06396dc17fcec418c3aadc234f737b63c876Caroline Ticefrom __future__ import print_function 72fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice 82fca8ce27632ebce63627b5a51e9749e68bcf8b9cmticeimport config 92fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice 102fca8ce27632ebce63627b5a51e9749e68bcf8b9cmticeimport unittest 112fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice 12f2a3ef46f75d2196a93d3ed27f4d1fcf22b54fbeLuis Lozano 132fca8ce27632ebce63627b5a51e9749e68bcf8b9cmticeclass ConfigTestCase(unittest.TestCase): 14eddb06396dc17fcec418c3aadc234f737b63c876Caroline Tice """Class for the config unit tests.""" 152fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice 162fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice def test_config(self): 172fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice # Verify that config exists, that it's a dictionary, and that it's 182fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice # empty. 192fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice self.assertTrue(type(config.config) is dict) 202fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice self.assertEqual(len(config.config), 0) 212fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice 222fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice # Verify that attempting to get a non-existant key out of the 232fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice # dictionary returns None. 242fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice self.assertIsNone(config.GetConfig('rabbit')) 252fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice self.assertIsNone(config.GetConfig('key1')) 262fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice 272fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice config.AddConfig('key1', 16) 282fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice config.AddConfig('key2', 32) 292fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice config.AddConfig('key3', 'third value') 302fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice 312fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice # Verify that after 3 calls to AddConfig we have 3 values in the 322fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice # dictionary. 332fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice self.assertEqual(len(config.config), 3) 342fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice 352fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice # Verify that GetConfig works and gets the expected values. 362fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice self.assertIs(config.GetConfig('key2'), 32) 372fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice self.assertIs(config.GetConfig('key3'), 'third value') 382fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice self.assertIs(config.GetConfig('key1'), 16) 392fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice 402fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice # Re-set config. 412fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice config.config.clear() 422fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice 432fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice # Verify that config exists, that it's a dictionary, and that it's 442fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice # empty. 452fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice self.assertTrue(type(config.config) is dict) 462fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice self.assertEqual(len(config.config), 0) 472fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice 482fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice 492fca8ce27632ebce63627b5a51e9749e68bcf8b9cmticeif __name__ == '__main__': 502fca8ce27632ebce63627b5a51e9749e68bcf8b9cmtice unittest.main() 51