4 # Copyright 2016 RIFT.IO Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
31 from rift
.mano
.config_data
import config
34 gi
.require_version('VnfdYang', '1.0')
35 gi
.require_version('RwYang', '1.0')
37 from gi
.repository
import (
42 class InitialPrimitiveReaderTest(unittest
.TestCase
):
43 def test_read_valid_config(self
):
50 # Hard to compare with multiple elements because ordering of list
51 # element is not deterministic.
56 # No, parameters (use default values)
60 with io
.StringIO() as yaml_hdl
:
61 yaml_hdl
.write(yaml
.safe_dump(input_prim_data
))
63 reader
= config
.VnfInitialConfigPrimitiveReader
.from_yaml_file_hdl(yaml_hdl
)
65 expected_primitives
= [
66 VnfdYang
.InitialConfigPrimitive
.from_dict({
67 "name": "prim_1", "seq": 0, "parameter": [
74 VnfdYang
.InitialConfigPrimitive
.from_dict({
75 "name": "prim_2", "seq": 1
79 for i
, prim
in enumerate(reader
.primitives
):
80 logging
.debug("Expected: %s", str(expected_primitives
[i
]))
81 logging
.debug("Got: %s", str(prim
))
82 self
.assertEqual(expected_primitives
[i
], prim
)
85 def main(argv
=sys
.argv
[1:]):
86 logging
.basicConfig(format
='TEST %(message)s')
88 runner
= xmlrunner
.XMLTestRunner(output
=os
.environ
["RIFT_MODULE_TEST"])
89 parser
= argparse
.ArgumentParser()
90 parser
.add_argument('-v', '--verbose', action
='store_true')
91 parser
.add_argument('-n', '--no-runner', action
='store_true')
93 args
, unknown
= parser
.parse_known_args(argv
)
97 # Set the global logging level
98 logging
.getLogger().setLevel(logging
.DEBUG
if args
.verbose
else logging
.ERROR
)
100 # The unittest framework requires a program name, so use the name of this
101 # file instead (we do not want to have to pass a fake program name to main
102 # when this is called from the interpreter).
103 unittest
.main(argv
=[__file__
] + unknown
+ ["-v"], testRunner
=runner
)
105 if __name__
== '__main__':