Show More
@@ -45,6 +45,7 b' import nose.plugins.builtin' | |||||
45 | from nose.core import TestProgram |
|
45 | from nose.core import TestProgram | |
46 |
|
46 | |||
47 | # Our own imports |
|
47 | # Our own imports | |
|
48 | from IPython.utils.importstring import import_item | |||
48 | from IPython.utils.path import get_ipython_module_path |
|
49 | from IPython.utils.path import get_ipython_module_path | |
49 | from IPython.utils.process import find_cmd, pycmd2argv |
|
50 | from IPython.utils.process import find_cmd, pycmd2argv | |
50 | from IPython.utils.sysinfo import sys_info |
|
51 | from IPython.utils.sysinfo import sys_info | |
@@ -81,18 +82,38 b" warnings.filterwarnings('ignore', 'wxPython/wxWidgets release number mismatch'," | |||||
81 | #----------------------------------------------------------------------------- |
|
82 | #----------------------------------------------------------------------------- | |
82 | # Logic for skipping doctests |
|
83 | # Logic for skipping doctests | |
83 | #----------------------------------------------------------------------------- |
|
84 | #----------------------------------------------------------------------------- | |
|
85 | def extract_version(mod): | |||
|
86 | return mod.__version__ | |||
84 |
|
87 | |||
85 |
def test_for(m |
|
88 | def test_for(item, min_version=None, callback=extract_version): | |
86 |
"""Test to see if m |
|
89 | """Test to see if item is importable, and optionally check against a minimum | |
|
90 | version. | |||
|
91 | ||||
|
92 | If min_version is given, the default behavior is to check against the | |||
|
93 | `__version__` attribute of the item, but specifying `callback` allows you to | |||
|
94 | extract the value you are interested in. e.g:: | |||
|
95 | ||||
|
96 | In [1]: import sys | |||
|
97 | ||||
|
98 | In [2]: from IPython.testing.iptest import test_for | |||
|
99 | ||||
|
100 | In [3]: test_for('sys', (2,6), callback=lambda sys: sys.version_info) | |||
|
101 | Out[3]: True | |||
|
102 | ||||
|
103 | """ | |||
87 | try: |
|
104 | try: | |
88 |
|
|
105 | check = import_item(item) | |
89 | except (ImportError, RuntimeError): |
|
106 | except (ImportError, RuntimeError): | |
90 |
# GTK reports Runtime error if it can't be initialized even if |
|
107 | # GTK reports Runtime error if it can't be initialized even if it's | |
91 | # importable. |
|
108 | # importable. | |
92 | return False |
|
109 | return False | |
93 | else: |
|
110 | else: | |
94 | if min_version: |
|
111 | if min_version: | |
95 | return sys.modules[mod].__version__ >= min_version |
|
112 | if callback: | |
|
113 | # extra processing step to get version to compare | |||
|
114 | check = callback(check) | |||
|
115 | ||||
|
116 | return check >= min_version | |||
96 | else: |
|
117 | else: | |
97 | return True |
|
118 | return True | |
98 |
|
119 | |||
@@ -102,24 +123,27 b' have = {}' | |||||
102 |
|
123 | |||
103 | have['curses'] = test_for('_curses') |
|
124 | have['curses'] = test_for('_curses') | |
104 | have['matplotlib'] = test_for('matplotlib') |
|
125 | have['matplotlib'] = test_for('matplotlib') | |
105 | have['pexpect'] = test_for('pexpect') |
|
126 | have['pexpect'] = test_for('IPython.external.pexpect') | |
106 | have['pymongo'] = test_for('pymongo') |
|
127 | have['pymongo'] = test_for('pymongo') | |
107 | have['wx'] = test_for('wx') |
|
128 | have['wx'] = test_for('wx') | |
108 | have['wx.aui'] = test_for('wx.aui') |
|
129 | have['wx.aui'] = test_for('wx.aui') | |
109 | if os.name == 'nt': |
|
|||
110 | have['zmq'] = test_for('zmq', '2.1.7') |
|
|||
111 | else: |
|
|||
112 | have['zmq'] = test_for('zmq', '2.1.4') |
|
|||
113 | have['qt'] = test_for('IPython.external.qt') |
|
130 | have['qt'] = test_for('IPython.external.qt') | |
114 |
|
131 | |||
115 | try: |
|
132 | have['tornado'] = test_for('tornado.version_info', (2,1,0), callback=None) | |
116 | import tornado |
|
133 | ||
117 | if tornado.version_info < (2,1,0): |
|
134 | if os.name == 'nt': | |
118 | raise ImportError |
|
135 | min_zmq = (2,1,7) | |
119 | except ImportError: |
|
|||
120 | have['tornado'] = False |
|
|||
121 | else: |
|
136 | else: | |
122 | have['tornado'] = True |
|
137 | min_zmq = (2,1,4) | |
|
138 | ||||
|
139 | def version_tuple(mod): | |||
|
140 | "turn '2.1.9' into (2,1,9), and '2.1dev' into (2,1,999)" | |||
|
141 | # turn 'dev' into 999, because Python3 rejects str-int comparisons | |||
|
142 | vs = mod.__version__.replace('dev', '.999') | |||
|
143 | tup = tuple([int(v) for v in vs.split('.') ]) | |||
|
144 | return tup | |||
|
145 | ||||
|
146 | have['zmq'] = test_for('zmq', min_zmq, version_tuple) | |||
123 |
|
147 | |||
124 | #----------------------------------------------------------------------------- |
|
148 | #----------------------------------------------------------------------------- | |
125 | # Functions and classes |
|
149 | # Functions and classes |
General Comments 0
You need to be logged in to leave comments.
Login now