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