2 Copyright (c) 2018 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 MagicMock
19 from xml.etree.ElementTree import Element, tostring
23 from mo.back.ie_ir_ver_2.emitter import soft_get, xml_shape
24 from mo.utils.error import Error
26 expected_result = b'<net><dim>2</dim><dim>10</dim><dim>50</dim><dim>50</dim></net>'
29 class TestEmitter(unittest.TestCase):
30 def test_xml_shape(self):
32 xml_shape(np.array([2, 10, 50, 50], dtype=np.int64), net)
33 self.assertEqual(tostring(net), expected_result)
35 def test_xml_shape_float_values(self):
37 xml_shape(np.array([2.0, 10.0, 50.0, 50.0], dtype=np.float32), net)
38 self.assertEqual(tostring(net), expected_result)
40 def test_xml_shape_non_integer_values(self):
42 with self.assertRaises(Error):
43 xml_shape(np.array([2.0, 10.0, 50.0, 50.5], dtype=np.float32), net)
45 def test_xml_shape_negative_values(self):
47 with self.assertRaises(Error):
48 xml_shape(np.array([2, 10, 50, -50], dtype=np.int64), net)
50 def test_xml_shape_zero_values(self):
52 with self.assertRaises(Error):
53 xml_shape(np.array([2, 0, 50, 50], dtype=np.int64), net)
56 class TestSoftGet(unittest.TestCase):
60 node.soft_get = lambda attr: attr
61 self.assertEqual(soft_get(node, 'string'), 'string')
63 def test_not_callable(self):
66 self.assertEqual(soft_get(node, 'string'), '<SUB-ELEMENT>')
68 def test_not_node_1(self):
69 node = {'soft_get': lambda attr: attr}
70 self.assertEqual(soft_get(node, 'string'), '<SUB-ELEMENT>')
72 def test_not_node_2(self):
73 node = 'something-else'
74 self.assertEqual(soft_get(node, 'string'), '<SUB-ELEMENT>')