##// END OF EJS Templates
Try to fix some of current failures....
Try to fix some of current failures. See error found in CI below. Hopefully this fixes it. There are manycomplexity, we need to make sure the loop has no task after each tests, so we need to close and restore the subprocess watcher. We make it a context manager and provide a decorator. ====================================================================== ERROR: IPython.core.tests.test_magic.test_script_out ---------------------------------------------------------------------- Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/nose/case.py", line 198, in runTest self.test(*self.arg) File "/home/runner/work/ipython/ipython/IPython/testing/decorators.py", line 223, in skipper_func return f(*args, **kwargs) File "/home/runner/work/ipython/ipython/IPython/core/tests/test_magic.py", line 953, in test_script_out ip.run_cell_magic("script", "--out output sh", "echo 'hi'") File "/home/runner/work/ipython/ipython/IPython/core/interactiveshell.py", line 2417, in run_cell_magic result = fn(*args, **kwargs) File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) File "/home/runner/work/ipython/ipython/IPython/core/magic.py", line 187, in <lambda> call = lambda f, *a, **k: f(*a, **k) File "/home/runner/work/ipython/ipython/IPython/core/magics/script.py", line 216, in shebang stdin=asyncio.subprocess.PIPE, File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete return future.result() File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/asyncio/subprocess.py", line 217, in create_subprocess_exec stderr=stderr, **kwds) File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/asyncio/base_events.py", line 1544, in subprocess_exec bufsize, **kwargs) File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/asyncio/unix_events.py", line 193, in _make_subprocess_transport self._child_watcher_callback, transp) File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/asyncio/unix_events.py", line 941, in add_child_handler "Cannot add child handler, " RuntimeError: Cannot add child handler, the child watcher does not have a loop attached

File last commit:

r25097:24314829
r26854:25f92b99
Show More
test_decorators.py
164 lines | 3.8 KiB | text/x-python | PythonLexer
"""Tests for the decorators we've created for IPython.
"""
# Module imports
# Std lib
import inspect
import sys
# Third party
import nose.tools as nt
# Our own
from IPython.testing import decorators as dec
#-----------------------------------------------------------------------------
# Utilities
# Note: copied from OInspect, kept here so the testing stuff doesn't create
# circular dependencies and is easier to reuse.
def getargspec(obj):
"""Get the names and default values of a function's arguments.
A tuple of four things is returned: (args, varargs, varkw, defaults).
'args' is a list of the argument names (it may contain nested lists).
'varargs' and 'varkw' are the names of the * and ** arguments or None.
'defaults' is an n-tuple of the default values of the last n arguments.
Modified version of inspect.getargspec from the Python Standard
Library."""
if inspect.isfunction(obj):
func_obj = obj
elif inspect.ismethod(obj):
func_obj = obj.__func__
else:
raise TypeError('arg is not a Python function')
args, varargs, varkw = inspect.getargs(func_obj.__code__)
return args, varargs, varkw, func_obj.__defaults__
#-----------------------------------------------------------------------------
# Testing functions
@dec.as_unittest
def trivial():
"""A trivial test"""
pass
@dec.skip()
def test_deliberately_broken():
"""A deliberately broken test - we want to skip this one."""
1/0
@dec.skip('Testing the skip decorator')
def test_deliberately_broken2():
"""Another deliberately broken test - we want to skip this one."""
1/0
# Verify that we can correctly skip the doctest for a function at will, but
# that the docstring itself is NOT destroyed by the decorator.
def doctest_bad(x,y=1,**k):
"""A function whose doctest we need to skip.
>>> 1+1
3
"""
print('x:',x)
print('y:',y)
print('k:',k)
def call_doctest_bad():
"""Check that we can still call the decorated functions.
>>> doctest_bad(3,y=4)
x: 3
y: 4
k: {}
"""
pass
def test_skip_dt_decorator():
"""Doctest-skipping decorator should preserve the docstring.
"""
# Careful: 'check' must be a *verbatim* copy of the doctest_bad docstring!
check = """A function whose doctest we need to skip.
>>> 1+1
3
"""
# Fetch the docstring from doctest_bad after decoration.
val = doctest_bad.__doc__
nt.assert_equal(check,val,"doctest_bad docstrings don't match")
# Doctest skipping should work for class methods too
class FooClass(object):
"""FooClass
Example:
>>> 1+1
2
"""
def __init__(self,x):
"""Make a FooClass.
Example:
>>> f = FooClass(3)
junk
"""
print('Making a FooClass.')
self.x = x
def bar(self,y):
"""Example:
>>> ff = FooClass(3)
>>> ff.bar(0)
boom!
>>> 1/0
bam!
"""
return 1/y
def baz(self,y):
"""Example:
>>> ff2 = FooClass(3)
Making a FooClass.
>>> ff2.baz(3)
True
"""
return self.x==y
def test_skip_dt_decorator2():
"""Doctest-skipping decorator should preserve function signature.
"""
# Hardcoded correct answer
dtargs = (['x', 'y'], None, 'k', (1,))
# Introspect out the value
dtargsr = getargspec(doctest_bad)
assert dtargsr==dtargs, \
"Incorrectly reconstructed args for doctest_bad: %s" % (dtargsr,)
@dec.skip_linux
def test_linux():
nt.assert_false(sys.platform.startswith('linux'),"This test can't run under linux")
@dec.skip_win32
def test_win32():
nt.assert_not_equal(sys.platform,'win32',"This test can't run under windows")
@dec.skip_osx
def test_osx():
nt.assert_not_equal(sys.platform,'darwin',"This test can't run under osx")