Example #1
0
def test_distutils_parse_env_order(monkeypatch):
    from numpy.distutils.system_info import _parse_env_order
    env = 'NPY_TESTS_DISTUTILS_PARSE_ENV_ORDER'

    base_order = list('abcdef')

    monkeypatch.setenv(env, 'b,i,e,f')
    order, unknown = _parse_env_order(base_order, env)
    assert len(order) == 3
    assert order == list('bef')
    assert len(unknown) == 1

    # For when LAPACK/BLAS optimization is disabled
    monkeypatch.setenv(env, '')
    order, unknown = _parse_env_order(base_order, env)
    assert len(order) == 0
    assert len(unknown) == 0

    for prefix in '^!':
        monkeypatch.setenv(env, f'{prefix}b,i,e')
        order, unknown = _parse_env_order(base_order, env)
        assert len(order) == 4
        assert order == list('acdf')
        assert len(unknown) == 1

    with pytest.raises(ValueError):
        monkeypatch.setenv(env, 'b,^e,i')
        _parse_env_order(base_order, env)

    with pytest.raises(ValueError):
        monkeypatch.setenv(env, '!b,^e,i')
        _parse_env_order(base_order, env)
def test_distutils_parse_env_order(monkeypatch):
    from numpy.distutils.system_info import _parse_env_order

    env = "NPY_TESTS_DISTUTILS_PARSE_ENV_ORDER"

    base_order = list("abcdef")

    monkeypatch.setenv(env, "b,i,e,f")
    order, unknown = _parse_env_order(base_order, env)
    assert len(order) == 3
    assert order == list("bef")
    assert len(unknown) == 1

    # For when LAPACK/BLAS optimization is disabled
    monkeypatch.setenv(env, "")
    order, unknown = _parse_env_order(base_order, env)
    assert len(order) == 0
    assert len(unknown) == 0

    for prefix in "^!":
        monkeypatch.setenv(env, f"{prefix}b,i,e")
        order, unknown = _parse_env_order(base_order, env)
        assert len(order) == 4
        assert order == list("acdf")
        assert len(unknown) == 1

    with pytest.raises(ValueError):
        monkeypatch.setenv(env, "b,^e,i")
        _parse_env_order(base_order, env)

    with pytest.raises(ValueError):
        monkeypatch.setenv(env, "!b,^e,i")
        _parse_env_order(base_order, env)