buildframework/helium/sf/python/pythoncore/lib/unittestadditions.py
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 645 b8d81fa19e7d
permissions -rw-r--r--
helium_11.0.0-e00f171ca185

#============================================================================ 
#Name        : unittestadditions.py 
#Part of     : Helium 

#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
#All rights reserved.
#This component and the accompanying materials are made available
#under the terms of the License "Eclipse Public License v1.0"
#which accompanies this distribution, and is available
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
#
#Initial Contributors:
#Nokia Corporation - initial contribution.
#
#Contributors:
#
#Description:
#===============================================================================
""" unit test additions"""


import logging
_logger = logging.getLogger('unittestadditions')

# pylint: disable=C0103

class skip(object):
    """ Skip decorator. The decorated function will only be called
        if the parameter is true.
         
        e.g: 
        @skip(True)
        def test():
           assert True==False
               
    """
    
    def __init__(self, shouldSkip, returns=None):
        self.shouldSkip = shouldSkip
        self.returns = returns

    def __call__(self, f_file):
        """ Returns the function f_file if  shouldSkip is False. Else a stub function is returned. """
        def __skiptest(*args, **kargs):
            """skip test"""
            _logger.warning("Skipping test %s" % f_file.__name__)
            return self.returns
        if self.shouldSkip:
            return __skiptest
        return f_file
# pylint: enable-msg=C0103