Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 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 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 | |
| 22 | class Args: |
| 23 | pass |
| 24 | |
| 25 | class XOSGeneratorTest(unittest.TestCase): |
| 26 | """ |
| 27 | Testing the CLI binding for the XOS Generative Toolchain |
| 28 | """ |
| 29 | |
| 30 | def test_generator(self): |
| 31 | """ |
| 32 | [XOS-GenX] The CLI entry point should correctly parse params |
| 33 | """ |
| 34 | args = Args() |
| 35 | args.files = ['tests/xproto/test.xproto'] |
| 36 | args.target = 'tests/xtarget/test.xtarget' |
| 37 | args.output = 'tests/out/dir/' |
| 38 | args.write_to_file = "target" |
| 39 | args.dest_file = None |
| 40 | args.dest_extension = None |
| 41 | |
| 42 | expected_args = Args() |
| 43 | expected_args.files = [os.path.abspath(os.getcwd() + '/' + args.files[0])] |
| 44 | expected_args.target = os.path.abspath(os.getcwd() + '/' + args.target) |
| 45 | expected_args.output = os.path.abspath(os.getcwd() + '/' + args.output) |
| 46 | |
| 47 | with patch("xosgenx.xosgen.XOSGenerator.generate") as generator: |
| 48 | XosGen.init(args) |
| 49 | actual_args = generator.call_args[0][0] |
| 50 | self.assertEqual(actual_args.files, expected_args.files) |
| 51 | self.assertEqual(actual_args.target, expected_args.target) |
| 52 | self.assertEqual(actual_args.output, expected_args.output) |
| 53 | |
| 54 | if __name__ == '__main__': |
Sapan Bhatia | 5ea307d | 2017-07-19 00:13:21 -0400 | [diff] [blame] | 55 | unittest.main() |