Skip to content

Commit 79f3690

Browse files
committed
+ tests
1 parent f9b317c commit 79f3690

File tree

7 files changed

+179
-135
lines changed

7 files changed

+179
-135
lines changed

tests/python_tests/samples/conftest.py

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# - "name": the model's name or path
2222
# - "convert_args": a list of arguments for the conversion command
2323
MODELS = {
24-
"TinyLlama-1.1B-Chat-v1.0": {
24+
"TinyLlama-1.1B-Chat-v1.0": {
2525
"name": "TinyLlama/TinyLlama-1.1B-Chat-v1.0",
2626
"convert_args": ['--weight-format', 'fp16']
2727
},
@@ -41,7 +41,7 @@
4141
"SmolLM2-360M": {
4242
"name": "HuggingFaceTB/SmolLM2-360M",
4343
"convert_args": ['--trust-remote-code']
44-
},
44+
},
4545
"WhisperTiny": {
4646
"name": "openai/whisper-tiny",
4747
"convert_args": ['--trust-remote-code', '--weight-format', 'fp16']
@@ -79,11 +79,11 @@
7979
"LCM_Dreamshaper_v7-int8-ov": {
8080
"name": "OpenVINO/LCM_Dreamshaper_v7-int8-ov",
8181
"convert_args": []
82-
},
82+
},
8383
"llava-1.5-7b-hf": {
8484
"name": "llava-hf/llava-1.5-7b-hf",
8585
"convert_args": ['--trust-remote-code', '--weight-format', 'fp16']
86-
},
86+
},
8787
"llava-v1.6-mistral-7b-hf": {
8888
"name": "llava-hf/llava-v1.6-mistral-7b-hf",
8989
"convert_args": ['--trust-remote-code', '--weight-format', 'fp16']
@@ -162,29 +162,32 @@
162162
"cmu_us_awb_arctic-wav-arctic_a0001.bin": "https://huggingface.co/datasets/Xenova/cmu-arctic-xvectors-extracted/resolve/main/cmu_us_awb_arctic-wav-arctic_a0001.bin"
163163
}
164164

165+
165166
SAMPLES_PY_DIR = Path(os.environ.get("SAMPLES_PY_DIR", os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../samples/python"))))
166167
SAMPLES_CPP_DIR = Path(os.environ.get("SAMPLES_CPP_DIR", os.getcwd()))
167168
SAMPLES_C_DIR = os.environ.get("SAMPLES_C_DIR", os.getcwd())
168169
SAMPLES_JS_DIR = Path(os.environ.get("SAMPLES_JS_DIR", os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../samples/js"))))
170+
PROMPT_REPO_URL = "https://github.com/intel-innersource/frameworks.ai.openvino.llm.prompts/raw/refs/heads/master"
171+
169172

170173
@pytest.fixture(scope="session", autouse=True)
171174
def setup_and_teardown(request, tmp_path_factory):
172175
"""Fixture to set up and tear down the temporary directories."""
173-
174-
ov_cache = get_ov_cache_dir(tmp_path_factory.mktemp("ov_cache"))
176+
177+
ov_cache = get_ov_cache_dir(tmp_path_factory.mktemp("ov_cache"))
175178
models_dir = os.path.join(ov_cache, "test_models")
176179
test_data = os.path.join(ov_cache, "test_data")
177-
180+
178181
logger.info(f"Creating directories: {models_dir} and {test_data}")
179182
os.makedirs(models_dir, exist_ok=True)
180183
os.makedirs(test_data, exist_ok=True)
181-
184+
182185
request.config.cache.set("OV_CACHE", str(ov_cache))
183186
request.config.cache.set("MODELS_DIR", str(models_dir))
184187
request.config.cache.set("TEST_DATA", str(test_data))
185-
188+
186189
yield
187-
190+
188191
if os.environ.get("CLEANUP_CACHE", "false").lower() != "false":
189192
if os.path.exists(ov_cache):
190193
logger.info(f"Removing temporary directory: {ov_cache}")
@@ -269,9 +272,9 @@ def download_model(request):
269272
command = ["huggingface-cli", "download", model_name, "--local-dir", model_path]
270273
logger.info(f"Downloading command: {' '.join(command)}")
271274
retry_request(lambda: subprocess.run(command, check=True, capture_output=True, text=True, env=sub_env))
272-
275+
273276
yield model_path
274-
277+
275278
# Cleanup the model after tests
276279
if os.environ.get("CLEANUP_CACHE", "false").lower() == "true":
277280
if os.path.exists(model_cache):
@@ -281,13 +284,13 @@ def download_model(request):
281284
@pytest.fixture(scope="session")
282285
def download_test_content(request):
283286
"""Download the test content from the given URL and return the file path or extracted folder."""
284-
287+
285288
test_data = request.config.cache.get("TEST_DATA", None)
286-
289+
287290
file_name = request.param
288291
file_url = TEST_FILES[file_name]
289292
file_path = os.path.join(test_data, file_name)
290-
293+
291294
if not os.path.exists(file_path):
292295
logger.info(f"Downloading test content from {file_url} to {file_path}...")
293296
os.makedirs(os.path.dirname(file_path), exist_ok=True)
@@ -327,9 +330,9 @@ def download_test_content(request):
327330
@pytest.fixture(scope="session")
328331
def generate_test_content(request):
329332
"""Generate an image of lines and return the file path."""
330-
333+
331334
test_data = request.config.cache.get("TEST_DATA", None)
332-
335+
333336
file_name = request.param
334337
file_path = os.path.join(test_data, file_name)
335338
if not os.path.exists(file_path):
@@ -355,24 +358,24 @@ def generate_test_content(request):
355358
@pytest.fixture(scope="session")
356359
def generate_image_generation_jsonl(request):
357360
"""Generate a JSONL file for image generation prompts."""
358-
361+
359362
test_data = request.config.cache.get("TEST_DATA", None)
360363
file_name, json_entries = request.param
361364
file_path = os.path.join(test_data, file_name)
362-
365+
363366
if not os.path.exists(file_path):
364367
os.makedirs(os.path.dirname(file_path), exist_ok=True)
365-
368+
366369
with open(file_path, "w", encoding="utf-8") as f:
367370
for entry in json_entries:
368371
f.write(json.dumps(entry) + "\n")
369-
372+
370373
logger.info(f"Generated image generation JSONL file at {file_path}")
371374
else:
372375
logger.info(f"Image generation JSONL file already exists at {file_path}")
373-
376+
374377
yield file_path
375-
378+
376379
# Cleanup the JSONL file after tests
377380
if os.environ.get("CLEANUP_CACHE", "false").lower() == "true":
378381
if os.path.exists(file_path):
@@ -387,3 +390,21 @@ def run_gc_after_test():
387390
"""
388391
yield
389392
gc.collect()
393+
394+
@pytest.fixture(scope="session")
395+
def download_test_video():
396+
github_raw_url = f"{PROMPT_REPO_URL}/multimodal/video/spinning-earth-480.mp4"
397+
response = requests.get(github_raw_url, stream=True)
398+
response.raise_for_status()
399+
400+
temp_dir = tempfile.mkdtemp()
401+
video_path = os.path.join(temp_dir, "spinning-earth-480.mp4")
402+
with open(video_path, 'wb') as f:
403+
for chunk in response.iter_content(chunk_size=8192):
404+
f.write(chunk)
405+
yield video_path
406+
407+
if os.path.exists(video_path):
408+
os.remove(video_path)
409+
os.rmdir(temp_dir)
410+

0 commit comments

Comments
 (0)