587
|
1 |
#============================================================================
|
|
2 |
#Name : unittestadditions.py
|
|
3 |
#Part of : Helium
|
|
4 |
|
|
5 |
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
6 |
#All rights reserved.
|
|
7 |
#This component and the accompanying materials are made available
|
|
8 |
#under the terms of the License "Eclipse Public License v1.0"
|
|
9 |
#which accompanies this distribution, and is available
|
|
10 |
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
11 |
#
|
|
12 |
#Initial Contributors:
|
|
13 |
#Nokia Corporation - initial contribution.
|
|
14 |
#
|
|
15 |
#Contributors:
|
|
16 |
#
|
|
17 |
#Description:
|
|
18 |
#===============================================================================
|
588
|
19 |
""" unit test additions"""
|
|
20 |
|
587
|
21 |
|
|
22 |
import logging
|
588
|
23 |
_logger = logging.getLogger('unittestadditions')
|
|
24 |
|
628
|
25 |
# pylint: disable=C0103
|
587
|
26 |
|
|
27 |
class skip(object):
|
|
28 |
""" Skip decorator. The decorated function will only be called
|
|
29 |
if the parameter is true.
|
|
30 |
|
|
31 |
e.g:
|
|
32 |
@skip(True)
|
|
33 |
def test():
|
|
34 |
assert True==False
|
|
35 |
|
|
36 |
"""
|
|
37 |
|
|
38 |
def __init__(self, shouldSkip, returns=None):
|
|
39 |
self.shouldSkip = shouldSkip
|
|
40 |
self.returns = returns
|
|
41 |
|
588
|
42 |
def __call__(self, f_file):
|
|
43 |
""" Returns the function f_file if shouldSkip is False. Else a stub function is returned. """
|
645
|
44 |
def __skiptest(*args, **kargs): # pylint: disable=W0613
|
588
|
45 |
"""skip test"""
|
|
46 |
_logger.warning("Skipping test %s" % f_file.__name__)
|
587
|
47 |
return self.returns
|
|
48 |
if self.shouldSkip:
|
|
49 |
return __skiptest
|
588
|
50 |
return f_file
|
|
51 |
# pylint: enable-msg=C0103
|