On Sat, Nov 26, 2011 at 6:51 PM, Joachim Durchholz <j...@durchholz.org> wrote: > Issue link: http://code.google.com/p/sympy/issues/detail?id=2867 > > The idea here is to have a lambda expression instead of a string. > I.e. instead of >>>> raises(TypeError, "Rational(2)*MyInt") > we want >>>> raises(TypeError, lambda: Rational(2)*MyInt) > > This works very well, except when the code needs to test a statement instead > of an exception. I'd like to hear how to deal with these. > > Here's the full list of remaining cases, grouped by constellation: > > > A) Testing nonassignability: > > sympy/core/tests/test_assumptions.py, line 393: > raises(AttributeError, "x.is_real = False") > > sympy/core/tests/test_containers.py, line 101: > raises(NotImplementedError, "d[5] = 6") # assert immutability >
Can't these be tested with hasattr: >>> l=range(3);t=tuple(l) >>> hasattr(l,'__setitem__') True >>> hasattr(t,'__setitem__') False > sympy/matrices/tests/test_matrices.py, line 1590: > raises(ValueError, "SparseMatrix([[1, 2], [3, 4]])[1, 2, 3] = 4") > > > B) Testing that a wrong import statement fails: > > sympy/core/tests/test_numbers.py, line 538: > raises(ImportError, 'from sympy import Pi') > > For these, can you redirect the output to an IO buffer, kind of like capture in utilities does? Since raises knows (via first arg) what error it is suppose to test, maybe it could use different strategies for these cases. -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.