Skip to content

Commit

Permalink
Merge pull request #81 from zivid/enable-tests-on-windows
Browse files Browse the repository at this point in the history
Enable Windows CI tests
  • Loading branch information
trym-b authored Jul 14, 2020
2 parents 8e41840 + 2eeee66 commit c860ee1
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
25 changes: 25 additions & 0 deletions continuous-integration/windows/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tempfile
import sys
import subprocess
import shutil
from pathlib import Path


Expand Down Expand Up @@ -42,9 +43,33 @@ def _install_zivid_sdk():
_run_process((str(zivid_installer), "/S"))


def _install_intel_opencl_runtime():
import requests # pylint: disable=import-outside-toplevel

with tempfile.TemporaryDirectory() as temp_dir:
intel_opencl_runtime_url = "https://www.dropbox.com/s/09bk2nx31hzrupf/opencl_runtime_18.1_x64_setup-20200625-090300.msi?raw=1"
print("Downloading {}".format(intel_opencl_runtime_url), flush=True)
opencl_runtime = Path(temp_dir) / "opencl_runtime.msi"
response = requests.get(intel_opencl_runtime_url)
opencl_runtime.write_bytes(response.content)
print("Installing {}".format(opencl_runtime), flush=True)
_run_process(("msiexec", "/i", str(opencl_runtime), "/passive"))


def _write_zivid_cpu_configuration_file():
api_config = Path() / "ZividAPIConfig.yml"
target_location = Path(
r"C:\Users\VssAdministrator\AppData\Local\Zivid\API\Config.yml"
)
target_location.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(str(api_config), str(target_location))


def _main():
_install_pip_dependencies()
_install_intel_opencl_runtime()
_install_zivid_sdk()
_write_zivid_cpu_configuration_file()


if __name__ == "__main__":
Expand Down
39 changes: 29 additions & 10 deletions continuous-integration/windows/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import argparse
import sys
import subprocess
import winreg # pylint: disable=import-error
from os import environ
from pathlib import Path


Expand All @@ -10,10 +12,10 @@ def _options():
return parser.parse_args()


def _run_process(args):
def _run_process(args, env=None):
sys.stdout.flush()
try:
process = subprocess.Popen(args)
process = subprocess.Popen(args, env=env)
exit_code = process.wait()
if exit_code != 0:
raise RuntimeError("Wait failed with exit code {}".format(exit_code))
Expand All @@ -23,24 +25,41 @@ def _run_process(args):
sys.stdout.flush()


def _read_sys_env(environement_variable_name):
key = winreg.CreateKey(
winreg.HKEY_LOCAL_MACHINE,
r"System\CurrentControlSet\Control\Session Manager\Environment",
)
return winreg.QueryValueEx(key, environement_variable_name)[0]


def _test(root):
environment = environ.copy()
sys_path_key = "PATH"
sys_path_value = _read_sys_env(sys_path_key)
environment[sys_path_key] = sys_path_value
_run_process(
("python", "-m", "pytest", str(root), "-c", str(root / "pytest.ini"),),
env=environment,
)


def _install_pip_dependencies():
print("Installing python test requirements", flush=True)
_run_process(
(
"echo",
"TODO: ",
"python",
"-m",
"pytest",
str(root),
"-c",
str(root / "pytest.ini"),
"pip",
"install",
"--requirement",
"continuous-integration/python-requirements/test.txt",
)
)


def _main():
options = _options()

_install_pip_dependencies()
_test(options.root)


Expand Down
10 changes: 10 additions & 0 deletions test/test_samples.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import platform

import pytest


@pytest.mark.skipif(
platform.system() == "Windows",
reason=r"python: can't open file 'D:\a\samples\sample_capture_from_file.py': [Errno 2] No such file or directory",
)
def test_capture_from_file(sample_data_file):
pytest.helpers.run_sample(
name="capture_from_file", working_directory=sample_data_file.parent
)


@pytest.mark.skipif(
platform.system() == "Windows",
reason=r"python: can't open file 'D:\a\samples\sample_print_version_info.py': [Errno 2] No such file or directory",
)
def test_print_version_info():
pytest.helpers.run_sample(name="print_version_info")

0 comments on commit c860ee1

Please sign in to comment.