|
4 | 4 | import shutil
|
5 | 5 | from argparse import Namespace
|
6 | 6 | from pathlib import Path
|
| 7 | +from unittest.mock import MagicMock, patch |
| 8 | +from zipfile import ZIP_STORED, ZipFile |
7 | 9 |
|
8 | 10 | import pytest
|
9 | 11 | import requests
|
@@ -81,9 +83,7 @@ def serialized_file(work_dir):
|
81 | 83 | @pytest.fixture(
|
82 | 84 | scope="module", name="mar_file_path", params=["yaml_config", "no_config"]
|
83 | 85 | )
|
84 |
| -def create_mar_file( |
85 |
| - work_dir, session_mocker, serialized_file, model_archiver, model_name, request |
86 |
| -): |
| 86 | +def create_mar_file(work_dir, serialized_file, model_archiver, model_name, request): |
87 | 87 | mar_file_path = Path(work_dir).joinpath(model_name + ".mar")
|
88 | 88 |
|
89 | 89 | name_file = REPO_ROOT_DIR.joinpath(
|
@@ -132,25 +132,19 @@ def create_mar_file(
|
132 | 132 | config_file=config_file,
|
133 | 133 | )
|
134 | 134 |
|
135 |
| - mock = session_mocker.MagicMock() |
136 |
| - mock.parse_args = session_mocker.MagicMock(return_value=args) |
137 |
| - session_mocker.patch( |
138 |
| - "archiver.ArgParser.export_model_args_parser", return_value=mock |
139 |
| - ) |
140 |
| - |
141 |
| - # Using ZIP_STORED instead of ZIP_DEFLATED reduces test runtime from 54 secs to 10 secs |
142 |
| - from zipfile import ZIP_STORED, ZipFile |
143 |
| - |
144 |
| - session_mocker.patch( |
145 |
| - "model_archiver.model_packaging_utils.zipfile.ZipFile", |
146 |
| - lambda x, y, _: ZipFile(x, y, ZIP_STORED), |
147 |
| - ) |
148 |
| - |
149 |
| - model_archiver.generate_model_archive() |
| 135 | + mock = MagicMock() |
| 136 | + mock.parse_args = MagicMock(return_value=args) |
| 137 | + with patch("archiver.ArgParser.export_model_args_parser", return_value=mock): |
| 138 | + # Using ZIP_STORED instead of ZIP_DEFLATED reduces test runtime from 54 secs to 10 secs |
| 139 | + with patch( |
| 140 | + "model_archiver.model_packaging_utils.zipfile.ZipFile", |
| 141 | + lambda x, y, _: ZipFile(x, y, ZIP_STORED), |
| 142 | + ): |
| 143 | + model_archiver.generate_model_archive() |
150 | 144 |
|
151 |
| - assert mar_file_path.exists() |
| 145 | + assert mar_file_path.exists() |
152 | 146 |
|
153 |
| - yield mar_file_path.as_posix() |
| 147 | + yield mar_file_path.as_posix() |
154 | 148 |
|
155 | 149 | # Clean up files
|
156 | 150 | mar_file_path.unlink(missing_ok=True)
|
|
0 commit comments