Debian Codegraph @

brian2/tests/test_utils.py

raw
1 import builtins
2
3 import pytest
4
5 from brian2.utils.environment import running_from_ipython
6 from brian2.utils.stringtools import SpellChecker
7
8
9 @pytest.mark.codegen_independent
10 def test_environment():
11 """
12 Test information about the environment we are running under.
13 """
14 if hasattr(builtins, "__IPYTHON__"):
15 testing_under_ipython = True
16 del builtins.__IPYTHON__
17 else:
18 testing_under_ipython = False
19
20 assert not running_from_ipython()
21 builtins.__IPYTHON__ = True
22 assert running_from_ipython()
23
24 if not testing_under_ipython:
25 del builtins.__IPYTHON__
26
27
28 @pytest.mark.codegen_independent
29 def test_spell_check():
30 checker = SpellChecker(["vm", "alpha", "beta"])
31 assert checker.suggest("Vm") == {"vm"}
32 assert checker.suggest("alphas") == {"alpha"}
33 assert checker.suggest("bta") == {"beta"}
34 assert checker.suggest("gamma") == set()
35
36
37 if __name__ == "__main__":
38 test_environment()
39 test_spell_check()