def test_get_engines_for_model_with_ir_raises(mocker): engines_mocker = mocker.patch('ie_serving.models.ir_engine.IrEngine.' 'build') engines_mocker.side_effect = ['modelv2', 'modelv4', Exception("test")] available_versions = [{'xml_file': 'modelv2.xml', 'bin_file': 'modelv2.bin', 'mapping_config': 'mapping_config.json', 'version_number': 2, 'batch_size_param': None, 'shape_param': None, 'num_ireq': 1, 'target_device': 'CPU', 'plugin_config': None}, {'xml_file': 'modelv4.xml', 'bin_file': 'modelv4.bin', 'mapping_config': 'mapping_config.json', 'version_number': 3, 'batch_size_param': None, 'shape_param': None, 'num_ireq': 1, 'target_device': 'CPU', 'plugin_config': None}, {'xml_file': 'modelv4.xml', 'bin_file': 'modelv4.bin', 'mapping_config': 'mapping_config.json', 'version_number': 4, 'batch_size_param': None, 'shape_param': None, 'num_ireq': 1, 'target_device': 'CPU', 'plugin_config': None}] versions_statuses = {} for version in available_versions: version_number = version['version_number'] versions_statuses[version_number] = ModelVersionStatus( "test", version_number) output = LocalModel.get_engines_for_model( model_name='test', versions_attributes=available_versions, versions_statuses=versions_statuses, update_locks={}) assert 2 == len(output) assert 'modelv2' == output[2] assert 'modelv4' == output[3]
def test_get_engines_for_model_with_ir_raises(mocker): engines_mocker = mocker.patch('ie_serving.models.ir_engine.IrEngine.' 'build') engines_mocker.side_effect = ['modelv2', 'modelv4', Exception("test")] available_versions = [{ 'xml_file': 'modelv2.xml', 'bin_file': 'modelv2.bin', 'mapping_config': 'mapping_config.json', 'version_number': 2 }, { 'xml_file': 'modelv4.xml', 'bin_file': 'modelv4.bin', 'mapping_config': 'mapping_config.json', 'version_number': 3 }, { 'xml_file': 'modelv4.xml', 'bin_file': 'modelv4.bin', 'mapping_config': 'mapping_config.json', 'version_number': 4 }] output = LocalModel.get_engines_for_model( versions_attributes=available_versions) assert 2 == len(output) assert 'modelv2' == output[2] assert 'modelv4' == output[3]
def test_get_engines_for_model(mocker, is_error): engines_mocker = mocker.patch('ie_serving.models.ir_engine.IrEngine.' 'build') engines_mocker.side_effect = ['modelv2', 'modelv4'] available_versions = [{ 'xml_file': 'modelv2.xml', 'bin_file': 'modelv2.bin', 'mapping_config': 'mapping_config.json', 'version_number': 2, 'batch_size_param': None, 'shape_param': None, 'num_ireq': 1, 'target_device': 'CPU', 'plugin_config': None }, { 'xml_file': 'modelv4.xml', 'bin_file': 'modelv4.bin', 'mapping_config': 'mapping_config.json', 'version_number': 4, 'batch_size_param': None, 'shape_param': None, 'num_ireq': 1, 'target_device': 'CPU', 'plugin_config': None }] versions_statuses = {} for version in available_versions: version_number = version['version_number'] versions_statuses[version_number] = ModelVersionStatus( "test", version_number) if is_error: get_engine_for_version_mocker = mocker.patch( 'ie_serving.models.local_model.LocalModel.get_engine_for_version') get_engine_for_version_mocker.side_effect = Exception() output = LocalModel.get_engines_for_model( model_name='test', versions_attributes=available_versions, versions_statuses=versions_statuses) for version_status in versions_statuses.values(): assert version_status.state == ModelVersionState.LOADING if is_error: assert version_status.status['error_code'] == ErrorCode.UNKNOWN assert get_engine_for_version_mocker.called else: assert version_status.status['error_code'] == ErrorCode.OK if is_error: assert 0 == len(output) else: assert 2 == len(output) assert 'modelv2' == output[2] assert 'modelv4' == output[4]
def test_get_engines_for_model(mocker): engines_mocker = mocker.patch('ie_serving.models.ir_engine.IrEngine.' 'build') engines_mocker.side_effect = ['modelv2', 'modelv4'] available_versions = [{ 'xml_file': 'modelv2.xml', 'bin_file': 'modelv2.bin', 'mapping_config': 'mapping_config.json', 'version_number': 2, 'batch_size': None }, { 'xml_file': 'modelv4.xml', 'bin_file': 'modelv4.bin', 'mapping_config': 'mapping_config.json', 'version_number': 4, 'batch_size': None }] output = LocalModel.get_engines_for_model( versions_attributes=available_versions) assert 2 == len(output) assert 'modelv2' == output[2] assert 'modelv4' == output[4]