configurationengine/source/testautomation/testautomation/testcli.py
changeset 0 2e8eeb919028
equal deleted inserted replaced
-1:000000000000 0:2e8eeb919028
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 
       
    17 
       
    18 from optparse import OptionParser, OptionGroup
       
    19 import os
       
    20 import sys
       
    21 import shutil
       
    22 import unittest
       
    23 
       
    24 def run(suite):
       
    25     parser = OptionParser(version="%%prog %s" % 1.0)
       
    26     parser.add_option("-f","--format",\
       
    27                     dest="format",\
       
    28                     help="The output format of the test results, which can be either stdout or xml file [stdout|xml]. Default is stdout",\
       
    29                     metavar="FORMAT",\
       
    30                     default="stdout")
       
    31     parser.add_option("-o","--output",\
       
    32                     dest="output",\
       
    33                     help="The output directory of xml output. Default is test-results",\
       
    34                     metavar="FOLDER",\
       
    35                     default="test-results")
       
    36 
       
    37     (options, args) = parser.parse_args()
       
    38     results = None
       
    39     if options.format == "stdout":
       
    40         results = unittest.TextTestRunner(verbosity=2).run(suite)
       
    41     elif options.format == "xml":
       
    42         if not os.path.exists(options.output):
       
    43             os.mkdir(options.output)
       
    44         else:
       
    45             shutil.rmtree(options.output)
       
    46             os.mkdir(options.output)
       
    47         runner = unittest.TextTestRunner(None,options.output)#Add support for xmlrunner
       
    48         results = runner.run(suite)
       
    49         print "Output file created %s" % os.path.join(options.output,runner.filename)
       
    50     else:
       
    51         parser.error("Unrecognized output format %s! See --help." % parser.format)
       
    52     
       
    53     if results.errors > 0 or results.failures > 0:
       
    54         return -1
       
    55     
       
    56     
       
    57   
       
    58