Skip to content

Commit

Permalink
Implement storing of models locally for test_timetest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
vurusovs committed Oct 14, 2020
1 parent 591d1f5 commit a76716f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 11 additions & 0 deletions tests/time_tests/test_runner/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import hashlib
import shutil
import logging
import tempfile

from test_runner.utils import upload_timetest_data, \
DATABASE, DB_COLLECTIONS
Expand Down Expand Up @@ -107,6 +108,16 @@ def niter(request):
# -------------------- CLI options --------------------


@pytest.fixture(scope="function")
def temp_dir(pytestconfig):
"""Create temporary directory for test purposes.
It will be cleaned up after every test run.
"""
temp_dir = tempfile.TemporaryDirectory()
yield temp_dir.name
temp_dir.cleanup()


@pytest.fixture(scope="function")
def cl_cache_dir(pytestconfig):
"""Generate directory to save OpenCL cache before test run and clean up after run.
Expand Down
13 changes: 11 additions & 2 deletions tests/time_tests/test_runner/test_timetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,38 @@
from pathlib import Path
import logging
import os
import shutil

from scripts.run_timetest import run_timetest
from test_runner.utils import expand_env_vars

REFS_FACTOR = 1.2 # 120%


def test_timetest(instance, executable, niter, cl_cache_dir, test_info):
def test_timetest(instance, executable, niter, cl_cache_dir, test_info, temp_dir):
"""Parameterized test.
:param instance: test instance. Should not be changed during test run
:param executable: timetest executable to run
:param niter: number of times to run executable
:param cl_cache_dir: directory to store OpenCL cache
:param test_info: custom `test_info` field of built-in `request` pytest fixture
:param temp_dir: path to a temporary directory. Will be cleaned up after test run
"""
# Prepare model to get model_path
model_path = instance["model"].get("path")
assert model_path, "Model path is empty"
model_path = Path(expand_env_vars(model_path))

# Copy model to a local temporary directory
model_dir = temp_dir / "model"
shutil.copytree(model_path.parent, model_dir)
model_path = model_dir / model_path.name

# Run executable
exe_args = {
"executable": Path(executable),
"model": Path(expand_env_vars(model_path)),
"model": Path(model_path),
"device": instance["device"]["name"],
"niter": niter
}
Expand Down

0 comments on commit a76716f

Please sign in to comment.