summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2017-10-01 18:53:08 +0200
committerStefan Behnel <stefan_ml@behnel.de>2017-10-01 18:53:08 +0200
commitaf5bb8945b958dc071e31f76f2774b702ae84c09 (patch)
tree0ef0366c7a8efd8e308f7a2d33c167ba96f9f7b3
parent557a2a2a6962f11727b2bfbdb04b6c4fea10e6fc (diff)
downloadcython-af5bb8945b958dc071e31f76f2774b702ae84c09.tar.gz
Avoid starting IPython in test module if we don't execute the tests.
-rw-r--r--Cython/Build/Tests/TestIpythonMagic.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/Cython/Build/Tests/TestIpythonMagic.py b/Cython/Build/Tests/TestIpythonMagic.py
index fafabde96..34272e4df 100644
--- a/Cython/Build/Tests/TestIpythonMagic.py
+++ b/Cython/Build/Tests/TestIpythonMagic.py
@@ -12,7 +12,7 @@ from Cython.Build import IpythonMagic
from Cython.TestUtils import CythonTest
try:
- from IPython.testing.globalipapp import get_ipython
+ import IPython.testing.globalipapp
from IPython.utils import py3compat
except ImportError:
# Disable tests and fake helpers for initialisation below.
@@ -21,19 +21,15 @@ except ImportError:
return s
__test__ = {}
- get_ipython = lambda: None
py3compat = _py3compat()
try:
- # disable IPython history thread to avoid having to clean it up
+ # disable IPython history thread before it gets started to avoid having to clean it up
from IPython.core.history import HistoryManager
HistoryManager.enabled = False
except ImportError:
pass
-# Initialise IPython after disabling history thread.
-ip = get_ipython()
-
code = py3compat.str_to_unicode("""\
def f(x):
return 2*x
@@ -75,17 +71,24 @@ else:
class TestIPythonMagic(CythonTest):
+ @classmethod
+ def setUpClass(cls):
+ CythonTest.setUpClass()
+ cls._ip = IPython.testing.globalipapp.get_ipython()
+
def setUp(self):
CythonTest.setUp(self)
- ip.extension_manager.load_extension('cython')
+ self._ip.extension_manager.load_extension('cython')
def test_cython_inline(self):
+ ip = self._ip
ip.ex('a=10; b=20')
result = ip.run_cell_magic('cython_inline', '', 'return a+b')
self.assertEqual(result, 30)
@skip_win32('Skip on Windows')
def test_cython_pyximport(self):
+ ip = self._ip
module_name = '_test_cython_pyximport'
ip.run_cell_magic('cython_pyximport', module_name, code)
ip.ex('g = f(10)')
@@ -99,12 +102,14 @@ class TestIPythonMagic(CythonTest):
pass
def test_cython(self):
+ ip = self._ip
ip.run_cell_magic('cython', '', code)
ip.ex('g = f(10)')
self.assertEqual(ip.user_ns['g'], 20.0)
def test_cython_name(self):
# The Cython module named 'mymodule' defines the function f.
+ ip = self._ip
ip.run_cell_magic('cython', '--name=mymodule', code)
# This module can now be imported in the interactive namespace.
ip.ex('import mymodule; g = mymodule.f(10)')
@@ -112,6 +117,7 @@ class TestIPythonMagic(CythonTest):
def test_cython_language_level(self):
# The Cython cell defines the functions f() and call().
+ ip = self._ip
ip.run_cell_magic('cython', '', cython3_code)
ip.ex('g = f(10); h = call(10)')
if sys.version_info[0] < 3:
@@ -123,6 +129,7 @@ class TestIPythonMagic(CythonTest):
def test_cython3(self):
# The Cython cell defines the functions f() and call().
+ ip = self._ip
ip.run_cell_magic('cython', '-3', cython3_code)
ip.ex('g = f(10); h = call(10)')
self.assertEqual(ip.user_ns['g'], 2.0 / 10.0)
@@ -130,6 +137,7 @@ class TestIPythonMagic(CythonTest):
def test_cython2(self):
# The Cython cell defines the functions f() and call().
+ ip = self._ip
ip.run_cell_magic('cython', '-2', cython3_code)
ip.ex('g = f(10); h = call(10)')
self.assertEqual(ip.user_ns['g'], 2 // 10)
@@ -138,6 +146,7 @@ class TestIPythonMagic(CythonTest):
@skip_win32('Skip on Windows')
def test_cython3_pgo(self):
# The Cython cell defines the functions f() and call().
+ ip = self._ip
ip.run_cell_magic('cython', '-3 --pgo', pgo_cython3_code)
ip.ex('g = f(10); h = call(10); main()')
self.assertEqual(ip.user_ns['g'], 2.0 / 10.0)
@@ -145,6 +154,7 @@ class TestIPythonMagic(CythonTest):
@skip_win32('Skip on Windows')
def test_extlibs(self):
+ ip = self._ip
code = py3compat.str_to_unicode("""
from libc.math cimport sin
x = sin(0.0)
@@ -155,6 +165,7 @@ x = sin(0.0)
def test_cython_verbose(self):
+ ip = self._ip
ip.run_cell_magic('cython', '--verbose', code)
ip.ex('g = f(10)')
self.assertEqual(ip.user_ns['g'], 20.0)
@@ -180,6 +191,7 @@ x = sin(0.0)
finally:
IpythonMagic.distutils.log = old_log
+ ip = self._ip
with mock_distutils() as verbose_log:
ip.run_cell_magic('cython', '--verbose', code)
ip.ex('g = f(10)')