2 Copyright (c) 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.
20 from accuracy_checker.launcher.model_conversion import (exec_mo_binary, find_dlsdk_ir, find_mo, prepare_args)
21 from tests.common import mock_filesystem
24 def test_mock_file_system():
25 with mock_filesystem(['foo/bar', 'foo/baz/']) as prefix:
26 assert (prefix / 'foo' / 'bar').is_file()
27 assert (prefix / 'foo' / 'baz').is_dir()
31 with mock_filesystem(['deployment_tools/model_optimizer/mo.py']) as prefix:
32 assert find_mo([prefix / 'deployment_tools' / 'model_optimizer'])
35 def test_find_mo_is_none_when_not_exist():
36 with mock_filesystem(['deployment_tools/model_optimizer/mo.py']) as prefix:
37 assert find_mo([prefix / 'deployment_tools']) is None
40 def test_find_mo_list_not_corrupted():
41 with mock_filesystem(['deployment_tools/model_optimizer/mo.py']) as prefix:
42 search_paths = [prefix]
44 assert len(search_paths) == 1
47 def test_find_ir__in_root():
48 with mock_filesystem(['model.xml', 'model.bin']) as root:
49 model, weights = find_dlsdk_ir(root, 'model')
50 assert model == root / 'model.xml'
51 assert weights == root / 'model.bin'
54 def test_find_ir_raises_file_not_found_error_when_ir_not_found():
55 with mock_filesystem(['foo/']) as root:
56 with pytest.raises(FileNotFoundError):
57 find_dlsdk_ir(root, 'model')
60 def test_prepare_args():
61 args = prepare_args('foo', ['a', 'b'], {'bar': 123, 'x': 'baz'})
62 assert args[0] == sys.executable
63 assert args[1] == 'foo'
66 assert '--bar' in args
69 assert args[args.index('--bar') + 1] == '123'
70 assert args[args.index('--x') + 1] == 'baz'
73 def test_exec_mo_binary(mocker):
74 subprocess_run = mocker.patch('subprocess.run')
75 mocker.patch('os.chdir')
77 args = prepare_args('ModelOptimizer', value_options={'--foo': 'bar'})
80 subprocess_run.assert_called_once_with(args, check=False, timeout=None)