예제 #1
0
def finalizeBatch(batchId=None):
    """ Finalizes given batch - counts duration, test count and result.
        
        :Parameters:
            batchId: id of batch to finalize. If None, tries to load it from environment.
            
        :Return:
            None
    """
    if not batchId:
        try:
            batchId = os.environ[batchuuidEnvOpt]
        except KeyError:
            log.error("BatchId is not defined when finalizeBatch called.")
            return

    batch = BatchRun.objects.get(id=batchId)
    if batch:
        endTime = datetime.datetime.now()
        startTime = batch.startTime
    batch.duration = computeDuration(startTime, endTime)
    tests = TestRun.objects.filter(batchId=batch)
    if tests:
        batch.testCount = tests.count()

        if tests.filter(result=RESULT_SUCCESS).count():
            batch.result = RESULT_SUCCESS
        if tests.filter(result=RESULT_ERROR).count():  #errors
            batch.result = RESULT_ERROR
        elif tests.filter(result=RESULT_FAILURE).count():  #failures
            batch.result = RESULT_FAILURE
        else:  #unknown tests.filter(result=-2).count()
            pass
    else:  #we assume skipped tests as o.k.
        batch.result = RESULT_SUCCESS
        batch.testCount = 0

    batch.hasFinished = True

    batch.save()
예제 #2
0
파일: report.py 프로젝트: snua12/zlomekfs
def finalizeBatch(batchId = None):
    """ Finalizes given batch - counts duration, test count and result.
        
        :Parameters:
            batchId: id of batch to finalize. If None, tries to load it from environment.
            
        :Return:
            None
    """
    if not batchId:
        try:
            batchId = os.environ[batchuuidEnvOpt]
        except KeyError:
            log.error ("BatchId is not defined when finalizeBatch called.")
            return
    
    batch = BatchRun.objects.get(id = batchId)
    if batch:
        endTime = datetime.datetime.now()
        startTime = batch.startTime
    batch.duration = computeDuration(startTime, endTime)
    tests = TestRun.objects.filter (batchId = batch)
    if tests:
        batch.testCount = tests.count()
        
        if tests.filter(result = RESULT_SUCCESS).count():
            batch.result = RESULT_SUCCESS
        if tests.filter(result = RESULT_ERROR).count(): #errors
            batch.result = RESULT_ERROR
        elif tests.filter(result = RESULT_FAILURE).count(): #failures
            batch.result = RESULT_FAILURE
        else: #unknown tests.filter(result=-2).count()
            pass
    else: #we assume skipped tests as o.k.
        batch.result = RESULT_SUCCESS
        batch.testCount = 0
    
    batch.hasFinished = True
    
    batch.save()
예제 #3
0
def generateDefaultRun(batch,
                       test=None,
                       duration=None,
                       name=None,
                       description=None):
    """ Generate TestRun instance according to given arguments. 
        
        :Parameters:
            batch: batch to which test belongs
            test: nose TestCase instance  if run belongs to real test run
                or ContextSuite instance.
                None otherwise (when reporting system errors, etc)
            duration: duration of test. If None, will be computed from test attributes.
            name: name of TestRun. If None, test.__str__ will be used
            description: description of TestRun. If None, test.shortDescription will be used
            
        :Return:
            saved TestRun instance or None
            
        :Raise:
            Exception: if batch is not defined
    """
    if not batch:
        raise Exception("Batch id not defined (%s)" % batch)
    if not test:

        class Fake:
            def __init__(self):
                self.inst = self

            def shortDescripton(self):
                return "Unknown"

        test = Fake()
    run = TestRun()
    run.batchId = batch

    if name and len(name) > 0:
        run.testName = name
    elif test:
        run.testName = str(test)
    else:
        run.testName = "Unknown"

    if description:
        run.description = description
    elif test and hasattr(test, "shortDescription"):
        run.description = test.shortDescription()
    else:
        run.description = "Unknown"

    if hasattr(test, startTimeAttr):
        run.startTime = getattr(test, startTimeAttr)
    else:
        run.startTime = datetime.datetime.now()

    if duration:
        run.duration = duration
    elif hasattr(test, startTimeAttr):
        if hasattr(test, endTimeAttr):
            run.duration = computeDuration(getattr(test, startTimeAttr),
                                           getattr(test, endTimeAttr))
        else:
            run.duration = computeDuration(getattr(test, startTimeAttr),
                                           datetime.datetime.now())
    else:
        run.duration = 0

    return run
예제 #4
0
파일: report.py 프로젝트: snua12/zlomekfs
def generateDefaultRun(batch, test = None, duration = None, name = None,
    description = None):
    """ Generate TestRun instance according to given arguments. 
        
        :Parameters:
            batch: batch to which test belongs
            test: nose TestCase instance  if run belongs to real test run
                or ContextSuite instance.
                None otherwise (when reporting system errors, etc)
            duration: duration of test. If None, will be computed from test attributes.
            name: name of TestRun. If None, test.__str__ will be used
            description: description of TestRun. If None, test.shortDescription will be used
            
        :Return:
            saved TestRun instance or None
            
        :Raise:
            Exception: if batch is not defined
    """
    if not batch:
        raise Exception ("Batch id not defined (%s)" % batch)
    if not test:
        class Fake:
            def __init__(self):
                self.inst = self
                
            def shortDescripton(self):
                return "Unknown"
                
        
        test = Fake()
    run = TestRun()
    run.batchId = batch
    
    if name and len(name) > 0:
        run.testName = name
    elif test:
        run.testName = str(test)
    else:
        run.testName = "Unknown"
        
        
    if description:
        run.description = description
    elif test and hasattr(test, "shortDescription"):
        run.description = test.shortDescription()
    else:
        run.description = "Unknown"
        
    if hasattr(test, startTimeAttr):
        run.startTime = getattr(test, startTimeAttr)
    else:
        run.startTime = datetime.datetime.now()
        
    if duration:
        run.duration = duration
    elif hasattr(test, startTimeAttr):
        if hasattr(test, endTimeAttr):                
            run.duration = computeDuration(getattr(test, startTimeAttr),
                            getattr(test, endTimeAttr))
        else:
            run.duration = computeDuration(getattr(test, startTimeAttr),
                            datetime.datetime.now())
    else:
        run.duration = 0
                            
        
    return run