def test_all_archs(): assert ti.lang.impl.current_cfg().arch in test_utils.expected_archs()
from tempfile import mkdtemp from time import sleep from typing import List import pytest import taichi as ti from tests import test_utils OFFLINE_CACHE_TEMP_DIR = mkdtemp() atexit.register(lambda: rmdir(OFFLINE_CACHE_TEMP_DIR)) supported_archs_offline_cache = [ti.cpu, ti.cuda] supported_archs_offline_cache = [ v for v in supported_archs_offline_cache if v in test_utils.expected_archs() ] def is_offline_cache_file(filename): suffixes = ('.ll', '.bc') return filename.endswith(suffixes) def get_cache_files_size(path): dir_path = tmp_offline_cache_file_path() files = listdir(path) result = 0 for file in files: if is_offline_cache_file(file): result += stat(join(dir_path, file)).st_size
def test_all_archs(): assert ti.cfg.arch in test_utils.expected_archs()
# test if specified in argument: for value in values: kwargs = {key: value} test_arg(key, value, kwargs) # test if specified in environment: env_key = 'TI_' + key.upper() for value in values: env_value = str(int(value) if isinstance(value, bool) else value) environ = {env_key: env_value} with patch_os_environ_helper(environ, excludes=env_configs): test_arg(key, value) @pytest.mark.parametrize('arch', test_utils.expected_archs()) def test_init_arch(arch): with patch_os_environ_helper({}, excludes=['TI_ARCH']): ti.init(arch=arch) assert ti.lang.impl.current_cfg().arch == arch with patch_os_environ_helper({'TI_ARCH': ti._lib.core.arch_name(arch)}, excludes=['TI_ARCH']): ti.init(arch=ti.cc) assert ti.lang.impl.current_cfg().arch == arch def test_init_bad_arg(): with pytest.raises(KeyError): ti.init(_test_mode=True, debug=True, foo_bar=233)