blob: e6de65c3b9bcb193b49302d1df90ca9d2aafbb87 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2# Copyright 2017-present Open Networking Foundation
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
Matteo Scandolo67654fa2017-06-09 09:33:17 -070017import unittest
18import os
19from mock import patch
20from xosgenx.xosgen import XosGen
21
22class Args:
23 pass
24
25class XOSGeneratorTest(unittest.TestCase):
26 """
27 Testing the CLI binding for the XOS Generative Toolchain
28 """
29
Scott Baker55e146a2017-11-01 13:52:24 -070030 def setUp(self):
31 os.chdir(os.path.join(os.path.abspath(os.path.dirname(os.path.realpath(__file__))), ".."))
32
Matteo Scandolo67654fa2017-06-09 09:33:17 -070033 def test_generator(self):
34 """
35 [XOS-GenX] The CLI entry point should correctly parse params
36 """
37 args = Args()
Scott Baker55e146a2017-11-01 13:52:24 -070038 args.files = ['xos-genx-tests/xproto/test.xproto']
39 args.target = 'xos-genx-tests/xtarget/test.xtarget'
40 args.output = 'xos-genx-tests/out/dir/'
Matteo Scandolo67654fa2017-06-09 09:33:17 -070041 args.write_to_file = "target"
42 args.dest_file = None
43 args.dest_extension = None
44
45 expected_args = Args()
46 expected_args.files = [os.path.abspath(os.getcwd() + '/' + args.files[0])]
47 expected_args.target = os.path.abspath(os.getcwd() + '/' + args.target)
48 expected_args.output = os.path.abspath(os.getcwd() + '/' + args.output)
49
50 with patch("xosgenx.xosgen.XOSGenerator.generate") as generator:
51 XosGen.init(args)
52 actual_args = generator.call_args[0][0]
53 self.assertEqual(actual_args.files, expected_args.files)
54 self.assertEqual(actual_args.target, expected_args.target)
55 self.assertEqual(actual_args.output, expected_args.output)
56
57if __name__ == '__main__':
Sapan Bhatia5ea307d2017-07-19 00:13:21 -040058 unittest.main()