blob: 3f948653d8d15f9bacc83bfbde7b124cc42468af [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
Matteo Scandolo67654fa2017-06-09 09:33:17 -070016import unittest
17import os
18from mock import patch
19from xosgenx.xosgen import XosGen
20
Zack Williams045b63d2019-01-22 16:30:57 -070021
Matteo Scandolo67654fa2017-06-09 09:33:17 -070022class Args:
23 pass
24
Zack Williams045b63d2019-01-22 16:30:57 -070025
Sapan Bhatiabfb233a2018-02-09 14:53:09 -080026class XOSProcessorTest(unittest.TestCase):
Matteo Scandolo67654fa2017-06-09 09:33:17 -070027 """
28 Testing the CLI binding for the XOS Generative Toolchain
29 """
30
Scott Baker55e146a2017-11-01 13:52:24 -070031 def setUp(self):
Zack Williams045b63d2019-01-22 16:30:57 -070032 os.chdir(
33 os.path.join(
34 os.path.abspath(os.path.dirname(os.path.realpath(__file__))), ".."
35 )
36 )
Scott Baker55e146a2017-11-01 13:52:24 -070037
Matteo Scandolo67654fa2017-06-09 09:33:17 -070038 def test_generator(self):
39 """
40 [XOS-GenX] The CLI entry point should correctly parse params
41 """
42 args = Args()
Zack Williams045b63d2019-01-22 16:30:57 -070043 args.files = ["xos-genx-tests/xproto/test.xproto"]
44 args.target = "xos-genx-tests/xtarget/test.xtarget"
45 args.output = "xos-genx-tests/out/dir/"
Matteo Scandolo67654fa2017-06-09 09:33:17 -070046 args.write_to_file = "target"
47 args.dest_file = None
48 args.dest_extension = None
49
50 expected_args = Args()
Zack Williams045b63d2019-01-22 16:30:57 -070051 expected_args.files = [os.path.abspath(os.getcwd() + "/" + args.files[0])]
52 expected_args.target = os.path.abspath(os.getcwd() + "/" + args.target)
53 expected_args.output = os.path.abspath(os.getcwd() + "/" + args.output)
Matteo Scandolo67654fa2017-06-09 09:33:17 -070054
Sapan Bhatiabfb233a2018-02-09 14:53:09 -080055 with patch("xosgenx.xosgen.XOSProcessor.process") as generator:
Matteo Scandolo67654fa2017-06-09 09:33:17 -070056 XosGen.init(args)
57 actual_args = generator.call_args[0][0]
58 self.assertEqual(actual_args.files, expected_args.files)
Matteo Scandolo67654fa2017-06-09 09:33:17 -070059 self.assertEqual(actual_args.output, expected_args.output)
60
Zack Williams045b63d2019-01-22 16:30:57 -070061
62if __name__ == "__main__":
Sapan Bhatia5ea307d2017-07-19 00:13:21 -040063 unittest.main()