1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright 2014 The ChromiumOS Authors 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7"""Unit tests for config.py""" 8 9 10import unittest 11 12import config 13 14 15class ConfigTestCase(unittest.TestCase): 16 """Class for the config unit tests.""" 17 18 def test_config(self): 19 # Verify that config exists, that it's a dictionary, and that it's 20 # empty. 21 self.assertTrue(isinstance(config.config, dict)) 22 self.assertEqual(len(config.config), 0) 23 24 # Verify that attempting to get a non-existant key out of the 25 # dictionary returns None. 26 self.assertIsNone(config.GetConfig("rabbit")) 27 self.assertIsNone(config.GetConfig("key1")) 28 29 config.AddConfig("key1", 16) 30 config.AddConfig("key2", 32) 31 config.AddConfig("key3", "third value") 32 33 # Verify that after 3 calls to AddConfig we have 3 values in the 34 # dictionary. 35 self.assertEqual(len(config.config), 3) 36 37 # Verify that GetConfig works and gets the expected values. 38 self.assertIs(config.GetConfig("key2"), 32) 39 self.assertIs(config.GetConfig("key3"), "third value") 40 self.assertIs(config.GetConfig("key1"), 16) 41 42 # Re-set config. 43 config.config.clear() 44 45 # Verify that config exists, that it's a dictionary, and that it's 46 # empty. 47 self.assertTrue(isinstance(config.config, dict)) 48 self.assertEqual(len(config.config), 0) 49 50 51if __name__ == "__main__": 52 unittest.main() 53