From 6aabd66239f40f9916761704f6716ffe0a0d2958 2016-05-26 21:24:57 From: Matthias Bussonnier Date: 2016-05-26 21:24:57 Subject: [PATCH] Make a few test non-optional. And add a few testing dependencies. --- diff --git a/IPython/core/tests/test_display.py b/IPython/core/tests/test_display.py index 9f10df4..58e2e91 100644 --- a/IPython/core/tests/test_display.py +++ b/IPython/core/tests/test_display.py @@ -2,7 +2,6 @@ # Distributed under the terms of the Modified BSD License. import json -import tempfile import os import warnings diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index a507ab9..17af507 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -39,6 +39,8 @@ else: from StringIO import StringIO +_ip = get_ipython() + @magic.magics_class class DummyMagics(magic.Magics): pass @@ -89,7 +91,6 @@ def test_config(): def test_rehashx(): # clear up everything - _ip = get_ipython() _ip.alias_manager.clear_aliases() del _ip.db['syscmdlist'] @@ -625,7 +626,6 @@ def test_extension(): sys.path.remove(daft_path) -@dec.skip_without('nbformat') def test_notebook_export_json(): _ip = get_ipython() _ip.history_manager.reset() # Clear any existing history. diff --git a/IPython/core/tests/test_run.py b/IPython/core/tests/test_run.py index 6f73f73..5e64fb2 100644 --- a/IPython/core/tests/test_run.py +++ b/IPython/core/tests/test_run.py @@ -254,22 +254,22 @@ class TestMagicRunSimple(tt.TempFileMixin): Returning from another run magic deletes the namespace""" # see ticket https://github.com/ipython/ipython/issues/238 - class secondtmp(tt.TempFileMixin): pass - empty = secondtmp() - empty.mktmp('') - # On Windows, the filename will have \users in it, so we need to use the - # repr so that the \u becomes \\u. - src = ("ip = get_ipython()\n" - "for i in range(5):\n" - " try:\n" - " ip.magic(%r)\n" - " except NameError as e:\n" - " print(i)\n" - " break\n" % ('run ' + empty.fname)) - self.mktmp(src) - _ip.magic('run %s' % self.fname) - _ip.run_cell('ip == get_ipython()') - nt.assert_equal(_ip.user_ns['i'], 4) + + with tt.TempFileMixin() as empty: + empty.mktmp('') + # On Windows, the filename will have \users in it, so we need to use the + # repr so that the \u becomes \\u. + src = ("ip = get_ipython()\n" + "for i in range(5):\n" + " try:\n" + " ip.magic(%r)\n" + " except NameError as e:\n" + " print(i)\n" + " break\n" % ('run ' + empty.fname)) + self.mktmp(src) + _ip.magic('run %s' % self.fname) + _ip.run_cell('ip == get_ipython()') + nt.assert_equal(_ip.user_ns['i'], 4) def test_run_second(self): """Test that running a second file doesn't clobber the first, gh-3547 @@ -278,12 +278,12 @@ class TestMagicRunSimple(tt.TempFileMixin): "def afunc():\n" " return avar\n") - empty = tt.TempFileMixin() - empty.mktmp("") - - _ip.magic('run %s' % self.fname) - _ip.magic('run %s' % empty.fname) - nt.assert_equal(_ip.user_ns['afunc'](), 1) + with tt.TempFileMixin() as empty: + empty.mktmp("") + + _ip.magic('run %s' % self.fname) + _ip.magic('run %s' % empty.fname) + nt.assert_equal(_ip.user_ns['afunc'](), 1) @dec.skip_win32 def test_tclass(self): diff --git a/IPython/terminal/tests/test_help.py b/IPython/terminal/tests/test_help.py index 9f92942..16a6f57 100644 --- a/IPython/terminal/tests/test_help.py +++ b/IPython/terminal/tests/test_help.py @@ -25,6 +25,5 @@ def test_locate_help(): def test_locate_profile_help(): tt.help_all_output_test("locate profile") -@skip_without('nbformat') # Requires jsonschema to be installed def test_trust_help(): tt.help_all_output_test("trust") diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index 9e1a883..1a9dd72 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -44,6 +44,7 @@ pjoin = path.join # Enable printing all warnings raise by IPython's modules +warnings.filterwarnings('ignore', message='.*Matplotlib is building the font cache.*', category=UserWarning, module='.*') if sys.version_info > (3,0): warnings.filterwarnings('error', message='.*', category=ResourceWarning, module='.*') warnings.filterwarnings('default', message='.*', category=Warning, module='IPy.*') diff --git a/IPython/testing/tools.py b/IPython/testing/tools.py index 69e5633..73f4ee7 100644 --- a/IPython/testing/tools.py +++ b/IPython/testing/tools.py @@ -303,6 +303,13 @@ class TempFileMixin(object): # delete it. I have no clue why pass + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, traceback): + self.tearDown() + + pair_fail_msg = ("Testing {0}\n\n" "In:\n" " {1!r}\n" diff --git a/setup.py b/setup.py index ab74fb8..b4f9826 100755 --- a/setup.py +++ b/setup.py @@ -182,13 +182,14 @@ extras_require = dict( parallel = ['ipyparallel'], qtconsole = ['qtconsole'], doc = ['Sphinx>=1.3'], - test = ['nose>=0.10.1', 'requests', 'testpath', 'pygments'], + test = ['nose>=0.10.1', 'requests', 'testpath', 'pygments', 'nbformat', 'ipykernel'], terminal = [], kernel = ['ipykernel'], nbformat = ['nbformat'], notebook = ['notebook', 'ipywidgets'], nbconvert = ['nbconvert'], ) + install_requires = [ 'setuptools>=18.5', 'decorator',