blob: 087c904b926b4e83187d9a722de5e235cd4b24dd [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15
Zack Williams9a42f872019-02-15 17:56:04 -070016from __future__ import absolute_import
Matteo Scandolo67654fa2017-06-09 09:33:17 -070017import unittest
18import os
19from mock import patch
20from xosgenx.xosgen import XosGen
21
Zack Williams045b63d2019-01-22 16:30:57 -070022
Matteo Scandolo67654fa2017-06-09 09:33:17 -070023class Args:
24 pass
25
Zack Williams045b63d2019-01-22 16:30:57 -070026
Sapan Bhatiabfb233a2018-02-09 14:53:09 -080027class XOSProcessorTest(unittest.TestCase):
Matteo Scandolo67654fa2017-06-09 09:33:17 -070028 """
29 Testing the CLI binding for the XOS Generative Toolchain
30 """
31
Scott Baker55e146a2017-11-01 13:52:24 -070032 def setUp(self):
Zack Williams045b63d2019-01-22 16:30:57 -070033 os.chdir(
34 os.path.join(
35 os.path.abspath(os.path.dirname(os.path.realpath(__file__))), ".."
36 )
37 )
Scott Baker55e146a2017-11-01 13:52:24 -070038
Matteo Scandolo67654fa2017-06-09 09:33:17 -070039 def test_generator(self):
40 """
41 [XOS-GenX] The CLI entry point should correctly parse params
42 """
43 args = Args()
Zack Williams045b63d2019-01-22 16:30:57 -070044 args.files = ["xos-genx-tests/xproto/test.xproto"]
45 args.target = "xos-genx-tests/xtarget/test.xtarget"
46 args.output = "xos-genx-tests/out/dir/"
Matteo Scandolo67654fa2017-06-09 09:33:17 -070047 args.write_to_file = "target"
48 args.dest_file = None
49 args.dest_extension = None
50
51 expected_args = Args()
Zack Williams045b63d2019-01-22 16:30:57 -070052 expected_args.files = [os.path.abspath(os.getcwd() + "/" + args.files[0])]
53 expected_args.target = os.path.abspath(os.getcwd() + "/" + args.target)
54 expected_args.output = os.path.abspath(os.getcwd() + "/" + args.output)
Matteo Scandolo67654fa2017-06-09 09:33:17 -070055
Sapan Bhatiabfb233a2018-02-09 14:53:09 -080056 with patch("xosgenx.xosgen.XOSProcessor.process") as generator:
Matteo Scandolo67654fa2017-06-09 09:33:17 -070057 XosGen.init(args)
58 actual_args = generator.call_args[0][0]
59 self.assertEqual(actual_args.files, expected_args.files)
Matteo Scandolo67654fa2017-06-09 09:33:17 -070060 self.assertEqual(actual_args.output, expected_args.output)
61
Zack Williams045b63d2019-01-22 16:30:57 -070062
63if __name__ == "__main__":
Sapan Bhatia5ea307d2017-07-19 00:13:21 -040064 unittest.main()