Added a warning when constructing a Matrix without bracket + test modified
[sympy.git] / sympy / utilities / pytest.py
blobf2594061386b460cdef8209031250b18e76e635c
1 """py.test hacks to support XFAIL/XPASS"""
3 # XXX this should be integrated into py.test
4 # XXX but we can't force everyone to install py-lib trunk
6 # tested with py-lib 0.9.0
7 from py.__.test.outcome import Outcome, Passed, Failed, Skipped
8 from py.__.test.terminal.terminal import TerminalSession
9 from time import time as now
11 __all__ = ['XFAIL']
13 class XFail(Outcome):
14 pass
16 class XPass(Outcome):
17 pass
19 TerminalSession.typemap[XFail] = 'f'
20 TerminalSession.typemap[XPass] = 'X'
22 TerminalSession.namemap[XFail] = 'XFAIL'
23 TerminalSession.namemap[XPass] = '*** XPASS ***'
26 def footer(self, colitems):
27 super(TerminalSession, self).footer(colitems)
28 self.endtime = now()
29 self.out.line()
30 self.skippedreasons()
31 self.failures()
32 self.xpasses()
33 self.summaryline()
36 def xpasses(self):
37 """report unexpectedly passed tests"""
38 texts = {}
39 for colitem, outcome in self.getitemoutcomepairs(XPass):
40 raisingtb = self.getlastvisible(outcome.excinfo.traceback)
41 fn = raisingtb.frame.code.path
42 lineno = raisingtb.lineno
43 #d = texts.setdefault(outcome.excinfo.exconly(), {})
44 d = texts.setdefault(outcome.msg, {})
45 d[(fn,lineno)] = outcome
47 if texts:
48 self.out.line()
49 self.out.sep('_', '*** XPASS ***')
50 for text, dict in texts.items():
51 #for (fn, lineno), outcome in dict.items():
52 # self.out.line('Skipped in %s:%d' %(fn, lineno+1))
53 #self.out.line("reason: %s" % text)
54 self.out.line("%s" % text)
55 self.out.line()
57 def summaryline(self):
58 outlist = []
59 sum = 0
60 for typ in Passed, XPass, XFail, Failed, Skipped:
61 l = self.getitemoutcomepairs(typ)
62 if l:
63 outlist.append('%d %s' % (len(l), typ.__name__.lower()))
64 sum += len(l)
65 elapsed = self.endtime-self.starttime
66 status = "%s" % ", ".join(outlist)
67 self.out.sep('=', 'tests finished: %s in %4.2f seconds' %
68 (status, elapsed))
70 # SymPy specific
71 if self.getitemoutcomepairs(Failed):
72 self.out.line('DO *NOT* COMMIT!')
74 TerminalSession.footer = footer
75 TerminalSession.xpasses = xpasses
76 TerminalSession.summaryline = summaryline
78 def XFAIL(func):
79 """XFAIL decorator"""
80 def func_wrapper():
81 try:
82 func()
83 except Outcome:
84 raise # pass-through test outcome
85 except:
86 raise XFail('XFAIL: %s' % func.func_name)
87 else:
88 raise XPass('XPASS: %s' % func.func_name)
90 return func_wrapper