Ejemplo n.º 1
0
    def add_tag(self, tag_to_tests):
        """ Append a tag with associated tests to the list.

        This method associates the internal model data with the GUI. While the
        sort order of the GUI can change at any time, the order of the data in
        the model does not. The entry in the model is referenced by a new id
        generated by wx.NewId(). This prevents overwriting entries when
        combining delete and insert statements.

        Args:
            index: An int marking the position to insert the row at.
            tag_to_tests: A tuple mapping tests(list, index 0) to a
                          tag(str, index 1).

        Returns:
            An int indicating the entry in the model so that it can be
            associated with the sorting algorithm for example.
        """

        model_index = wx.NewId()
        position = self.GetItemCount()
        self._clientData[model_index] = tag_to_tests
        if wx.VERSION >= (3, 0, 3, ''):  # DEBUG wxPhoenix
            self.InsertItem(position, unicode(tag_to_tests[1]))
            self.SetItem(position, 1, str(len(tag_to_tests[0])))
        else:
            self.InsertStringItem(position, unicode(tag_to_tests[1]))
            self.SetStringItem(position, 1, str(len(tag_to_tests[0])))
        # associate the model with the GUI
        self.SetItemData(position, model_index)
        return model_index
Ejemplo n.º 2
0
    def add_tag(self, tag_to_tests):
        """ Append a tag with associated tests to the list.

        This method associates the internal model data with the GUI. While the
        sort order of the GUI can change at any time, the order of the data in
        the model does not. The entry in the model is referenced by a new id
        generated by wx.NewId(). This prevents overwriting entries when
        combining delete and insert statements.

        Args:
            index: An int marking the position to insert the row at.
            tag_to_tests: A tuple mapping tests(list, index 0) to a
                          tag(str, index 1).

        Returns:
            An int indicating the entry in the model so that it can be
            associated with the sorting algorithm for example.
        """

        model_index = wx.NewId()
        position = self.GetItemCount()
        self._clientData[model_index] = tag_to_tests
        if wx.VERSION >= (3, 0, 3, ''):  # DEBUG wxPhoenix
            self.InsertItem(position, unicode(tag_to_tests[1]))
            self.SetItem(position, 1, str(len(tag_to_tests[0])))
        else:
            self.InsertStringItem(position, unicode(tag_to_tests[1]))
            self.SetStringItem(position, 1, str(len(tag_to_tests[0])))
        # associate the model with the GUI
        self.SetItemData(position, model_index)
        return model_index
Ejemplo n.º 3
0
 def _fetch_lib(self, name, arguments, cursor):
     t = cursor.execute(
         'select max(last_updated) from libraries where name = ? and arguments = ?',
         (name, unicode(arguments))).fetchone()[0]
     return cursor.execute(
         'select * from libraries where name = ? and arguments = ? and last_updated = ?',
         (name, unicode(arguments), t)).fetchone()
Ejemplo n.º 4
0
 def __call__(self, data):
     from .messages import RideLogException
     try:
         self.listener(data)
     except Exception as err:
         # Prevent infinite recursion if RideLogMessage listener is broken,
         if not isinstance(data, RideLogException):
             RideLogException(message='Error in listener: %s\n' \
                                      'While handling %s' % (unicode(err),
                                                             unicode(data)),
                              exception=err, level='ERROR').publish()
Ejemplo n.º 5
0
 def __call__(self, data):
     from .messages import RideLogException
     try:
         self.listener(data)
     except Exception as err:
         # Prevent infinite recursion if RideLogMessage listener is broken,
         if not isinstance(data, RideLogException):
             RideLogException(message='Error in listener: %s\n' \
                                      'While handling %s' % (unicode(err),
                                                             unicode(data)),
                              exception=err, level='ERROR').publish()
Ejemplo n.º 6
0
 def item_text(self, row, col):
     test, match = self._tests[row]
     if col == 0:
         return test.name
     if col == 1:
         return u', '.join(unicode(t) for t in test.tags)
     return test.datafile_controller.longname
Ejemplo n.º 7
0
 def item_text(self, row, col):
     test, match = self._tests[row]
     if col == 0:
         return test.name
     if col == 1:
         return u', '.join(unicode(t) for t in test.tags)
     return test.datafile_controller.longname
Ejemplo n.º 8
0
 def OnRun(self, event):
     """Called when the user clicks the "Run" button"""
     if not self._can_start_running_tests():
         return
     #if no tests are selected warn the user, issue #1622
     if not self.tests_selected():
         if not self.ask_user_to_run_anyway():
             # In Linux NO runs dialog 4 times
             return
     self._initialize_ui_for_running()
     command = self._create_command()
     self._output("command: %s\n" % command)  # DEBUG encode
     try:
         if PY2:
             command = bytes(command)  # .encode(encoding))
             # TODO This does not work if for example -i Áçãú
         # self._output("DEBUG: starting command %s\n" % command)
         # DEBUG encode
         self._test_runner.run_command(
             command, self._get_current_working_dir())
         # self._output("DEBUG: Passed test_runner.run_command\n")
         self._process_timer.Start(41)  # roughly 24fps
         self._set_running()
         self._progress_bar.Start()
     except Exception as e:
         # self._output("DEBUG: Except block test_runner.run_command\n")
         self._set_stopped()
         error, log_message = self.get_current_profile().format_error(
             unicode(e), None)
         self._output(error)
         if log_message:
             log_message.publish()
Ejemplo n.º 9
0
 def delete(self):
     self.controller.remove(unicode(self.name))
     if type(self) is Tag and len(self.controller._tags.value) == 0:
         if len(self.controller.parent.default_tags.value) > 0:
             self.controller.set_value("")
         else:
             self.controller.clear()
Ejemplo n.º 10
0
 def OnRun(self, event):
     """Called when the user clicks the "Run" button"""
     if not self._can_start_running_tests():
         return
     #if no tests are selected warn the user, issue #1622
     if not self.tests_selected():
         if not self.ask_user_to_run_anyway():
             # In Linux NO runs dialog 4 times
             return
     self._initialize_ui_for_running()
     command = self._create_command()
     self._output("command: %s\n" % command)  # DEBUG encode
     try:
         if PY2:
             command = bytes(command)  # .encode(encoding))
             # TODO This does not work if for example -i Áçãú
         # self._output("DEBUG: starting command %s\n" % command)
         # DEBUG encode
         self._test_runner.run_command(command,
                                       self._get_current_working_dir())
         # self._output("DEBUG: Passed test_runner.run_command\n")
         self._process_timer.Start(41)  # roughly 24fps
         self._set_running()
         self._progress_bar.Start()
     except Exception as e:
         # self._output("DEBUG: Except block test_runner.run_command\n")
         self._set_stopped()
         error, log_message = self.get_current_profile().format_error(
             unicode(e), None)
         self._output(error)
         if log_message:
             log_message.publish()
Ejemplo n.º 11
0
 def delete(self):
     self.controller.remove(unicode(self.name))
     if type(self) is Tag and len(self.controller._tags.value) == 0:
         if len(self.controller.parent.default_tags.value) > 0:
             self.controller.set_value("")
         else:
             self.controller.clear()
Ejemplo n.º 12
0
 def OnCreateKeyword(self, event):
     cells = self._data_cells_from_current_row()
     if not cells:
         return
     try:
         self._execute(AddKeywordFromCells(cells))
     except ValueError as err:
         wx.MessageBox(unicode(err))
Ejemplo n.º 13
0
 def OnCreateKeyword(self, event):
     cells = self._data_cells_from_current_row()
     if not cells:
         return
     try:
         self._execute(AddKeywordFromCells(cells))
     except ValueError as err:
         wx.MessageBox(unicode(err))
Ejemplo n.º 14
0
 def get_and_insert_keywords(self, library_name, library_args):
     result_queue = Queue.Queue(maxsize=1)
     self._messages.put(
         ('insert', library_name, library_args, result_queue), timeout=3)
     try:
         return result_queue.get(timeout=5)
     except Queue.Empty as e:
         RideLogMessage(u'Failed to read keywords from library db: {}'
                        .format(unicode(e))).publish()
         return []
Ejemplo n.º 15
0
 def _matches(self, test):
     name = test.name.lower()
     if self._match_in(name):
         return True
     if any(self._match_in(unicode(tag).lower()) for tag in test.tags):
         return True
     doc = test.documentation.value.lower()
     if self._match_in(doc):
         return True
     return False
Ejemplo n.º 16
0
 def details(self):
     value = self._value
     if self.name.startswith('@'):
         if value is None:
             value = '[ ]'
     return ('<table>'
             '<tr><td><i>Name:</i></td><td>%s</td></tr>'
             '<tr><td><i>Source:</i></td><td>%s</td></tr>'
             '<tr><td valign=top><i>Value:</i></td><td>%s</td></tr>'
             '</table>') % (self.name, self._original_source, unicode(value))
Ejemplo n.º 17
0
 def test_finds_newest_version(self):
     self._database.insert_library_keywords(
         'lib.py', 'foo',
         [LibraryKeywordInfo('this is old', 'doc', 'lib.py', '')])
     self._database.insert_library_keywords(
         'lib.py', 'foo',
         [LibraryKeywordInfo('this is new', 'doc', 'lib.py', '')])
     kws = self._database.fetch_library_keywords('lib.py', 'foo')
     self.assertEqual(len(kws), 1, unicode(kws))
     self.assertEqual(kws[0].name, 'this is new')
Ejemplo n.º 18
0
 def get_and_insert_keywords(self, library_name, library_args):
     result_queue = Queue.Queue(maxsize=1)
     self._messages.put(
         ('insert', library_name, library_args, result_queue), timeout=3)
     try:
         return result_queue.get(timeout=5)
     except Queue.Empty as e:
         RideLogMessage(u'Failed to read keywords from library db: {}'
                        .format(unicode(e))).publish()
         return []
Ejemplo n.º 19
0
 def _matches(self, test):
     name = test.name.lower()
     if self._match_in(name):
         return True
     if any(self._match_in(unicode(tag).lower()) for tag in test.tags):
         return True
     doc = test.documentation.value.lower()
     if self._match_in(doc):
         return True
     return False
Ejemplo n.º 20
0
 def _search_for_tags(self):
     unique_tags = _SortableD()  # dict()  # utils.NormalizedDict() # DEBUG
     for i in self.model.suite.children:
         for test in i.testcase_table.tests:
             try:
                 for tag in getattr(test.tags, 'tags').split("    "):
                     if tag is None or len(unicode(tag).strip()) == 0:
                         continue
                     else:
                         tag_name = unicode(tag)
                     if tag_name in unique_tags:
                         unique_tags[tag_name].append(test)
                     else:
                         unique_tags[tag_name] = [test]
             except AttributeError:
                 pass
     isreversed = (self.sort_state[0] == 0 and self.sort_state[1] == 0)
     self._results = sorted(unique_tags.items(),
                            key=lambda item: len(item[0]),
                            reverse=isreversed)
Ejemplo n.º 21
0
 def details(self):
     value = self._value
     if self.name.startswith('@'):
         if value is None:
             value = '[ ]'
     return ('<table>'
             '<tr><td><i>Name:</i></td><td>%s</td></tr>'
             '<tr><td><i>Source:</i></td><td>%s</td></tr>'
             '<tr><td valign=top><i>Value:</i></td><td>%s</td></tr>'
             '</table>') % (self.name, self._original_source,
                            unicode(value))
Ejemplo n.º 22
0
def _parse_args(args):
    parsed = []
    if args.positional:
        parsed.extend(list(args.positional))
    if args.defaults:
        for i, value in enumerate(args.defaults):
            index = len(args.positional) - len(args.defaults) + i
            parsed[index] = parsed[index] + '=' + unicode(value)
    if args.varargs:
        parsed.append('*%s' % args.varargs)
    if args.kwargs:
        parsed.append('**%s' % args.kwargs)
    return parsed
Ejemplo n.º 23
0
    def _search_for_tags(self):
        unique_tags = utils.NormalizedDict()
        self._tags = utils.NormalizedDict()
        self._test_cases = []
        for test in self.frame._controller.all_testcases():
            self._test_cases.append(test)
            for tag in test.tags:
                if tag.is_empty() or len(unicode(tag).strip()) == 0:
                    continue
                else:
                    tag_name = unicode(tag)
                if tag_name in unique_tags:
                    unique_tags[tag_name].append(test)
                    self._tags[tag_name].append(tag)
                else:
                    unique_tags[tag_name] = [test]
                    self._tags[tag_name] = [tag]

        isreversed = (self.sort_state[1] != 1)
        self.total_test_cases = len(self._test_cases)
        self._results = sorted(unique_tags.items(),
                               key=lambda item: item[0].lower,
                               reverse=isreversed)
Ejemplo n.º 24
0
 def insert_library_keywords(self, library_name, library_arguments,
                             keywords):
     cur = self._cursor()
     old_versions = cur.execute(
         'select id from libraries where name = ? and arguments = ?',
         (library_name, unicode(library_arguments))).fetchall()
     cur.executemany('delete from keywords where library = ?', old_versions)
     cur.executemany('delete from libraries where id = ?', old_versions)
     lib = self._insert_library(library_name, library_arguments, cur)
     keyword_values = [[
         kw.name, kw.doc, u' | '.join(kw.arguments), kw.source, lib[0]
     ] for kw in keywords if kw is not None]
     self._insert_library_keywords(keyword_values, cur)
     self._connection.commit()
Ejemplo n.º 25
0
    def __init__(self, message, exception, level='INFO', notify_user=False):
        """Initializes a RIDE log exception.

        The log ``level`` has default value ``INFO`` and the ``timestamp``
        is generated automatically. Message is automatically appended with
        a traceback.
        """
        exc_type, exc_value, exc_traceback = sys.exc_info()
        if exc_traceback:
            tb = traceback.extract_tb(exc_traceback)
            message += '\n\nTraceback (most recent call last):\n%s\n%s' % \
                (unicode(exception), ''.join(traceback.format_list(tb)))
        RideMessage.__init__(
            self, message=message, level=level, notify_user=False,
            timestamp=utils.get_timestamp(), exception=exception)
Ejemplo n.º 26
0
    def _search_for_tags(self):
        unique_tags = utils.NormalizedDict()
        self._tags = utils.NormalizedDict()
        self._test_cases = []
        for test in self.frame._controller.all_testcases():
            self._test_cases.append(test)
            for tag in test.tags:
                if tag.is_empty() or len(unicode(tag).strip()) == 0:
                    continue
                else:
                    tag_name = unicode(tag)
                if tag_name in unique_tags:
                    unique_tags[tag_name].append(test)
                    self._tags[tag_name].append(tag)
                else:
                    unique_tags[tag_name] = [test]
                    self._tags[tag_name] = [tag]

        isreversed = (self.sort_state[1] != 1)
        self.total_test_cases = len(self._test_cases)

        self._results = sorted(unique_tags.items(),
                               key=lambda item: item[0].lower(),
                               reverse=isreversed)
Ejemplo n.º 27
0
    def insert_library_keywords(self, library_name, library_arguments,
                                keywords):
        library_doc_format = "ROBOT"
        if len(keywords) > 0:
            library_doc_format = keywords[0].doc_format
            #if any(x.doc_format != library_doc_format for x in keywords):
            #    print("debug: keywords doc format not consistent within library")

        cur = self._cursor()
        old_versions = cur.execute(
            'select id from libraries where name = ?  and arguments = ?',
            (library_name, unicode(library_arguments))).fetchall()
        cur.executemany('delete from keywords where library = ?', old_versions)
        cur.executemany('delete from libraries where id = ?', old_versions)
        lib = self._insert_library(library_name, library_doc_format,
                                   library_arguments, cur)
        keyword_values = [[
            kw.name, kw.doc, u' | '.join(kw.arguments), kw.source, lib[0]
        ] for kw in keywords if kw is not None]
        self._insert_library_keywords(keyword_values, cur)
        self._connection.commit()
Ejemplo n.º 28
0
 def _source_name(self, source):
     return unicode(os.path.basename(source)) if source else ''
Ejemplo n.º 29
0
 def _tags(self):
     if self.__tags is None:
         self.__tags = [unicode(tag).lower() for tag in self._test.tags]
     return self.__tags
Ejemplo n.º 30
0
 def matches(self, test):
     tags = [unicode(tag) for tag in test.tags]
     if self._matches(tags):
         return test.longname
     return False
Ejemplo n.º 31
0
 def matches(self, test):
     tags = [unicode(tag) for tag in test.tags]
     if self._matches(tags):
         return test.longname
     return False
Ejemplo n.º 32
0
 def _insert_library(self, name, doc_format, arguments, cursor):
     cursor.execute('insert into libraries values (null, ?, ?, ?, ?)',
                    (name, doc_format, unicode(arguments), time.time()))
     return self._fetch_lib(name, arguments, cursor)
Ejemplo n.º 33
0
 def _key(self, name, args):
     return name, unicode(tuple(args or ''))
Ejemplo n.º 34
0
 def _key(self, name, args):
     return name, unicode(tuple(args or ''))
Ejemplo n.º 35
0
def TipMessage(cell):
    if not cell:
        return ''
    tip = _TooltipMessage(cell) if not cell.for_loop \
        else _ForLoopTooltipMessage(cell)
    return html_escape(unicode(tip))
Ejemplo n.º 36
0
 def _insert_library(self, name, doc_format, arguments, cursor):
     cursor.execute('insert into libraries values (null, ?, ?, ?, ?)', (name, doc_format, unicode(arguments), time.time()))
     return self._fetch_lib(name, arguments, cursor)
Ejemplo n.º 37
0
 def update_library_timestamp(self, name, arguments, milliseconds=None):
     self._cursor().execute('update libraries set last_updated = ? where name = ? and arguments = ?', (milliseconds or time.time(), name, unicode(arguments)))
     self._connection.commit()
Ejemplo n.º 38
0
 def _fetch_lib(self, name, arguments, cursor):
     t = cursor.execute('select max(last_updated) from libraries where name = ?  and arguments = ?', (name, unicode(arguments))).fetchone()[0]
     return cursor.execute('select * from libraries where name = ?  and arguments = ? and last_updated = ?', (name, unicode(arguments), t)).fetchone()
Ejemplo n.º 39
0
    def insert_library_keywords(self, library_name, library_arguments, keywords):
        library_doc_format = "ROBOT"
        if len(keywords) > 0:
            library_doc_format = keywords[0].doc_format
            #if any(x.doc_format != library_doc_format for x in keywords):
            #    print("debug: keywords doc format not consistent within library")

        cur = self._cursor()
        old_versions = cur.execute('select id from libraries where name = ?  and arguments = ?', (library_name, unicode(library_arguments))).fetchall()
        cur.executemany('delete from keywords where library = ?', old_versions)
        cur.executemany('delete from libraries where id = ?', old_versions)
        lib = self._insert_library(library_name, library_doc_format, library_arguments, cur)
        keyword_values = [[kw.name, kw.doc, u' | '.join(kw.arguments), kw.source, lib[0]] for kw in keywords if kw is not None]
        self._insert_library_keywords(keyword_values, cur)
        self._connection.commit()
Ejemplo n.º 40
0
 def _source(self, item):
     return unicode(os.path.basename(item.source)) if item.source else ''
Ejemplo n.º 41
0
def _format_value(value):
    if isinstance(value, basestring):
        return value
    if isinstance(value, list):
        return u'[ %s ]' % u' | '.join(unicode(v) for v in value)
    return unicode(value)
Ejemplo n.º 42
0
def _format_value(value):
    if isinstance(value, basestring):
        return value
    if isinstance(value, list):
        return u'[ %s ]' % u' | '.join(unicode(v) for v in value)
    return unicode(value)
Ejemplo n.º 43
0
 def _source(self, item):
     return unicode(os.path.basename(item.source)) if item.source else ''
Ejemplo n.º 44
0
 def _cache_error(self, data, error):
     self._errors.append("Error in serializing '%s':\n%s"
                         % (data.data.source, unicode(error)))
Ejemplo n.º 45
0
 def update_library_timestamp(self, name, arguments, milliseconds=None):
     self._cursor().execute(
         'update libraries set last_updated = ? where name = ? and arguments = ?',
         (milliseconds or time.time(), name, unicode(arguments)))
     self._connection.commit()
Ejemplo n.º 46
0
 def _tags(self):
     if self.__tags is None:
         self.__tags = [unicode(tag).lower() for tag in self._test.tags]
     return self.__tags
Ejemplo n.º 47
0
 def _source_name(self, source):
     return unicode(os.path.basename(source)) if source else ''
Ejemplo n.º 48
0
 def _cache_error(self, data, error):
     self._errors.append("Error in serializing '%s':\n%s"
                         % (data.data.source, unicode(error)))