Merge "Test OpenStack vGPU feature"
[functest.git] / functest / tests / unit / utils / test_env.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2018 Orange and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # pylint: disable=missing-docstring
11
12 import logging
13 import os
14 import unittest
15
16 from six.moves import reload_module
17
18 from functest.utils import env
19
20
21 class EnvTesting(unittest.TestCase):
22     # pylint: disable=missing-docstring
23
24     def setUp(self):
25         os.environ['FOO'] = 'foo'
26         os.environ['BUILD_TAG'] = 'master'
27         os.environ['CI_LOOP'] = 'weekly'
28
29     def test_get_unset_unknown_env(self):
30         del os.environ['FOO']
31         self.assertEqual(env.get('FOO'), None)
32
33     def test_get_unknown_env(self):
34         self.assertEqual(env.get('FOO'), 'foo')
35         reload_module(env)
36
37     def test_get_unset_env(self):
38         del os.environ['CI_LOOP']
39         self.assertEqual(
40             env.get('CI_LOOP'), env.INPUTS['CI_LOOP'])
41
42     def test_get_env(self):
43         self.assertEqual(
44             env.get('CI_LOOP'), 'weekly')
45
46     def test_get_unset_env2(self):
47         del os.environ['BUILD_TAG']
48         self.assertEqual(
49             env.get('BUILD_TAG'), env.INPUTS['BUILD_TAG'])
50
51     def test_get_env2(self):
52         self.assertEqual(env.get('BUILD_TAG'), 'master')
53
54
55 if __name__ == "__main__":
56     logging.disable(logging.CRITICAL)
57     unittest.main(verbosity=2)