Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
test_scripts.py49 linesDownload Raw Back to tests
1""" Test scripts
2
3Test that we can run executable scripts that have been installed with numpy.
4"""
5import os
6import subprocess
7import sys
8from os.path import dirname, isfile, join as pathjoin
9
10import pytest
11
12import numpy as np
13from numpy.testing import IS_WASM, assert_equal
14
15is_inplace = isfile(pathjoin(dirname(np.__file__), '..', 'setup.py'))
16
17
18def find_f2py_commands():
19    if sys.platform == 'win32':
20        exe_dir = dirname(sys.executable)
21        if exe_dir.endswith('Scripts'):  # virtualenv
22            return [os.path.join(exe_dir, 'f2py')]
23        else:
24            return [os.path.join(exe_dir, "Scripts", 'f2py')]
25    else:
26        # Three scripts are installed in Unix-like systems:
27        # 'f2py', 'f2py{major}', and 'f2py{major.minor}'. For example,
28        # if installed with python3.9 the scripts would be named
29        # 'f2py', 'f2py3', and 'f2py3.9'.
30        version = sys.version_info
31        major = str(version.major)
32        minor = str(version.minor)
33        return ['f2py', 'f2py' + major, 'f2py' + major + '.' + minor]
34
35
36@pytest.mark.skipif(is_inplace, reason="Cannot test f2py command inplace")
37@pytest.mark.xfail(reason="Test is unreliable")
38@pytest.mark.parametrize('f2py_cmd', find_f2py_commands())
39def test_f2py(f2py_cmd):
40    # test that we can run f2py script
41    stdout = subprocess.check_output([f2py_cmd, '-v'])
42    assert_equal(stdout.strip(), np.__version__.encode('ascii'))
43
44
45@pytest.mark.skipif(IS_WASM, reason="Cannot start subprocess")
46def test_pep338():
47    stdout = subprocess.check_output([sys.executable, '-mnumpy.f2py', '-v'])
48    assert_equal(stdout.strip(), np.__version__.encode('ascii'))
49 
codekingpro/portable-devtools · Team Ai