##// 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 39 - pip install setuptools --upgrade
40 40 - pip install -e file://$PWD#egg=ipython[test] --upgrade
41 41 - pip install trio curio
42 - pip install 'pytest<4' matplotlib
42 43 - pip install codecov check-manifest --upgrade
43 44
44 45 script:
@@ -49,6 +50,7 b' script:'
49 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 51 fi
51 52 - cd /tmp && iptest --coverage xml && cd -
53 - pytest IPython
52 54 # On the latest Python (on Linux) only, make sure that the docs build.
53 55 - |
54 56 if [[ "$TRAVIS_PYTHON_VERSION" == "3.7" ]] && [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
@@ -39,7 +39,7 b' def test_alias_args_error():'
39 39 _ip.run_cell('parts 1')
40 40
41 41 nt.assert_equal(cap.stderr.split(':')[0], 'UsageError')
42
42
43 43 def test_alias_args_commented():
44 44 """Check that alias correctly ignores 'commented out' args"""
45 45 _ip.magic('alias commetarg echo this is %%s a commented out arg')
@@ -47,7 +47,10 b' def test_alias_args_commented():'
47 47 with capture_output() as cap:
48 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 55 def test_alias_args_commented_nargs():
53 56 """Check that alias correctly counts args, excluding those commented out"""
@@ -59,4 +62,4 b' def test_alias_args_commented_nargs():'
59 62 assert am.is_alias(alias_name)
60 63
61 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 33 from IPython.utils.process import find_cmd
34 34
35 35
36
37 _ip = get_ipython()
38
39 36 @magic.magics_class
40 37 class DummyMagics(magic.Magics): pass
41 38
@@ -150,6 +147,7 b' def test_rehashx():'
150 147 # rehashx must fill up syscmdlist
151 148 scoms = _ip.db['syscmdlist']
152 149 nt.assert_true(len(scoms) > 10)
150
153 151
154 152
155 153 def test_magic_parse_options():
@@ -16,10 +16,6 b' import nose.tools as nt'
16 16 from IPython.testing import tools as tt
17 17
18 18 #-----------------------------------------------------------------------------
19 # Globals
20 #-----------------------------------------------------------------------------
21
22 #-----------------------------------------------------------------------------
23 19 # Test functions begin
24 20 #-----------------------------------------------------------------------------
25 21
@@ -23,8 +23,12 b' from IPython.utils.path import compress_user'
23 23 # Globals and constants
24 24 #-----------------------------------------------------------------------------
25 25
26 inspector = oinspect.Inspector()
27 ip = get_ipython()
26 inspector = None
27
28 def setup_module():
29 global inspector
30 inspector = oinspect.Inspector()
31
28 32
29 33 #-----------------------------------------------------------------------------
30 34 # Local utilities
@@ -34,7 +38,7 b' ip = get_ipython()'
34 38 # defined, if any code is inserted above, the following line will need to be
35 39 # updated. Do NOT insert any whitespace between the next line and the function
36 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 43 from unittest import TestCase
40 44
@@ -123,7 +127,6 b' class SimpleClass(object):'
123 127 """Some method's docstring"""
124 128
125 129
126
127 130 class Awkward(object):
128 131 def __getattr__(self, name):
129 132 raise Exception(name)
@@ -221,7 +224,6 b' def support_function_one(x, y=2, *a, **kw):'
221 224 def test_calldef_none():
222 225 # We should ignore __call__ for all of these.
223 226 for obj in [support_function_one, SimpleClass().method, any, str.upper]:
224 print(obj)
225 227 i = inspector.info(obj)
226 228 nt.assert_is(i['call_def'], None)
227 229
@@ -1,5 +1,5 b''
1 1 try:
2 from numpy.testing.noseclasses import KnownFailure, knownfailureif
2 from numpy.testing import KnownFailure, knownfailureif
3 3 except ImportError:
4 4 from ._decorators import knownfailureif
5 5 try:
@@ -49,7 +49,7 b' class TestController:'
49 49 self.env = {}
50 50 self.dirs = []
51 51
52 def setup(self):
52 def setUp(self):
53 53 """Create temporary directories etc.
54 54
55 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 440 'all tests.')
441 441 argparser.add_argument('--all', action='store_true',
442 442 help='Include slow tests not run by default.')
443 argparser.add_argument('--url', help="URL to use for the JS tests.")
444 443 argparser.add_argument('-j', '--fast', nargs='?', const=None, default=1, type=int,
445 444 help='Run test sections in parallel. This starts as many '
446 445 'processes as you have cores, or you can specify a number.')
@@ -38,6 +38,7 b' Authors'
38 38 import re
39 39 import unittest
40 40 from doctest import DocTestFinder, DocTestRunner, TestResults
41 from IPython.terminal.interactiveshell import InteractiveShell
41 42
42 43 #-----------------------------------------------------------------------------
43 44 # Classes and functions
@@ -78,7 +79,7 b' class IPython2PythonConverter(object):'
78 79 dnew = self.rps1.sub(pyps1, dnew)
79 80 dnew = self.rps2.sub(pyps2, dnew)
80 81 dnew = self.rout.sub(pyout, dnew)
81 ip = globalipapp.get_ipython()
82 ip = InteractiveShell.instance()
82 83
83 84 # Convert input IPython source into valid Python.
84 85 out = []
@@ -4,6 +4,7 b' include LICENSE'
4 4 include setupbase.py
5 5 include setupegg.py
6 6 include MANIFEST.in
7 include pytest.ini
7 8 include .mailmap
8 9
9 10 recursive-exclude tools *
General Comments 0
You need to be logged in to leave comments. Login now