Adding an autostart in Docker
[optf/osdf.git] / test / osdf / utils / test_programming_utils.py
1 # -------------------------------------------------------------------------
2 #   Copyright (c) 2018 AT&T Intellectual Property
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #   Unless required by applicable law or agreed to in writing, software
11 #   distributed under the License is distributed on an "AS IS" BASIS,
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #   limitations under the License.
15 #
16 # -------------------------------------------------------------------------
17 #
18 import unittest
19
20 from osdf.utils import programming_utils as putil
21
22
23 class TestProgrammingUtils(unittest.TestCase):
24
25     def test_namedtuple_with_defaults_list(self):
26         MyType1 = putil.namedtuple_with_defaults('MyType1', 'afield bfield', ['a', 'b'])
27         res = MyType1()
28         assert res.afield == 'a'
29
30     def test_namedtuple_with_defaults_dict(self):
31         MyType2 = putil.namedtuple_with_defaults('MyType2', 'afield bfield', {'afield': 'x', 'bfield': 'y'})
32         res = MyType2()
33         assert res.afield == 'x'
34         res = MyType2('blah')
35         assert res.afield == 'blah'
36         res = MyType2('a', 'bar')
37         assert res.bfield == 'bar'
38
39     def test_inverted_dict(self):
40         orig = {'x': 'a', 'y': 'b', 'z': 'a'}
41         res = putil.inverted_dict(['x', 'y', 'z'], orig)
42         assert set(res['a']) == {'x', 'z'} and res['b'] == ['y']
43
44
45 if __name__ == "__main__":
46     unittest.main()