2 Copyright (c) 2018-2019 Intel Corporation
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
18 from unittest.mock import patch
20 from mo.front.mxnet.loader import load_symbol_nodes, parse_input_model
23 class MockSymbolLoadObj():
28 class TestLoader(unittest.TestCase):
31 @patch('os.path.isfile')
32 @patch('mxnet.symbol.load')
33 def test_load_symbol_nodes(self, mock_symbol_load, mock_isfile, mock_json_loads, mock_json_load):
34 mock_isfile.return_value = True
35 mock_json_load.return_value = {'nodes': ''}
36 mock_json_loads.return_value = {'nodes': {'node1': 1}}
37 mock_symbol_load_obj = MockSymbolLoadObj()
38 mock_symbol_load.return_value = mock_symbol_load_obj
39 with patch('mo.front.mxnet.loader.open') as mock_open:
40 self.assertEqual({'node1': 1}, load_symbol_nodes("model_name", True))
44 @patch('os.path.isfile')
45 @patch('mxnet.symbol.load')
46 def test_load_symbol_with_custom_nodes(self, mock_symbol_load, mock_isfile, mock_json_loads, mock_json_load):
47 mock_isfile.return_value = True
48 mock_json_load.return_value = {'nodes': [{'op': 'custom_op'}, {'op': 'custom_op'}]}
49 mock_json_loads.return_value = {'nodes': {'node1': 1}}
50 mock_symbol_load_obj = MockSymbolLoadObj()
51 mock_symbol_load.return_value = mock_symbol_load_obj
52 with patch('mo.front.mxnet.loader.open') as mock_open:
53 list_nodes = load_symbol_nodes("model_name", False)
54 self.assertEqual(2, len(list_nodes))
55 for node in list_nodes:
56 self.assertEqual({'op': 'custom_op'}, node)
58 def test_parse_input_model(self):
59 input_model = '/model-optimizer-mxnet/data/nd/vgg19-0015.params'
60 model_name, iteration_number = parse_input_model(input_model)
61 self.assertEqual(model_name, '/model-optimizer-mxnet/data/nd/vgg19')
62 self.assertEqual(iteration_number, 15)