1# Copyright (c) 2023 Nordic Semiconductor ASA 2# 3# SPDX-License-Identifier: Apache-2.0 4 5import os 6import textwrap 7from pathlib import Path 8 9import pytest 10 11pytest_plugins = ['pytester'] 12 13 14@pytest.mark.parametrize( 15 'import_path, class_name, device_type', 16 [ 17 ('twister_harness.device.binary_adapter', 'NativeSimulatorAdapter', 'native'), 18 ('twister_harness.device.qemu_adapter', 'QemuAdapter', 'qemu'), 19 ('twister_harness.device.hardware_adapter', 'HardwareAdapter', 'hardware'), 20 ], 21 ids=[ 22 'native', 23 'qemu', 24 'hardware', 25 ] 26) 27def test_if_adapter_is_chosen_properly( 28 import_path: str, 29 class_name: str, 30 device_type: str, 31 tmp_path: Path, 32 twister_harness: str, 33 pytester: pytest.Pytester, 34): 35 pytester.makepyfile( 36 textwrap.dedent( 37 f""" 38 from twister_harness import DeviceAdapter 39 from {import_path} import {class_name} 40 41 def test_plugin(device_object): 42 assert isinstance(device_object, DeviceAdapter) 43 assert type(device_object) == {class_name} 44 """ 45 ) 46 ) 47 48 build_dir = tmp_path / 'build_dir' 49 os.mkdir(build_dir) 50 pytester.syspathinsert(twister_harness) 51 result = pytester.runpytest( 52 '--twister-harness', 53 f'--build-dir={build_dir}', 54 f'--device-type={device_type}', 55 '-p', 'twister_harness.plugin' 56 ) 57 58 assert result.ret == 0 59 result.assert_outcomes(passed=1, failed=0, errors=0, skipped=0) 60