Revision: 126 Author: jprantan Date: Mon Jun 28 05:33:00 2010 Log: Added copyright text and removed support from all older RF versions. http://code.google.com/p/robotframework-mabot/source/detail?r=126
Modified: /trunk/src/mabot/utils/robotapi.py ======================================= --- /trunk/src/mabot/utils/robotapi.py Mon Jun 1 03:06:27 2009 +++ /trunk/src/mabot/utils/robotapi.py Mon Jun 28 05:33:00 2010 @@ -1,3 +1,17 @@ +# Copyright 2008 Nokia Siemens Networks Oyj +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import sys try: @@ -6,23 +20,19 @@ from robot.common import UserErrorHandler from robot.running.model import RunnableTestSuite, RunnableTestCase from robot.output.readers import Message - from robot.running import TestSuite as _TestSuite + from robot.running import TestSuite from robot.conf import RobotSettings - from robot.utils import get_timestamp, normalize - from robot.utils import get_elapsed_time as _get_elapsed_time - from robot.running.namespace import Namespace as _NameSpace - from robot.utils import ArgumentParser as _ArgumentParser + from robot.running.namespace import Namespace + from robot.running.context import ExecutionContext + from robot.utils import ArgumentParser, get_timestamp, normalize,\ + elapsed_time_to_string + from robot.utils import get_elapsed_time as _get_elapsed_time from robot import version ROBOT_VERSION = version.get_version() from robot.errors import DataError - if ROBOT_VERSION >= '2.0.3': - from robot.errors import Information - else: - class Information(Exception): - """Used by argument parser with --help or --version""" - if ROBOT_VERSION >= '2.1': - from robot.output.logger import LOGGER - LOGGER.disable_automatic_console_logger() + from robot.errors import Information + from robot.output.logger import LOGGER + LOGGER.disable_automatic_console_logger() except ImportError, error: print """All needed Robot modules could not be imported. Check your Robot installation.""" @@ -30,65 +40,19 @@ sys.exit(1) - -def Namespace(suite, parent): - if ROBOT_VERSION >= '2.1': - return _NameSpace(suite, parent) - else: - return _NameSpace(suite, parent, NoOperation()) - - -def TestSuite(datasources, settings): - if ROBOT_VERSION >= '2.1': - return _TestSuite(datasources, settings) - else: - return _TestSuite(datasources, settings, NoOperation()) - - def RobotTestOutput(suite): return _RobotTestOutput(suite, NoOperation()) - + def get_elapsed_time(start_time, end_time=None, seps=('', ' ', ':', '.')): elapsed = _get_elapsed_time(start_time, end_time, seps) - if ROBOT_VERSION >= '2.1': - from robot.utils import elapsed_time_to_string - elapsed = elapsed_time_to_string(elapsed) - return elapsed - - -class _ArgumentParserFor2_0_2AndOlderRobot(_ArgumentParser): - - def __init__(self, doc, version): - self.doc = doc.replace("<VERSION>", version) - self.version = version - _ArgumentParser.__init__(self, doc) - - def parse_args(self, args, **kwargs): - try: - opts, args = RobotArgParser.parse_args(self, args) - except Exception, err: - raise DataError('[ERROR] %s' % str(err)) - if opts['help']: - raise Information(self.doc) - if opts['version']: - raise Information('Mabot %s' % (self.version)) - if len(args) > 1: - DataError("[ERROR] Only one datasource is allowed.") - return opts, args - - -def ArgumentParser(doc, version, arg_limits): - if ROBOT_VERSION >= '2.0.3': - return _ArgumentParser(doc, version, arg_limits) - else: - return _ArgumentParserFor2_0_2AndOlderRobot(doc, version) + return elapsed_time_to_string(elapsed) class NoOperation: - + def __getattr__(self, name): return self.noop - + def noop(self, *args, **kwargs): - pass + pass
