Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | # 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 Williams | 9a42f87 | 2019-02-15 17:56:04 -0700 | [diff] [blame^] | 16 | from __future__ import absolute_import |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 17 | import unittest |
| 18 | import os |
| 19 | from mock import patch |
| 20 | from xosgenx.xosgen import XosGen |
| 21 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 22 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 23 | class Args: |
| 24 | pass |
| 25 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 26 | |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 27 | class XOSProcessorTest(unittest.TestCase): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 28 | """ |
| 29 | Testing the CLI binding for the XOS Generative Toolchain |
| 30 | """ |
| 31 | |
Scott Baker | 55e146a | 2017-11-01 13:52:24 -0700 | [diff] [blame] | 32 | def setUp(self): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 33 | os.chdir( |
| 34 | os.path.join( |
| 35 | os.path.abspath(os.path.dirname(os.path.realpath(__file__))), ".." |
| 36 | ) |
| 37 | ) |
Scott Baker | 55e146a | 2017-11-01 13:52:24 -0700 | [diff] [blame] | 38 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 39 | def test_generator(self): |
| 40 | """ |
| 41 | [XOS-GenX] The CLI entry point should correctly parse params |
| 42 | """ |
| 43 | args = Args() |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 44 | 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 47 | args.write_to_file = "target" |
| 48 | args.dest_file = None |
| 49 | args.dest_extension = None |
| 50 | |
| 51 | expected_args = Args() |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 52 | 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 55 | |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 56 | with patch("xosgenx.xosgen.XOSProcessor.process") as generator: |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 57 | XosGen.init(args) |
| 58 | actual_args = generator.call_args[0][0] |
| 59 | self.assertEqual(actual_args.files, expected_args.files) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 60 | self.assertEqual(actual_args.output, expected_args.output) |
| 61 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 62 | |
| 63 | if __name__ == "__main__": |
Sapan Bhatia | 5ea307d | 2017-07-19 00:13:21 -0400 | [diff] [blame] | 64 | unittest.main() |