File: test_testing.py

package info (click to toggle)
python-mne 1.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 131,492 kB
  • sloc: python: 213,302; javascript: 12,910; sh: 447; makefile: 144
file content (60 lines) | stat: -rw-r--r-- 1,599 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Authors: The MNE-Python contributors.
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.

import os.path as op
from pathlib import Path

import numpy as np
import pytest

from mne.datasets import testing
from mne.utils import _TempDir, _url_to_local_path, buggy_mkl_svd


def test_buggy_mkl():
    """Test decorator for buggy MKL issues."""
    from unittest import SkipTest

    @buggy_mkl_svd
    def foo(a, b):
        raise np.linalg.LinAlgError("SVD did not converge")

    with pytest.warns(RuntimeWarning, match="convergence error"):
        with pytest.raises(SkipTest):
            foo(1, 2)

    @buggy_mkl_svd
    def bar(c, d, e):
        raise RuntimeError("SVD did not converge")

    pytest.raises(RuntimeError, bar, 1, 2, 3)


def test_tempdir():
    """Test TempDir."""
    tempdir2 = _TempDir()
    assert Path(tempdir2).is_dir()
    x = str(tempdir2)
    del tempdir2
    assert not Path(x).is_dir()


def test_datasets(monkeypatch, tmp_path):
    """Test dataset config."""
    # gh-4192
    fake_path = tmp_path / "MNE-testing-data"
    fake_path.mkdir()
    with open(fake_path / "version.txt", "w") as fid:
        fid.write("9999.9999")
    monkeypatch.setenv("_MNE_FAKE_HOME_DIR", str(tmp_path))
    monkeypatch.setenv("MNE_DATASETS_TESTING_PATH", str(tmp_path))
    got_path = str(testing.data_path(download=False, verbose="debug"))
    assert got_path == str(fake_path)


def test_url_to_local_path():
    """Test URL to local path."""
    assert _url_to_local_path("http://google.com/home/why.html", ".") == op.join(
        ".", "home", "why.html"
    )