##// END OF EJS Templates
Also run test with Pytest....
Matthias Bussonnier -
Show More
@@ -0,0 +1,69 b''
1 import types
2 import sys
3 import builtins
4 import os
5 import pytest
6 import pathlib
7 import shutil
8
9 from IPython.testing import tools
10
11
12 def get_ipython():
13 from IPython.terminal.interactiveshell import TerminalInteractiveShell
14 if TerminalInteractiveShell._instance:
15 return TerminalInteractiveShell.instance()
16
17 config = tools.default_config()
18 config.TerminalInteractiveShell.simple_prompt = True
19
20 # Create and initialize our test-friendly IPython instance.
21 shell = TerminalInteractiveShell.instance(config=config)
22 return shell
23
24
25 @pytest.fixture(scope='session', autouse=True)
26 def work_path():
27 path = pathlib.Path("./tmp-ipython-pytest-profiledir")
28 os.environ["IPYTHONDIR"] = str(path.absolute())
29 if path.exists():
30 raise ValueError('IPython dir temporary path already exists ! Did previous test run exit successfully ?')
31 path.mkdir()
32 yield
33 shutil.rmtree(str(path.resolve()))
34
35
36 def nopage(strng, start=0, screen_lines=0, pager_cmd=None):
37 if isinstance(strng, dict):
38 strng = strng.get("text/plain", "")
39 print(strng)
40
41
42 def xsys(self, cmd):
43 """Replace the default system call with a capturing one for doctest.
44 """
45 # We use getoutput, but we need to strip it because pexpect captures
46 # the trailing newline differently from commands.getoutput
47 print(self.getoutput(cmd, split=False, depth=1).rstrip(), end="", file=sys.stdout)
48 sys.stdout.flush()
49
50
51 # for things to work correctly we would need this as a session fixture;
52 # unfortunately this will fail on some test that get executed as _collection_
53 # time (before the fixture run), in particular parametrized test that contain
54 # yields. so for now execute at import time.
55 #@pytest.fixture(autouse=True, scope='session')
56 def inject():
57
58 builtins.get_ipython = get_ipython
59 builtins._ip = get_ipython()
60 builtins.ip = get_ipython()
61 builtins.ip.system = types.MethodType(xsys, ip)
62 builtins.ip.builtin_trap.activate()
63 from IPython.core import page
64
65 page.pager_page = nopage
66 # yield
67
68
69 inject()
@@ -0,0 +1,2 b''
1 [pytest]
2 addopts = --duration=10
@@ -39,6 +39,7 b' install:'
39 - pip install setuptools --upgrade
39 - pip install setuptools --upgrade
40 - pip install -e file://$PWD#egg=ipython[test] --upgrade
40 - pip install -e file://$PWD#egg=ipython[test] --upgrade
41 - pip install trio curio
41 - pip install trio curio
42 - pip install 'pytest<4' matplotlib
42 - pip install codecov check-manifest --upgrade
43 - pip install codecov check-manifest --upgrade
43
44
44 script:
45 script:
@@ -49,6 +50,7 b' script:'
49 cp /home/travis/virtualenv/python3.8-dev/lib/python3.8/site-packages/parso/python/grammar37.txt /home/travis/virtualenv/python3.8-dev/lib/python3.8/site-packages/parso/python/grammar38.txt
50 cp /home/travis/virtualenv/python3.8-dev/lib/python3.8/site-packages/parso/python/grammar37.txt /home/travis/virtualenv/python3.8-dev/lib/python3.8/site-packages/parso/python/grammar38.txt
50 fi
51 fi
51 - cd /tmp && iptest --coverage xml && cd -
52 - cd /tmp && iptest --coverage xml && cd -
53 - pytest IPython
52 # On the latest Python (on Linux) only, make sure that the docs build.
54 # On the latest Python (on Linux) only, make sure that the docs build.
53 - |
55 - |
54 if [[ "$TRAVIS_PYTHON_VERSION" == "3.7" ]] && [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
56 if [[ "$TRAVIS_PYTHON_VERSION" == "3.7" ]] && [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
@@ -39,7 +39,7 b' def test_alias_args_error():'
39 _ip.run_cell('parts 1')
39 _ip.run_cell('parts 1')
40
40
41 nt.assert_equal(cap.stderr.split(':')[0], 'UsageError')
41 nt.assert_equal(cap.stderr.split(':')[0], 'UsageError')
42
42
43 def test_alias_args_commented():
43 def test_alias_args_commented():
44 """Check that alias correctly ignores 'commented out' args"""
44 """Check that alias correctly ignores 'commented out' args"""
45 _ip.magic('alias commetarg echo this is %%s a commented out arg')
45 _ip.magic('alias commetarg echo this is %%s a commented out arg')
@@ -47,7 +47,10 b' def test_alias_args_commented():'
47 with capture_output() as cap:
47 with capture_output() as cap:
48 _ip.run_cell('commetarg')
48 _ip.run_cell('commetarg')
49
49
50 nt.assert_equal(cap.stdout, 'this is %s a commented out arg')
50 # strip() is for pytest compat; testing via iptest patch IPython shell
51 # in testin.globalipapp and replace the system call which messed up the
52 # \r\n
53 assert cap.stdout.strip() == 'this is %s a commented out arg'
51
54
52 def test_alias_args_commented_nargs():
55 def test_alias_args_commented_nargs():
53 """Check that alias correctly counts args, excluding those commented out"""
56 """Check that alias correctly counts args, excluding those commented out"""
@@ -59,4 +62,4 b' def test_alias_args_commented_nargs():'
59 assert am.is_alias(alias_name)
62 assert am.is_alias(alias_name)
60
63
61 thealias = am.get_alias(alias_name)
64 thealias = am.get_alias(alias_name)
62 nt.assert_equal(thealias.nargs, 1) No newline at end of file
65 nt.assert_equal(thealias.nargs, 1)
@@ -33,9 +33,6 b' from IPython.utils.tempdir import (TemporaryDirectory,'
33 from IPython.utils.process import find_cmd
33 from IPython.utils.process import find_cmd
34
34
35
35
36
37 _ip = get_ipython()
38
39 @magic.magics_class
36 @magic.magics_class
40 class DummyMagics(magic.Magics): pass
37 class DummyMagics(magic.Magics): pass
41
38
@@ -150,6 +147,7 b' def test_rehashx():'
150 # rehashx must fill up syscmdlist
147 # rehashx must fill up syscmdlist
151 scoms = _ip.db['syscmdlist']
148 scoms = _ip.db['syscmdlist']
152 nt.assert_true(len(scoms) > 10)
149 nt.assert_true(len(scoms) > 10)
150
153
151
154
152
155 def test_magic_parse_options():
153 def test_magic_parse_options():
@@ -16,10 +16,6 b' import nose.tools as nt'
16 from IPython.testing import tools as tt
16 from IPython.testing import tools as tt
17
17
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19 # Globals
20 #-----------------------------------------------------------------------------
21
22 #-----------------------------------------------------------------------------
23 # Test functions begin
19 # Test functions begin
24 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
25
21
@@ -23,8 +23,12 b' from IPython.utils.path import compress_user'
23 # Globals and constants
23 # Globals and constants
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25
25
26 inspector = oinspect.Inspector()
26 inspector = None
27 ip = get_ipython()
27
28 def setup_module():
29 global inspector
30 inspector = oinspect.Inspector()
31
28
32
29 #-----------------------------------------------------------------------------
33 #-----------------------------------------------------------------------------
30 # Local utilities
34 # Local utilities
@@ -34,7 +38,7 b' ip = get_ipython()'
34 # defined, if any code is inserted above, the following line will need to be
38 # defined, if any code is inserted above, the following line will need to be
35 # updated. Do NOT insert any whitespace between the next line and the function
39 # updated. Do NOT insert any whitespace between the next line and the function
36 # definition below.
40 # definition below.
37 THIS_LINE_NUMBER = 37 # Put here the actual number of this line
41 THIS_LINE_NUMBER = 41 # Put here the actual number of this line
38
42
39 from unittest import TestCase
43 from unittest import TestCase
40
44
@@ -123,7 +127,6 b' class SimpleClass(object):'
123 """Some method's docstring"""
127 """Some method's docstring"""
124
128
125
129
126
127 class Awkward(object):
130 class Awkward(object):
128 def __getattr__(self, name):
131 def __getattr__(self, name):
129 raise Exception(name)
132 raise Exception(name)
@@ -221,7 +224,6 b' def support_function_one(x, y=2, *a, **kw):'
221 def test_calldef_none():
224 def test_calldef_none():
222 # We should ignore __call__ for all of these.
225 # We should ignore __call__ for all of these.
223 for obj in [support_function_one, SimpleClass().method, any, str.upper]:
226 for obj in [support_function_one, SimpleClass().method, any, str.upper]:
224 print(obj)
225 i = inspector.info(obj)
227 i = inspector.info(obj)
226 nt.assert_is(i['call_def'], None)
228 nt.assert_is(i['call_def'], None)
227
229
@@ -1,5 +1,5 b''
1 try:
1 try:
2 from numpy.testing.noseclasses import KnownFailure, knownfailureif
2 from numpy.testing import KnownFailure, knownfailureif
3 except ImportError:
3 except ImportError:
4 from ._decorators import knownfailureif
4 from ._decorators import knownfailureif
5 try:
5 try:
@@ -49,7 +49,7 b' class TestController:'
49 self.env = {}
49 self.env = {}
50 self.dirs = []
50 self.dirs = []
51
51
52 def setup(self):
52 def setUp(self):
53 """Create temporary directories etc.
53 """Create temporary directories etc.
54
54
55 This is only called when we know the test group will be run. Things
55 This is only called when we know the test group will be run. Things
@@ -440,7 +440,6 b" argparser.add_argument('testgroups', nargs='*',"
440 'all tests.')
440 'all tests.')
441 argparser.add_argument('--all', action='store_true',
441 argparser.add_argument('--all', action='store_true',
442 help='Include slow tests not run by default.')
442 help='Include slow tests not run by default.')
443 argparser.add_argument('--url', help="URL to use for the JS tests.")
444 argparser.add_argument('-j', '--fast', nargs='?', const=None, default=1, type=int,
443 argparser.add_argument('-j', '--fast', nargs='?', const=None, default=1, type=int,
445 help='Run test sections in parallel. This starts as many '
444 help='Run test sections in parallel. This starts as many '
446 'processes as you have cores, or you can specify a number.')
445 'processes as you have cores, or you can specify a number.')
@@ -38,6 +38,7 b' Authors'
38 import re
38 import re
39 import unittest
39 import unittest
40 from doctest import DocTestFinder, DocTestRunner, TestResults
40 from doctest import DocTestFinder, DocTestRunner, TestResults
41 from IPython.terminal.interactiveshell import InteractiveShell
41
42
42 #-----------------------------------------------------------------------------
43 #-----------------------------------------------------------------------------
43 # Classes and functions
44 # Classes and functions
@@ -78,7 +79,7 b' class IPython2PythonConverter(object):'
78 dnew = self.rps1.sub(pyps1, dnew)
79 dnew = self.rps1.sub(pyps1, dnew)
79 dnew = self.rps2.sub(pyps2, dnew)
80 dnew = self.rps2.sub(pyps2, dnew)
80 dnew = self.rout.sub(pyout, dnew)
81 dnew = self.rout.sub(pyout, dnew)
81 ip = globalipapp.get_ipython()
82 ip = InteractiveShell.instance()
82
83
83 # Convert input IPython source into valid Python.
84 # Convert input IPython source into valid Python.
84 out = []
85 out = []
@@ -4,6 +4,7 b' include LICENSE'
4 include setupbase.py
4 include setupbase.py
5 include setupegg.py
5 include setupegg.py
6 include MANIFEST.in
6 include MANIFEST.in
7 include pytest.ini
7 include .mailmap
8 include .mailmap
8
9
9 recursive-exclude tools *
10 recursive-exclude tools *
General Comments 0
You need to be logged in to leave comments. Login now