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