CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
_pytest.py75 linesDownload Raw Back to pywt
1"""common test-related code."""
2import multiprocessing
3import os
4import platform
5import sys
6
7import numpy as np
8import pytest
9
10__all__ = ['uses_matlab',   # skip if pymatbridge and Matlab unavailable
11           'uses_futures',  # skip if futures unavailable
12           'uses_pymatbridge',  # skip if no PYWT_XSLOW environment variable
13           'uses_precomputed',  # skip if PYWT_XSLOW environment variable found
14           'matlab_result_dict_cwt',   # dict with precomputed Matlab dwt data
15           'matlab_result_dict_dwt',   # dict with precomputed Matlab cwt data
16           'futures',      # the futures module or None
17           'max_workers',  # the number of workers available to futures
18           'size_set',     # the set of Matlab tests to run
19           ]
20
21try:
22    from concurrent import futures
23    max_workers = multiprocessing.cpu_count()
24    futures_available = True
25except ImportError:
26    futures_available = False
27    futures = None
28    max_workers = 1
29
30# Check if running on Emscripten/WASM, and skip tests that require concurrency.
31# Relevant issue: https://github.com/pyodide/pyodide/issues/237
32IS_WASM = (sys.platform == "emscripten") or (platform.machine() in ["wasm32", "wasm64"])
33
34
35# check if pymatbridge + MATLAB tests should be run
36matlab_result_dict_dwt = None
37matlab_result_dict_cwt = None
38matlab_missing = True
39use_precomputed = True
40size_set = 'reduced'
41if 'PYWT_XSLOW' in os.environ:
42    try:
43        from pymatbridge import Matlab
44        mlab = Matlab()
45        matlab_missing = False
46        use_precomputed = False
47        size_set = 'full'
48    except ImportError:
49        print("To run Matlab compatibility tests you need to have MathWorks "
50              "MATLAB, MathWorks Wavelet Toolbox and the pymatbridge Python "
51              "package installed.")
52if use_precomputed:
53    # load dictionaries of precomputed results
54    data_dir = os.path.join(os.path.dirname(__file__), 'tests', 'data')
55    matlab_data_file_cwt = os.path.join(
56        data_dir, 'cwt_matlabR2015b_result.npz')
57    matlab_result_dict_cwt = np.load(matlab_data_file_cwt)
58
59    matlab_data_file_dwt = os.path.join(
60        data_dir, 'dwt_matlabR2012a_result.npz')
61    matlab_result_dict_dwt = np.load(matlab_data_file_dwt)
62
63uses_futures = pytest.mark.skipif(
64    not futures_available or IS_WASM,
65    reason='futures is not available, or running via Pyodide/WASM.')
66    # not futures_available, reason='futures not available')
67uses_matlab = pytest.mark.skipif(
68    matlab_missing, reason='pymatbridge and/or Matlab not available')
69uses_pymatbridge = pytest.mark.skipif(
70    use_precomputed,
71    reason='PYWT_XSLOW set: skipping tests against precomputed Matlab results')
72uses_precomputed = pytest.mark.skipif(
73    not use_precomputed,
74    reason='PYWT_XSLOW not set: test against precomputed matlab tests')
75 
Aluode/PerceptionLabPortable · CoolFace