configurationengine/source/scripts/tests/__init__.py
author terytkon
Thu, 11 Mar 2010 17:04:37 +0200
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
permissions -rw-r--r--
Adding EPL version of configurationengine.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     1
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     2
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     3
# All rights reserved.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     4
# This component and the accompanying materials are made available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     5
# under the terms of "Eclipse Public License v1.0"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     6
# which accompanies this distribution, and is available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     8
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     9
# Initial Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    11
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    12
# Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    13
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    14
# Description: 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    15
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    16
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    17
import unittest, os, sys
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    18
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
SOURCE_ROOT = os.path.normpath(os.path.join(ROOT_PATH, '../..'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
PLUGIN_SOURCE_ROOT = os.path.normpath(os.path.join(SOURCE_ROOT, 'plugins'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
assert os.path.split(SOURCE_ROOT)[1] == 'source'
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
assert os.path.split(PLUGIN_SOURCE_ROOT)[1] == 'plugins'
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
def _setup():
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
    """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
    Set up everything so that running "python cone_tool.py" finds the ConE
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
    and plug-in modules.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
    """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
    sys.path.append(SOURCE_ROOT)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
    sys.path.append(os.path.join(SOURCE_ROOT, 'testautomation'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
    # Import the plugin_utils module from plugins/
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
    sys.path.append(PLUGIN_SOURCE_ROOT)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
    import plugin_utils
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
    del sys.path[-1]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
    # Collect all needed plug-in source directories (all in 'common')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
    plugin_sources = plugin_utils.find_plugin_sources(os.path.join(PLUGIN_SOURCE_ROOT, 'common'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
    plugin_source_paths = [path for path, _ in plugin_sources]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
    paths = []
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
    paths.append(SOURCE_ROOT)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
    paths.extend(plugin_source_paths)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
    os.environ['PYTHONPATH'] = os.environ.get('PYTHONPATH', '') + ';' + ';'.join(paths)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
    # Generate egg-info for the plug-ins if necessary
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
    import build_egg_info
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
    for path in plugin_source_paths:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
        build_egg_info.generate_egg_info(path)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
_setup()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
# Find all unittest_*.py files in this folder
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    55
import re
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    56
__all__ = filter(lambda name: re.match(r'^unittest_.*\.py$', name) != None, os.listdir(ROOT_PATH))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    57
# Strip .py endings
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    58
__all__ = map(lambda name: name[:-3], __all__)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    59
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    60
def collect_suite():  
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    61
    suite = unittest.TestSuite()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    62
    for test_module in __all__:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    63
        # Load the test module dynamically and add it to the test suite
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    64
        module = __import__(test_module)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    65
        suite.addTests(unittest.TestLoader().loadTestsFromModule(module))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    66
    return suite
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    67
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    68
def runtests():
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    69
    unittest.TextTestRunner(verbosity=2).run(collect_suite())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    70
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    71
if __name__ == '__main__':
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    72
    runtests()