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 | |
Scott Baker | 55e146a | 2017-11-01 13:52:24 -0700 | [diff] [blame^] | 30 | def setUp(self): |
| 31 | os.chdir(os.path.join(os.path.abspath(os.path.dirname(os.path.realpath(__file__))), "..")) |
| 32 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 33 | def test_generator(self): |
| 34 | """ |
| 35 | [XOS-GenX] The CLI entry point should correctly parse params |
| 36 | """ |
| 37 | args = Args() |
Scott Baker | 55e146a | 2017-11-01 13:52:24 -0700 | [diff] [blame^] | 38 | args.files = ['xos-genx-tests/xproto/test.xproto'] |
| 39 | args.target = 'xos-genx-tests/xtarget/test.xtarget' |
| 40 | args.output = 'xos-genx-tests/out/dir/' |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 41 | args.write_to_file = "target" |
| 42 | args.dest_file = None |
| 43 | args.dest_extension = None |
| 44 | |
| 45 | expected_args = Args() |
| 46 | expected_args.files = [os.path.abspath(os.getcwd() + '/' + args.files[0])] |
| 47 | expected_args.target = os.path.abspath(os.getcwd() + '/' + args.target) |
| 48 | expected_args.output = os.path.abspath(os.getcwd() + '/' + args.output) |
| 49 | |
| 50 | with patch("xosgenx.xosgen.XOSGenerator.generate") as generator: |
| 51 | XosGen.init(args) |
| 52 | actual_args = generator.call_args[0][0] |
| 53 | self.assertEqual(actual_args.files, expected_args.files) |
| 54 | self.assertEqual(actual_args.target, expected_args.target) |
| 55 | self.assertEqual(actual_args.output, expected_args.output) |
| 56 | |
| 57 | if __name__ == '__main__': |
Sapan Bhatia | 5ea307d | 2017-07-19 00:13:21 -0400 | [diff] [blame] | 58 | unittest.main() |