1 # -------------------------------------------------------------------------
2 # Copyright (c) 2018 AT&T Intellectual Property
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # -------------------------------------------------------------------------
20 from osdf.utils import programming_utils as putil
23 class TestProgrammingUtils(unittest.TestCase):
25 def test_namedtuple_with_defaults_list(self):
26 MyType1 = putil.namedtuple_with_defaults('MyType1', 'afield bfield', ['a', 'b'])
28 assert res.afield == 'a'
30 def test_namedtuple_with_defaults_dict(self):
31 MyType2 = putil.namedtuple_with_defaults('MyType2', 'afield bfield', {'afield': 'x', 'bfield': 'y'})
33 assert res.afield == 'x'
35 assert res.afield == 'blah'
36 res = MyType2('a', 'bar')
37 assert res.bfield == 'bar'
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']
45 if __name__ == "__main__":