##// END OF EJS Templates
Fixing a nasty bug in test_frontend.py that was leading to all sorts...
Fixing a nasty bug in test_frontend.py that was leading to all sorts of weird problems with our test suite like random test errors and unhandled errors in Deferreds. There are 3 problems with this test module: 1. Doesn't use twisted.trial.unittest.TestCase as a base class 2. Test methods don't return Deferreds 3. One test method actually has an unhandled error in a Deferred The only thing I have don't is put a @skip decorator on test_error_callback_added_to_execute to hide 3. All of these things still need to be fixed though. But our tests now pass.

File last commit:

r1577:44a45452
r1614:9dcfcfc5
Show More
test_refs.py
185 lines | 4.1 KiB | text/x-python | PythonLexer
Fernando Perez
Checkpoint with more tests working....
r1420 # Module imports
# Std lib
import inspect
# Third party
# Our own
Fernando Perez
Complete first pass on testing system. All tests pass on my box. Whew....
r1435 from IPython.testing import decorators as dec
Fernando Perez
Checkpoint with more tests working....
r1420
#-----------------------------------------------------------------------------
# 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.im_func
else:
raise TypeError, 'arg is not a Python function'
args, varargs, varkw = inspect.getargs(func_obj.func_code)
return args, varargs, varkw, func_obj.func_defaults
#-----------------------------------------------------------------------------
# Testing functions
def test_trivial():
"""A trivial passing test."""
pass
@dec.skip
def test_deliberately_broken():
"""A deliberately broken test - we want to skip this one."""
1/0
Fernando Perez
Fix error in test decorator.
r1577 @dec.skip('foo')
def test_deliberately_broken2():
"""Another deliberately broken test - we want to skip this one."""
1/0
Fernando Perez
Checkpoint with more tests working....
r1420
# Verify that we can correctly skip the doctest for a function at will, but
# that the docstring itself is NOT destroyed by the decorator.
@dec.skip_doctest
def doctest_bad(x,y=1,**k):
"""A function whose doctest we need to skip.
>>> 1+1
3
"""
Fernando Perez
Complete first pass on testing system. All tests pass on my box. Whew....
r1435 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
# Doctest skipping should work for class methods too
class foo(object):
"""Foo
Example:
>>> 1+1
2
"""
@dec.skip_doctest
def __init__(self,x):
"""Make a foo.
Example:
>>> f = foo(3)
junk
"""
print 'Making a foo.'
self.x = x
@dec.skip_doctest
def bar(self,y):
"""Example:
>>> f = foo(3)
>>> f.bar(0)
boom!
>>> 1/0
bam!
"""
return 1/y
def baz(self,y):
"""Example:
>>> f = foo(3)
Making a foo.
>>> f.baz(3)
True
"""
return self.x==y
Fernando Perez
Checkpoint with more tests working....
r1420
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__
assert check==val,"doctest_bad docstrings don't match"
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,)
def doctest_run():
"""Test running a trivial script.
In [13]: run simplevars.py
x is: 1
"""
#@dec.skip_doctest
def doctest_runvars():
"""Test that variables defined in scripts get loaded correcly via %run.
In [13]: run simplevars.py
x is: 1
In [14]: x
Out[14]: 1
"""
def doctest_ivars():
"""Test that variables defined interactively are picked up.
In [5]: zz=1
In [6]: zz
Out[6]: 1
"""
@dec.skip_doctest
def doctest_refs():
Fernando Perez
Local checkpoint of changes to testing machinery. Work in progress.
r1403 """DocTest reference holding issues when running scripts.
In [32]: run show_refs.py
c referrers: [<type 'dict'>]
In [33]: map(type,gc.get_referrers(c))
Out[33]: [<type 'dict'>]
"""