##// END OF EJS Templates
make sure to run async tests...
Min RK -
Show More
@@ -1,72 +1,87 b''
1 import types
2 import sys
3 import builtins
1 import builtins
2 import inspect
4 import os
3 import os
5 import pytest
6 import pathlib
4 import pathlib
7 import shutil
5 import shutil
6 import sys
7 import types
8
9 import pytest
8
10
9 # Must register before it gets imported
11 # Must register before it gets imported
10 pytest.register_assert_rewrite("IPython.testing.tools")
12 pytest.register_assert_rewrite("IPython.testing.tools")
11
13
12 from .testing import tools
14 from .testing import tools
13
15
14
16
17 def pytest_collection_modifyitems(items):
18 """This function is automatically run by pytest passing all collected test
19 functions.
20
21 We use it to add asyncio marker to all async tests and assert we don't use
22 test functions that are async generators which wouldn't make sense.
23 """
24 for item in items:
25 if inspect.iscoroutinefunction(item.obj):
26 item.add_marker("asyncio")
27 assert not inspect.isasyncgenfunction(item.obj)
28
29
15 def get_ipython():
30 def get_ipython():
16 from .terminal.interactiveshell import TerminalInteractiveShell
31 from .terminal.interactiveshell import TerminalInteractiveShell
17 if TerminalInteractiveShell._instance:
32 if TerminalInteractiveShell._instance:
18 return TerminalInteractiveShell.instance()
33 return TerminalInteractiveShell.instance()
19
34
20 config = tools.default_config()
35 config = tools.default_config()
21 config.TerminalInteractiveShell.simple_prompt = True
36 config.TerminalInteractiveShell.simple_prompt = True
22
37
23 # Create and initialize our test-friendly IPython instance.
38 # Create and initialize our test-friendly IPython instance.
24 shell = TerminalInteractiveShell.instance(config=config)
39 shell = TerminalInteractiveShell.instance(config=config)
25 return shell
40 return shell
26
41
27
42
28 @pytest.fixture(scope='session', autouse=True)
43 @pytest.fixture(scope='session', autouse=True)
29 def work_path():
44 def work_path():
30 path = pathlib.Path("./tmp-ipython-pytest-profiledir")
45 path = pathlib.Path("./tmp-ipython-pytest-profiledir")
31 os.environ["IPYTHONDIR"] = str(path.absolute())
46 os.environ["IPYTHONDIR"] = str(path.absolute())
32 if path.exists():
47 if path.exists():
33 raise ValueError('IPython dir temporary path already exists ! Did previous test run exit successfully ?')
48 raise ValueError('IPython dir temporary path already exists ! Did previous test run exit successfully ?')
34 path.mkdir()
49 path.mkdir()
35 yield
50 yield
36 shutil.rmtree(str(path.resolve()))
51 shutil.rmtree(str(path.resolve()))
37
52
38
53
39 def nopage(strng, start=0, screen_lines=0, pager_cmd=None):
54 def nopage(strng, start=0, screen_lines=0, pager_cmd=None):
40 if isinstance(strng, dict):
55 if isinstance(strng, dict):
41 strng = strng.get("text/plain", "")
56 strng = strng.get("text/plain", "")
42 print(strng)
57 print(strng)
43
58
44
59
45 def xsys(self, cmd):
60 def xsys(self, cmd):
46 """Replace the default system call with a capturing one for doctest.
61 """Replace the default system call with a capturing one for doctest.
47 """
62 """
48 # We use getoutput, but we need to strip it because pexpect captures
63 # We use getoutput, but we need to strip it because pexpect captures
49 # the trailing newline differently from commands.getoutput
64 # the trailing newline differently from commands.getoutput
50 print(self.getoutput(cmd, split=False, depth=1).rstrip(), end="", file=sys.stdout)
65 print(self.getoutput(cmd, split=False, depth=1).rstrip(), end="", file=sys.stdout)
51 sys.stdout.flush()
66 sys.stdout.flush()
52
67
53
68
54 # for things to work correctly we would need this as a session fixture;
69 # for things to work correctly we would need this as a session fixture;
55 # unfortunately this will fail on some test that get executed as _collection_
70 # unfortunately this will fail on some test that get executed as _collection_
56 # time (before the fixture run), in particular parametrized test that contain
71 # time (before the fixture run), in particular parametrized test that contain
57 # yields. so for now execute at import time.
72 # yields. so for now execute at import time.
58 #@pytest.fixture(autouse=True, scope='session')
73 #@pytest.fixture(autouse=True, scope='session')
59 def inject():
74 def inject():
60
75
61 builtins.get_ipython = get_ipython
76 builtins.get_ipython = get_ipython
62 builtins._ip = get_ipython()
77 builtins._ip = get_ipython()
63 builtins.ip = get_ipython()
78 builtins.ip = get_ipython()
64 builtins.ip.system = types.MethodType(xsys, ip)
79 builtins.ip.system = types.MethodType(xsys, ip)
65 builtins.ip.builtin_trap.activate()
80 builtins.ip.builtin_trap.activate()
66 from .core import page
81 from .core import page
67
82
68 page.pager_page = nopage
83 page.pager_page = nopage
69 # yield
84 # yield
70
85
71
86
72 inject()
87 inject()
@@ -1,184 +1,185 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Setup script for IPython.
2 """Setup script for IPython.
3
3
4 Under Posix environments it works like a typical setup.py script.
4 Under Posix environments it works like a typical setup.py script.
5 Under Windows, the command sdist is not supported, since IPython
5 Under Windows, the command sdist is not supported, since IPython
6 requires utilities which are not available under Windows."""
6 requires utilities which are not available under Windows."""
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (c) 2008-2011, IPython Development Team.
9 # Copyright (c) 2008-2011, IPython Development Team.
10 # Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>
10 # Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>
11 # Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
11 # Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
12 # Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
12 # Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
13 #
13 #
14 # Distributed under the terms of the Modified BSD License.
14 # Distributed under the terms of the Modified BSD License.
15 #
15 #
16 # The full license is in the file COPYING.rst, distributed with this software.
16 # The full license is in the file COPYING.rst, distributed with this software.
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18
18
19 import os
19 import os
20 import sys
20 import sys
21 from itertools import chain
21 from itertools import chain
22
22
23 # **Python version check**
23 # **Python version check**
24 #
24 #
25 # This check is also made in IPython/__init__, don't forget to update both when
25 # This check is also made in IPython/__init__, don't forget to update both when
26 # changing Python version requirements.
26 # changing Python version requirements.
27 if sys.version_info < (3, 8):
27 if sys.version_info < (3, 8):
28 pip_message = 'This may be due to an out of date pip. Make sure you have pip >= 9.0.1.'
28 pip_message = 'This may be due to an out of date pip. Make sure you have pip >= 9.0.1.'
29 try:
29 try:
30 import pip
30 import pip
31 pip_version = tuple([int(x) for x in pip.__version__.split('.')[:3]])
31 pip_version = tuple([int(x) for x in pip.__version__.split('.')[:3]])
32 if pip_version < (9, 0, 1) :
32 if pip_version < (9, 0, 1) :
33 pip_message = 'Your pip version is out of date, please install pip >= 9.0.1. '\
33 pip_message = 'Your pip version is out of date, please install pip >= 9.0.1. '\
34 'pip {} detected.'.format(pip.__version__)
34 'pip {} detected.'.format(pip.__version__)
35 else:
35 else:
36 # pip is new enough - it must be something else
36 # pip is new enough - it must be something else
37 pip_message = ''
37 pip_message = ''
38 except Exception:
38 except Exception:
39 pass
39 pass
40
40
41
41
42 error = """
42 error = """
43 IPython 8+ supports Python 3.8 and above, following NEP 29.
43 IPython 8+ supports Python 3.8 and above, following NEP 29.
44 When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
44 When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
45 Python 3.3 and 3.4 were supported up to IPython 6.x.
45 Python 3.3 and 3.4 were supported up to IPython 6.x.
46 Python 3.5 was supported with IPython 7.0 to 7.9.
46 Python 3.5 was supported with IPython 7.0 to 7.9.
47 Python 3.6 was supported with IPython up to 7.16.
47 Python 3.6 was supported with IPython up to 7.16.
48 Python 3.7 was still supported with the 7.x branch.
48 Python 3.7 was still supported with the 7.x branch.
49
49
50 See IPython `README.rst` file for more information:
50 See IPython `README.rst` file for more information:
51
51
52 https://github.com/ipython/ipython/blob/master/README.rst
52 https://github.com/ipython/ipython/blob/master/README.rst
53
53
54 Python {py} detected.
54 Python {py} detected.
55 {pip}
55 {pip}
56 """.format(py=sys.version_info, pip=pip_message )
56 """.format(py=sys.version_info, pip=pip_message )
57
57
58 print(error, file=sys.stderr)
58 print(error, file=sys.stderr)
59 sys.exit(1)
59 sys.exit(1)
60
60
61 # At least we're on the python version we need, move on.
61 # At least we're on the python version we need, move on.
62
62
63 from setuptools import setup
63 from setuptools import setup
64
64
65 # Our own imports
65 # Our own imports
66 from setupbase import target_update
66 from setupbase import target_update
67
67
68 from setupbase import (
68 from setupbase import (
69 setup_args,
69 setup_args,
70 check_package_data_first,
70 check_package_data_first,
71 find_data_files,
71 find_data_files,
72 git_prebuild,
72 git_prebuild,
73 install_symlinked,
73 install_symlinked,
74 install_lib_symlink,
74 install_lib_symlink,
75 install_scripts_for_symlink,
75 install_scripts_for_symlink,
76 unsymlink,
76 unsymlink,
77 )
77 )
78
78
79 #-------------------------------------------------------------------------------
79 #-------------------------------------------------------------------------------
80 # Handle OS specific things
80 # Handle OS specific things
81 #-------------------------------------------------------------------------------
81 #-------------------------------------------------------------------------------
82
82
83 if os.name in ('nt','dos'):
83 if os.name in ('nt','dos'):
84 os_name = 'windows'
84 os_name = 'windows'
85 else:
85 else:
86 os_name = os.name
86 os_name = os.name
87
87
88 # Under Windows, 'sdist' has not been supported. Now that the docs build with
88 # Under Windows, 'sdist' has not been supported. Now that the docs build with
89 # Sphinx it might work, but let's not turn it on until someone confirms that it
89 # Sphinx it might work, but let's not turn it on until someone confirms that it
90 # actually works.
90 # actually works.
91 if os_name == 'windows' and 'sdist' in sys.argv:
91 if os_name == 'windows' and 'sdist' in sys.argv:
92 print('The sdist command is not available under Windows. Exiting.')
92 print('The sdist command is not available under Windows. Exiting.')
93 sys.exit(1)
93 sys.exit(1)
94
94
95
95
96 #-------------------------------------------------------------------------------
96 #-------------------------------------------------------------------------------
97 # Things related to the IPython documentation
97 # Things related to the IPython documentation
98 #-------------------------------------------------------------------------------
98 #-------------------------------------------------------------------------------
99
99
100 # update the manuals when building a source dist
100 # update the manuals when building a source dist
101 if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'):
101 if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'):
102
102
103 # List of things to be updated. Each entry is a triplet of args for
103 # List of things to be updated. Each entry is a triplet of args for
104 # target_update()
104 # target_update()
105 to_update = [
105 to_update = [
106 (
106 (
107 "docs/man/ipython.1.gz",
107 "docs/man/ipython.1.gz",
108 ["docs/man/ipython.1"],
108 ["docs/man/ipython.1"],
109 "cd docs/man && python -m gzip --best ipython.1",
109 "cd docs/man && python -m gzip --best ipython.1",
110 ),
110 ),
111 ]
111 ]
112
112
113
113
114 [ target_update(*t) for t in to_update ]
114 [ target_update(*t) for t in to_update ]
115
115
116 #---------------------------------------------------------------------------
116 #---------------------------------------------------------------------------
117 # Find all the packages, package data, and data_files
117 # Find all the packages, package data, and data_files
118 #---------------------------------------------------------------------------
118 #---------------------------------------------------------------------------
119
119
120 data_files = find_data_files()
120 data_files = find_data_files()
121
121
122 setup_args['data_files'] = data_files
122 setup_args['data_files'] = data_files
123
123
124 #---------------------------------------------------------------------------
124 #---------------------------------------------------------------------------
125 # custom distutils commands
125 # custom distutils commands
126 #---------------------------------------------------------------------------
126 #---------------------------------------------------------------------------
127 # imports here, so they are after setuptools import if there was one
127 # imports here, so they are after setuptools import if there was one
128 from setuptools.command.sdist import sdist
128 from setuptools.command.sdist import sdist
129
129
130 setup_args['cmdclass'] = {
130 setup_args['cmdclass'] = {
131 'build_py': \
131 'build_py': \
132 check_package_data_first(git_prebuild('IPython')),
132 check_package_data_first(git_prebuild('IPython')),
133 'sdist' : git_prebuild('IPython', sdist),
133 'sdist' : git_prebuild('IPython', sdist),
134 'symlink': install_symlinked,
134 'symlink': install_symlinked,
135 'install_lib_symlink': install_lib_symlink,
135 'install_lib_symlink': install_lib_symlink,
136 'install_scripts_sym': install_scripts_for_symlink,
136 'install_scripts_sym': install_scripts_for_symlink,
137 'unsymlink': unsymlink,
137 'unsymlink': unsymlink,
138 }
138 }
139
139
140
140
141 #---------------------------------------------------------------------------
141 #---------------------------------------------------------------------------
142 # Handle scripts, dependencies, and setuptools specific things
142 # Handle scripts, dependencies, and setuptools specific things
143 #---------------------------------------------------------------------------
143 #---------------------------------------------------------------------------
144
144
145 # setuptools requirements
145 # setuptools requirements
146
146
147 extras_require = dict(
147 extras_require = dict(
148 parallel=["ipyparallel"],
148 parallel=["ipyparallel"],
149 qtconsole=["qtconsole"],
149 qtconsole=["qtconsole"],
150 doc=["Sphinx>=1.3"],
150 doc=["Sphinx>=1.3"],
151 test=[
151 test=[
152 "pytest",
152 "pytest",
153 "pytest-asyncio",
153 "testpath",
154 "testpath",
154 "pygments",
155 "pygments",
155 ],
156 ],
156 test_extra=[
157 test_extra=[
157 "pytest",
158 "pytest",
158 "testpath",
159 "testpath",
159 "curio",
160 "curio",
160 "matplotlib!=3.2.0",
161 "matplotlib!=3.2.0",
161 "nbformat",
162 "nbformat",
162 "numpy>=1.17",
163 "numpy>=1.17",
163 "pandas",
164 "pandas",
164 "pygments",
165 "pygments",
165 "trio",
166 "trio",
166 ],
167 ],
167 terminal=[],
168 terminal=[],
168 kernel=["ipykernel"],
169 kernel=["ipykernel"],
169 nbformat=["nbformat"],
170 nbformat=["nbformat"],
170 notebook=["notebook", "ipywidgets"],
171 notebook=["notebook", "ipywidgets"],
171 nbconvert=["nbconvert"],
172 nbconvert=["nbconvert"],
172 )
173 )
173
174
174 everything = set(chain.from_iterable(extras_require.values()))
175 everything = set(chain.from_iterable(extras_require.values()))
175 extras_require['all'] = list(sorted(everything))
176 extras_require['all'] = list(sorted(everything))
176
177
177 setup_args["extras_require"] = extras_require
178 setup_args["extras_require"] = extras_require
178
179
179 #---------------------------------------------------------------------------
180 #---------------------------------------------------------------------------
180 # Do the actual setup now
181 # Do the actual setup now
181 #---------------------------------------------------------------------------
182 #---------------------------------------------------------------------------
182
183
183 if __name__ == "__main__":
184 if __name__ == "__main__":
184 setup(**setup_args)
185 setup(**setup_args)
General Comments 0
You need to be logged in to leave comments. Login now