Beispiel #1
0
 def test_is_var(self):
     for ok in SCALARS + LISTS:
         assert is_var(ok)
         assert is_var(ok + '=', allow_assign_mark=True)
         assert is_var(ok + ' =', allow_assign_mark=True)
     for nok in NOKS:
         assert not is_var(nok)
Beispiel #2
0
    def _unescape_variable_if_needed(self,name):
        if not (isinstance(name,basestring) and len(name) >1):
            raise ValueError
        if name.startswith('\\'):
            name = name[1:]
        elif name[0] in ['$','@'] and name[1] != '{':
            name ='%s{%s}' %(name[0],name[1:])
        if is_var(name):
            return name

        name = '%s{%s}' %(name[0],self.replace_variables(name[2:-1]))
        if is_var(name):
            return name
        raise ValueError
Beispiel #3
0
    def default(self, line):
        '''Run RobotFramework keywordrun_clirun_clis'''
        command = line.strip()

        if not command:
            return
        try:
            u_command = ''
            if sys.version_info > (3, ):
                u_command = command
            else:
                u_command = command.decode("utf-8")
            keyword = KEYWORD_SEP.split(u_command)
            variable_name = keyword[0].rstrip('= ')

            if is_var(variable_name):
                variable_value = self.rf_bi.run_keyword(*keyword[1:])
                self.rf_bi._variables.__setitem__(variable_name,
                                                  variable_value)
                print('< ', variable_name, '=', repr(variable_value))
            else:
                result = self.rf_bi.run_keyword(*keyword)
                if result:
                    print('< ', repr(result))
        except HandlerExecutionFailed as exc:
            print('< keyword: %s' % command)
            print('! %s' % exc.full_message)
        except Exception as exc:
            print('< keyword: %s' % command)
            print('! FAILED: %s' % repr(exc))
Beispiel #4
0
def run_keyword(bi, command):
    """Run a keyword in robotframewrk environment"""
    if not command:
        return
    try:
        u_command = ''
        if sys.version_info > (3, ):
            u_command = command
        else:
            u_command = command.decode(COMMAND_LINE_ENCODING)
        keyword = KEYWORD_SEP.split(u_command)
        variable_name = keyword[0].rstrip('= ')

        if is_var(variable_name):
            variable_value = bi.run_keyword(*keyword[1:])
            bi._variables.__setitem__(variable_name, variable_value)
            print_output('#', '{} = {!r}'.format(variable_name,
                                                 variable_value))
        else:
            result = bi.run_keyword(*keyword)
            if result:
                print_output('<', repr(result))
    except ExecutionFailed as exc:
        print_error('! keyword:', command)
        print_error('!', exc.message)
    except HandlerExecutionFailed as exc:
        print_error('! keyword:', command)
        print_error('!', exc.full_message)
    except Exception as exc:
        print_error('! keyword:', command)
        print_error('! FAILED:', repr(exc))
Beispiel #5
0
    def default(self, line):
        '''Run RobotFramework keywordrun_clirun_clis'''
        command = line.strip()

        if not command:
            return
        try:
            u_command = command.decode("utf-8")
            keyword = KEYWORD_SEP.split(u_command)
            variable_name = keyword[0].rstrip('= ')

            if is_var(variable_name):
                variable_value = self.rf_bi.run_keyword(*keyword[1:])
                self.rf_bi._variables.__setitem__(variable_name,
                                                  variable_value)
                print('< ', variable_name, '=', repr(variable_value))
            else:
                result = self.rf_bi.run_keyword(*keyword)
                if result:
                    print('< ', repr(result))
        except HandlerExecutionFailed as exc:
            print('< keyword: %s' % command)
            print('! %s' % exc.full_message)
        except Exception as exc:
            print('< keyword: %s' % command)
            print('! FAILED: %s' % repr(exc))
Beispiel #6
0
 def _get_assigned_vars(self, content):
     vars = []
     for item in content:
         if not is_var(item.rstrip('= ')):
             break
         vars.append(item)
     return vars
Beispiel #7
0
    def default(self, line):
        '''Run RobotFramework keywordrun_clirun_clis'''
        command = line.strip()

        if not command:
            return
        try:
            if hasattr(command, 'decode'):
                # python 2, convert to unicode
                u_command = command.decode("utf-8")
            else:
                # python 3, strings are unicode by default
                u_command = command

            keyword = KEYWORD_SEP.split(u_command)
            variable_name = keyword[0].rstrip('= ')

            if is_var(variable_name):
                variable_value = self.rf_bi.run_keyword(*keyword[1:])
                self.rf_bi._variables.__setitem__(variable_name,
                                                  variable_value)
                print('< ', variable_name, '=', repr(variable_value))
            else:
                result = self.rf_bi.run_keyword(*keyword)
                if result:
                    print('< ', repr(result))
        except HandlerExecutionFailed as exc:
            print('< keyword: %s' % command)
            print('! %s' % exc.full_message)
        except Exception as exc:
            print('< keyword: %s' % command)
            print('! FAILED: %s' % repr(exc))
 def lex(self, ctx):
     name = self.statement[0]
     values = self.statement[1:]
     if is_var(name.value, allow_assign_mark=True):
         self._valid_variable(name, values)
     else:
         self._invalid_variable(name, values)
     if is_dict_var(name.value, allow_assign_mark=True):
         self._validate_dict_items(values)
def run_keyword(bi, command):
    """Run a keyword in robotframewrk environment"""
    if not command:
        return
    try:
        keyword_args = parse_keyword(command)
        keyword = keyword_args[0]
        args = keyword_args[1:]

        is_comment = keyword.strip().startswith('#')
        if is_comment:
            return

        variable_name = keyword.rstrip('= ')
        if rf_version <= 3.1:
            if is_var(variable_name):
                variable_only = not args
                if variable_only:
                    display_value = ['Log to console', keyword]
                    bi.run_keyword(*display_value)
                else:
                    variable_value = assign_variable(bi,
                                                     variable_name,
                                                     args)
                    print_output('#',
                                 '{} = {!r}'.format(variable_name,
                                                    variable_value))
        else:
            result = bi.run_keyword(keyword, *args)
            if result:
                print_output('<', repr(result))
        elif rf_version >= 3.2:
            if is_variable(variable_name):
                variable_only = not args
                if variable_only:
                    display_value = ['Log to console', keyword]
                    bi.run_keyword(*display_value)
                else:
                    variable_value = assign_variable(bi,
                                                     variable_name,
                                                     args)
                    print_output('#',
                                 '{} = {!r}'.format(variable_name,
                                                    variable_value))
            else:
                result = bi.run_keyword(keyword, *args)
                if result:
                    print_output('<', repr(result))
    except ExecutionFailed as exc:
        print_error('! keyword:', command)
        print_error('!', exc.message)
    except HandlerExecutionFailed as exc:
        print_error('! keyword:', command)
        print_error('!', exc.full_message)
    except Exception as exc:
        print_error('! keyword:', command)
        print_error('! FAILED:', repr(exc))
 def _lex_as_keyword_call(self):
     keyword_seen = False
     for token in self.statement:
         if keyword_seen:
             token.type = Token.ARGUMENT
         elif is_var(token.value, allow_assign_mark=True):
             token.type = Token.ASSIGN
         else:
             token.type = Token.KEYWORD
             keyword_seen = True
Beispiel #11
0
 def _get_assigned_vars(self, content):
     for item in content:
         if not is_var(item.rstrip('= ')):
             return
         yield item
Beispiel #12
0
 def _get_assigned_vars(self, content):
     for item in content:
         if not is_var(item.rstrip('= ')):
             return
         yield item
Beispiel #13
0
 def _is_assign(self, value):
     return (is_var(value)
             or value.endswith('=') and is_var(rstrip(value[:-1])))
 def _get_assign(self, content):
     assign = []
     while content and is_var(content[0].rstrip('= ')):
         assign.append(content.pop(0))
     return assign
Beispiel #15
0
 def _get_veriable_position(self, text):
     if text:
         name = text.split()[0]
         if is_var(name):
             return 0, len(name)
     return 0, 0
Beispiel #16
0
 def _get_assign(self, content):
     assign = []
     while content and is_var(content[0].rstrip('= ')):
         assign.append(content.pop(0))
     return assign
Beispiel #17
0
 def test_is_var(self):
     for ok in SCALARS + LISTS:
         assert is_var(ok)
     for nok in NOKS:
         assert not is_var(nok)
 def test_is_var(self):
     for ok in SCALARS + LISTS:
         assert is_var(ok)
     for nok in NOKS:
         assert not is_var(nok)