def __GetTestCaseName(self): # default value is __main__ ,if we find ,we do not use this stks = inspect.stack() for i in xrange(0, len(stks) - 1): frm = stks[i] mm = inspect.getmodule(frm[0]) fc = frm[0].f_code fn = frm[3] if fn.lower().startswith('test_'): # if we find the test_ case name ,so we should test whether it is the XUnitCase class functions, # if so we return the whole module.class:function format _cls = fc.co_varnames[0] inst = frm[0].f_locals[_cls] # it is the class we search for ,so we return it if issubclass(inst.__class__, XUnitCase): cn = cls.GetClassName(inst.__class__) + ':' + fn return cn # we do not get the name, so we should get the class for i in xrange(0, len(stks) - 1): frm = stks[i] mm = inspect.getmodule(frm[0]) fc = frm[0].f_code fn = frm[3] _cls = fc.co_varnames[0] inst = frm[0].f_locals[_cls] # it is the class we search for ,so we return it if issubclass(inst.__class__, XUnitCase): cn = cls.GetClassName(inst.__class__) return cn # nothing find ,so we should return __main__ return '__main__'
def XUnitsetUp(self): cn = cls.GetClassName(self.__class__) sec = '.' + cn utcfg = xunit.config.XUnitConfig() self._xmlold = utcfg.GetValue(sec, 'xmllog', '') fname = randgen.GenRandomChars(20) self.__fname = fname + '.log' utcfg.SetValue(sec, 'xmllog', self.__fname, 1) self.__fh = open(self.__fname, 'w') return
def test_xmlfilewarn(self): cn = cls.GetClassName(self.__class__) xl = logger.XmlLogger(cn, self.__fh) xl.SetLevel(logger.WARNING_LEVEL) n = randgen.GenRandomNum(100, 1) s = randgen.GenRandomChars(n) xl.Debug(s) vpat = re.compile(s) xl.Flush() v = '' with open(self.__fname, 'r+b') as f: sl = f.readlines() v = ''.join(sl) self.assertTrue(v == '') return
def XUnittearDown(self): if self.__fh: self.__fh.close() del self.__fh self.__fh = None if self.__fname and os.path.isfile(self.__fname): os.remove(self.__fname) self.__fname = None utcfg = xunit.config.XUnitConfig() if self._xmlold: cn = cls.GetClassName(self.__class__) sec = '.' + cn utcfg.SetValue(sec, 'xmllog', self._xmlold, 1) self._xmlold = None return
def test_xmldebug(self): cn = cls.GetClassName(self.__class__) xl = logger.XmlLogger(cn, self.__fh) xl.SetLevel(logger.DEBUG_LEVEL) n = randgen.GenRandomNum(100, 1) s = randgen.GenRandomChars(n) xl.Debug(s) vpat = re.compile(s) v = xl.Flush() self.assertTrue(vpat.search(v)) vpat = re.compile(cn) self.assertTrue(vpat.search(v)) xl.SetLevel(logger.WARNING_LEVEL) n = randgen.GenRandomNum(100, 1) s = randgen.GenRandomChars(n) xl.Debug(s) vpat = re.compile(s) v = xl.Flush() self.assertTrue(v == '') return
def startTest(self, test): if self.__verbose and self.__output > 0: cn = cls.GetClassName(test.__class__) self.__logger.CaseStart(cn + ':' + test._testMethodName) return