forked from ipython/ipython
/
test_shell_options.py
executable file
·94 lines (69 loc) · 2.89 KB
/
test_shell_options.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
"""A few unit tests for the Shell module.
"""
from unittest import TestCase, main
from IPython import Shell
try:
import matplotlib
has_matplotlib = True
except ImportError:
has_matplotlib = False
class ShellTestBase(TestCase):
def _test(self,argv,ans):
shell = Shell._select_shell(argv)
err = 'Got %s != %s' % (shell,ans)
self.failUnlessEqual(shell,ans,err)
class ArgsTestCase(ShellTestBase):
def test_plain(self):
self._test([],Shell.IPShell)
def test_tkthread(self):
self._test(['-tkthread'],Shell.IPShell)
def test_gthread(self):
self._test(['-gthread'],Shell.IPShellGTK)
def test_qthread(self):
self._test(['-qthread'],Shell.IPShellQt)
def test_q4thread(self):
self._test(['-q4thread'],Shell.IPShellQt4)
def test_wthread(self):
self._test(['-wthread'],Shell.IPShellWX)
if has_matplotlib:
class MplArgsTestCase(ShellTestBase):
def setUp(self):
self.backend = matplotlib.rcParams['backend']
def tearDown(self):
matplotlib.rcParams['backend'] = self.backend
def _test(self,argv,ans):
shell = Shell._select_shell(argv)
err = 'Got %s != %s' % (shell,ans)
self.failUnlessEqual(shell,ans,err)
def test_tk(self):
matplotlib.rcParams['backend'] = 'TkAgg'
self._test(['-pylab'],Shell.IPShellMatplotlib)
def test_ps(self):
matplotlib.rcParams['backend'] = 'PS'
self._test(['-pylab'],Shell.IPShellMatplotlib)
def test_gtk(self):
matplotlib.rcParams['backend'] = 'GTKAgg'
self._test(['-pylab'],Shell.IPShellMatplotlibGTK)
def test_gtk_2(self):
self._test(['-gthread','-pylab'],Shell.IPShellMatplotlibGTK)
self.failUnlessEqual(matplotlib.rcParams['backend'],'GTKAgg')
def test_qt(self):
matplotlib.rcParams['backend'] = 'QtAgg'
self._test(['-pylab'],Shell.IPShellMatplotlibQt)
def test_qt_2(self):
self._test(['-qthread','-pylab'],Shell.IPShellMatplotlibQt)
self.failUnlessEqual(matplotlib.rcParams['backend'],'QtAgg')
def test_qt4(self):
matplotlib.rcParams['backend'] = 'Qt4Agg'
self._test(['-pylab'],Shell.IPShellMatplotlibQt4)
def test_qt4_2(self):
self._test(['-q4thread','-pylab'],Shell.IPShellMatplotlibQt4)
self.failUnlessEqual(matplotlib.rcParams['backend'],'Qt4Agg')
def test_wx(self):
matplotlib.rcParams['backend'] = 'WxAgg'
self._test(['-pylab'],Shell.IPShellMatplotlibWX)
def test_wx_2(self):
self._test(['-pylab','-wthread'],Shell.IPShellMatplotlibWX)
self.failUnlessEqual(matplotlib.rcParams['backend'],'WXAgg')
main()