File: test_utils.py

package info (click to toggle)
brian 2.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,872 kB
  • sloc: python: 51,820; cpp: 2,033; makefile: 108; sh: 72
file content (39 lines) | stat: -rw-r--r-- 982 bytes parent folder | download | duplicates (2)
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
import builtins

import pytest

from brian2.utils.environment import running_from_ipython
from brian2.utils.stringtools import SpellChecker


@pytest.mark.codegen_independent
def test_environment():
    """
    Test information about the environment we are running under.
    """
    if hasattr(builtins, "__IPYTHON__"):
        testing_under_ipython = True
        del builtins.__IPYTHON__
    else:
        testing_under_ipython = False

    assert not running_from_ipython()
    builtins.__IPYTHON__ = True
    assert running_from_ipython()

    if not testing_under_ipython:
        del builtins.__IPYTHON__


@pytest.mark.codegen_independent
def test_spell_check():
    checker = SpellChecker(["vm", "alpha", "beta"])
    assert checker.suggest("Vm") == {"vm"}
    assert checker.suggest("alphas") == {"alpha"}
    assert checker.suggest("bta") == {"beta"}
    assert checker.suggest("gamma") == set()


if __name__ == "__main__":
    test_environment()
    test_spell_check()