buildframework/helium/sf/python/pythoncore/lib/unittestadditions.py
author wbernard
Tue, 27 Apr 2010 08:33:08 +0300
changeset 587 85df38eb4012
child 588 c7c26511138f
permissions -rw-r--r--
helium_9.0-a7879c935424
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
#============================================================================ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
#Name        : unittestadditions.py 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Description:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
logger = logging.getLogger('unittestadditions')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
class skip(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
    """ Skip decorator. The decorated function will only be called
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
        if the parameter is true.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
         
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
        e.g: 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
        @skip(True)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
        def test():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
           assert True==False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
               
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
    def __init__(self, shouldSkip, returns=None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
        self.shouldSkip = shouldSkip
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
        self.returns = returns
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
    def __call__(self, f):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
        """ Returns the function f if  shouldSkip is False. Else a stub function is returned. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
        def __skiptest(*args, **kargs):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
            logger.warning("Skipping test %s" % f.__name__)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
            return self.returns
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
        if self.shouldSkip:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
            return __skiptest
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
        return f