Ejemplo n.º 1
0
    def __init__(self, usage, name=None, version=None, arg_limits=None,
                 validator=None, env_options=None, auto_help=True,
                 auto_version=True, auto_pythonpath='DEPRECATED',
                 auto_argumentfile=True):
        """Available options and tool name are read from the usage.

        Tool name is got from the first row of the usage. It is either the
        whole row or anything before first ' -- '.
        """
        if not usage:
            raise FrameworkError('Usage cannot be empty')
        self.name = name or usage.splitlines()[0].split(' -- ')[0].strip()
        self.version = version or get_full_version()
        self._usage = usage
        self._arg_limit_validator = ArgLimitValidator(arg_limits)
        self._validator = validator
        self._auto_help = auto_help
        self._auto_version = auto_version
        # TODO: Change DeprecationWarning to more loud UserWarning in RF 5.1.
        if auto_pythonpath == 'DEPRECATED':
            auto_pythonpath = False
        else:
            warnings.warn("ArgumentParser option 'auto_pythonpath' is deprecated "
                          "since Robot Framework 5.0.", DeprecationWarning)
        self._auto_pythonpath = auto_pythonpath
        self._auto_argumentfile = auto_argumentfile
        self._env_options = env_options
        self._short_opts = ''
        self._long_opts = []
        self._multi_opts = []
        self._flag_opts = []
        self._short_to_long = {}
        self._expected_args = ()
        self._create_options(usage)
Ejemplo n.º 2
0
 def _send_version(self):
     robot_version = 'Robot Framework ' + version.get_full_version()
     info = {'cmd_line': ' '.join(sys.argv), 
             'python' : sys.version, 
             'robot' : robot_version, 
             'protocol' : self.RED_AGENT_PROTOCOL_VERSION}
     self._send_to_server(AgentEventMessage.VERSION, info)
Ejemplo n.º 3
0
    def __init__(self, usage, name=None, version=None, arg_limits=None,
                 validator=None, env_options=None, auto_help=True,
                 auto_version=True, auto_pythonpath=True,
                 auto_argumentfile=True):
        """Available options and tool name are read from the usage.

        Tool name is got from the first row of the usage. It is either the
        whole row or anything before first ' -- '.
        """
        if not usage:
            raise FrameworkError('Usage cannot be empty')
        self.name = name or usage.splitlines()[0].split(' -- ')[0].strip()
        self.version = version or get_full_version()
        self._usage = usage
        self._arg_limit_validator = ArgLimitValidator(arg_limits)
        self._validator = validator
        self._auto_help = auto_help
        self._auto_version = auto_version
        self._auto_pythonpath = auto_pythonpath
        self._auto_argumentfile = auto_argumentfile
        self._env_options = env_options
        self._short_opts = ''
        self._long_opts = []
        self._multi_opts = []
        self._flag_opts = []
        self._short_to_long = {}
        self._expected_args = ()
        self._create_options(usage)
Ejemplo n.º 4
0
    def save_environment(self):
        environment = {}
        environment['id'] = 'Robot Framework'
        environment['name'] = socket.getfqdn()
        environment['url'] = 'http://' + socket.getfqdn() + ':8000'
        included_args = self.AllureProperties.get_property(
            'robot.cli.arguments.included')
        rf_args = sys.argv[1:]
        if included_args:
            rf_args = []
            for index, arg in enumerate(sys.argv):
                if arg in included_args:
                    rf_args.append(sys.argv[index])
                    if index < len(
                            sys.argv) and not sys.argv[index +
                                                       1].startswith('-'):
                        rf_args.append(sys.argv[index + 1])
        env_dict = (\
                    {'Robot Framework Full Version': get_full_version()},\
                    {'Robot Framework Version': get_version()},\
                    {'Interpreter': get_interpreter()},\
                    {'Python version': sys.version.split()[0]},\
                    {'Allure Adapter version': VERSION},\
                    {'Robot Framework CLI Arguments': rf_args},\
                    {'Robot Framework Hostname': socket.getfqdn()},\
                    {'Robot Framework Platform': sys.platform}\
                    )

        for key in env_dict:
            self.AllureImplc.environment.update(key)

        self.AllureImplc.logdir = self.AllureProperties.get_property(
            'allure.cli.logs.xml')
        self.AllureImplc.store_environment(environment)
Ejemplo n.º 5
0
def _get_robot_version():
    try:
        import robot
    except ImportError:
        return None
    from robot import version
    return 'Robot Framework ' + version.get_full_version()
Ejemplo n.º 6
0
def _get_robot_version():
    try:
        import robot
    except ImportError:
        return None
    from robot import version
    return 'Robot Framework ' + version.get_full_version()
Ejemplo n.º 7
0
    def __init__(self, usage, name=None, version=None, arg_limits=None,
                 validator=None, auto_help=True, auto_version=True,
                 auto_escape=True, auto_pythonpath=True, auto_argumentfile=True):
        """Available options and tool name are read from the usage.

        Tool name is got from the first row of the usage. It is either the
        whole row or anything before first ' -- '.
        """
        if not usage:
            raise FrameworkError('Usage cannot be empty')
        self.name = name or usage.splitlines()[0].split(' -- ')[0].strip()
        self.version = version or get_full_version()
        self._usage = usage
        self._arg_limit_validator = ArgLimitValidator(arg_limits)
        self._validator = validator
        self._auto_help = auto_help
        self._auto_version = auto_version
        self._auto_escape = auto_escape
        self._auto_pythonpath = auto_pythonpath
        self._auto_argumentfile = auto_argumentfile
        self._short_opts = ''
        self._long_opts = []
        self._multi_opts = []
        self._toggle_opts = []
        self._names = []
        self._short_to_long = {}
        self._expected_args = ()
        self._create_options(usage)
Ejemplo n.º 8
0
 def _get_writer(self, path, rpa, generator):
     if not path:
         return NullMarkupWriter()
     writer = XmlWriter(path, write_empty=False, usage='output')
     writer.start('robot', {'generator': get_full_version(generator),
                            'generated': get_timestamp(),
                            'rpa': 'true' if rpa else 'false'})
     return writer
 def _get_writer(self, path, generator):
     try:
         writer = utils.XmlWriter(path)
     except:
         raise DataError("Opening output file '%s' for writing failed: %s"
                         % (path, utils.get_error_message()))
     writer.start('robot', {'generator': get_full_version(generator),
                            'generated': utils.get_timestamp()})
     return writer
Ejemplo n.º 10
0
 def _send_version(self):
     from robot import version
     robot_version = 'Robot Framework ' + version.get_full_version()
     info = {
         'python': sys.version,
         'robot': robot_version,
         'protocol': self.RED_AGENT_PROTOCOL_VERSION
     }
     self._send_to_server('version', info)
Ejemplo n.º 11
0
 def _get_writer(self, path, generator):
     if not path:
         return NullMarkupWriter()
     try:
         writer = XmlWriter(path, encoding='UTF-8', write_empty=False)
     except EnvironmentError as err:
         raise DataError("Opening output file '%s' failed: %s" %
                         (path, err.strerror))
     writer.start('robot', {'generator': get_full_version(generator),
                            'generated': get_timestamp()})
     return writer
 def _get_writer(self, path, generator):
     if not path:
         return NullMarkupWriter()
     try:
         writer = XmlWriter(path, encoding='UTF-8')
     except EnvironmentError as err:
         raise DataError("Opening output file '%s' failed: %s" %
                         (path, err.strerror))
     writer.start('robot', {'generator': get_full_version(generator),
                            'generated': get_timestamp()})
     return writer
Ejemplo n.º 13
0
 def _use_template(self, outfile, template, title, background=None):
     ttuple = time.localtime()
     str_time = utils.format_time(ttuple, daytimesep='&nbsp;', gmtsep='&nbsp;')
     int_time = long(time.mktime(ttuple))
     elapsed_time = utils.elapsed_time_to_string(self.suite.elapsedtime)
     namespace = Namespace(gentime_str=str_time,
                           gentime_int=int_time,
                           elapsed_time=elapsed_time,
                           version=get_full_version(self._generator),
                           suite=self.suite,
                           title=title,
                           background=background)
     Template(template=template).generate(namespace, outfile)
Ejemplo n.º 14
0
    def __init__(self, path, log_level='TRACE', rpa=False, generator='Robot'):
        if not jsonstreams:
            raise DataError('Using the JSON output format requires the '
                            'jsonstreams module to be installed. Typically '
                            'you can install it by running '
                            '`pip install jsonstreams`.')

        self._log_message_is_logged = IsLogged(log_level)
        self._error_message_is_logged = IsLogged('WARN')
        self._path = path

        # Setup the JSON data to store before writing the file
        self._data = {
            'rpa': rpa is not None,
            'generator': get_full_version(generator),
            'generated': get_timestamp()
        }
        self._errors = []

        # Setup stacks
        self._item_stack = list()

        # We need to keep track of the active suite, test, and body item
        self._suite = None
        self._body = None
        self._body_item = None
        self._test = None
        self._errors_element = None

        # We need to be able to track the type of item being processed
        # at any moment
        self._item_type = None

        self._root = jsonstreams.Stream(jsonstreams.Type.object,
                                        filename=self._path)
        self._root.write('rpa', rpa is not None)
        self._root.write('generator', get_full_version(generator))
        self._root.write('generated', get_timestamp())
Ejemplo n.º 15
0
 def _use_template(self, outfile, template, title, background=None):
     ttuple = time.localtime()
     str_time = utils.format_time(ttuple,
                                  daytimesep='&nbsp;',
                                  gmtsep='&nbsp;')
     int_time = long(time.mktime(ttuple))
     elapsed_time = utils.elapsed_time_to_string(self.suite.elapsedtime)
     namespace = Namespace(gentime_str=str_time,
                           gentime_int=int_time,
                           elapsed_time=elapsed_time,
                           version=get_full_version(self._generator),
                           suite=self.suite,
                           title=title,
                           background=background)
     Template(template=template).generate(namespace, outfile)
Ejemplo n.º 16
0
 def __init__(self,
              path,
              log_level='TRACE',
              split_level=-1,
              generator='Robot'):
     self._namegen = utils.FileNameGenerator(path)
     self._log_message_is_logged = IsLogged(log_level)
     self._error_is_logged = IsLogged('WARN')
     self._writer = None
     self._writer_args = (path, {
         'generator': get_full_version(generator),
         'generated': utils.get_timestamp()
     })
     self._index_writer = None
     self._split_level = split_level
     self._suite_level = 0
     self._errors = []
Ejemplo n.º 17
0
class XmlLogger(object):

    def __init__(self, path, log_level='TRACE', generator='Robot'):
        self._log_message_is_logged = IsLogged(log_level)
        self._error_message_is_logged = IsLogged('WARN')
        self._writer = self._get_writer(path, generator)
        self._errors = []

    def _get_writer(self, path, generator):
        if path == 'NONE':
            return NullMarkupWriter()
        try:
            writer = XmlWriter(path, encoding='UTF-8')
        except EnvironmentError, err:
            raise DataError("Opening output file '%s' failed: %s" %
                            (path, err.strerror))
        writer.start('robot', {'generator': get_full_version(generator),
                               'generated': get_timestamp()})
        return writer
Ejemplo n.º 18
0
def serialize_test_doc(suite, outpath, title):
    outfile = open(outpath, 'w')
    serializer = TestdocSerializer(outfile, suite)
    ttuple = time.localtime()
    str_time = utils.format_time(ttuple, daytimesep='&nbsp;', gmtsep='&nbsp;')
    int_time = long(time.mktime(ttuple))
    if title:
        title = title.replace('_', ' ')
    else:
        title = 'Documentation for %s' % suite.name
    namespace = Namespace(gentime_str=str_time,
                          gentime_int=int_time,
                          version=version.get_full_version('testdoc.py'),
                          suite=suite,
                          title=title)
    Template(template=templates.LOG).generate(namespace, outfile)
    suite.serialize(serializer)
    outfile.write('</body>\n</html>\n')
    outfile.close()
    def save_environment(self):
        environment = {}    
        environment['id'] = 'Robot Framework'
        environment['name'] = socket.getfqdn()
        environment['url']= 'http://'+socket.getfqdn()+':8000'
        
        env_dict = (\
                    {'Robot Framework Full Version': get_full_version()},\
                    {'Robot Framework Version': get_version()},\
                    {'Interpreter': get_interpreter()},\
                    {'Python version': sys.version.split()[0]},\
                    {'Allure Adapter version': VERSION},\
                    {'Robot Framework CLI Arguments': sys.argv[1:]},\
                    {'Robot Framework Hostname': socket.getfqdn()},\
                    {'Robot Framework Platform': sys.platform}\
                    )

        for key in env_dict:
            self.AllureImplc.environment.update(key)
        
        self.AllureImplc.logdir = self.AllureProperties.get_property('allure.cli.logs.xml')
        self.AllureImplc.store_environment(environment)
Ejemplo n.º 20
0
    def close(self): 

        environment = {}    
        environment['id'] = 'Robot Framework'
        environment['name'] = socket.getfqdn()
        environment['url']= 'http://'+socket.getfqdn()+':8000'
        
        env_dict = (\
                    {'Robot Framework Full Version': get_full_version()},\
                    {'Robot Framework Version': get_version()},\
                    {'Interpreter': get_interpreter()},\
                    {'Python version': sys.version.split()[0]},\
                    {'Allure Adapter version': VERSION},\
                    {'Robot Framework CLI Arguments': sys.argv[1:]},\
                    {'Robot Framework Hostname': socket.getfqdn()},\
                    {'Robot Framework Platform': sys.platform}\
                    )

        for key in env_dict:
            self.AllureImplc.environment.update(key)
        self.AllureImplc.store_environment(environment)        

        # store the Allure properties
        #
        with self.AllureImplc._attachfile('allure.properties') as f:

            li = self.AllureProperties
            lilen = int(len(self.AllureProperties))
            
            for i in range(lilen):
                if i < len(li):
                    key = list(li[i].keys())[0]
                    value = list(li[i].values())[0]
                    f.write(key+'='+value+'\n')
    
        f.close()
        return
Ejemplo n.º 21
0
 def write(self, line):
     version = get_full_version('Robot Framework')
     self._html_writer.start('meta', {'name': 'Generator', 'content': version})
Ejemplo n.º 22
0
 def test_print_version_when_version_not_set(self):
     ap = ArgumentParser(' --version', name='Kekkonen')
     msg = assert_raises(Information, ap.parse_args, ['--version'])
     assert_equals(unicode(msg), 'Kekkonen %s' % get_full_version())
Ejemplo n.º 23
0
 def write(self, line):
     version = get_full_version('Robot Framework')
     self._html_writer.start('meta', {
         'name': 'Generator',
         'content': version
     })
 def test_print_version_when_version_not_set(self):
     ap = ArgumentParser(' --version', name='Kekkonen')
     msg = assert_raises(Information, ap.parse_args, ['--version'])
     assert_equals(unicode(msg), 'Kekkonen %s' % get_full_version())
 def _write_meta_generator(self):
     self._write('<meta name="Generator" content="%s">\n'
                 % get_full_version('Robot Framework'))