Am 26.11.2011 15:02, schrieb Chris Smith:
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
If that's what these cases are supposed to test, I'm all fine.
sympy/matrices/tests/test_matrices.py, line 1590:
raises(ValueError, "SparseMatrix([[1, 2], [3, 4]])[1, 2, 3] = 4")
Hm. I now see that I didn't see before: the three tests raise different
exceptions, AttributeError, NotImplementedError, and ValueError.
I'm not sure how to deal with that, or whether it's a relevant
difference at all.
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?
That would be possible, but simply rewriting the test as
try:
from sympy import Pi
okay = false
catch ImportError e
okay = True
if ! okay:
raise "importing Pi should have raised an ImportError"
sounds like less of a hassle. After all, there is just a single test of
this kind - unless there are going to be more of this type, anything
elaborate would probably be overkill.
Since raises knows (via first arg) what error it is suppose to test,
maybe it could use different strategies for these cases.
That decision can already be made by inspecting the type of the second
parameter: if it's callable, just call it inside a try...
--
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.