aboutsummaryrefslogtreecommitdiff
path: root/crosperf/config_unittest.py
blob: 208f44dc4f11334c2af369a40b69e827edf4977d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Unit tests for config.py"""

from __future__ import print_function

import unittest

import config


class ConfigTestCase(unittest.TestCase):
  """Class for the config unit tests."""

  def test_config(self):
    # Verify that config exists, that it's a dictionary, and that it's
    # empty.
    self.assertTrue(isinstance(config.config, dict))
    self.assertEqual(len(config.config), 0)

    # Verify that attempting to get a non-existant key out of the
    # dictionary returns None.
    self.assertIsNone(config.GetConfig('rabbit'))
    self.assertIsNone(config.GetConfig('key1'))

    config.AddConfig('key1', 16)
    config.AddConfig('key2', 32)
    config.AddConfig('key3', 'third value')

    # Verify that after 3 calls to AddConfig we have 3 values in the
    # dictionary.
    self.assertEqual(len(config.config), 3)

    # Verify that GetConfig works and gets the expected values.
    self.assertIs(config.GetConfig('key2'), 32)
    self.assertIs(config.GetConfig('key3'), 'third value')
    self.assertIs(config.GetConfig('key1'), 16)

    # Re-set config.
    config.config.clear()

    # Verify that config exists, that it's a dictionary, and that it's
    # empty.
    self.assertTrue(isinstance(config.config, dict))
    self.assertEqual(len(config.config), 0)


if __name__ == '__main__':
  unittest.main()