Skip to content

Commit

Permalink
Fixed Gherkin calls. Still to fix TestTableSettings Setup/Teardown/Te…
Browse files Browse the repository at this point in the history
…mplate keywords
  • Loading branch information
HelioGuilherme66 committed Dec 17, 2023
1 parent a43065d commit 692b283
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 55 deletions.
21 changes: 15 additions & 6 deletions src/robotide/editor/texteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import wx
from wx import stc, Colour
from wx.adv import HyperlinkCtrl, EVT_HYPERLINK
from multiprocessing import shared_memory
from .popupwindow import HtmlPopupWindow
from . import _EDIT
from .. import robotapi
Expand Down Expand Up @@ -119,12 +120,12 @@ def _open(self):
self._save_flag = 0
""" DEBUG: To be used in Localization
"""
if hasattr(datafile_controller, 'preamble'): # DEBUG: Is failing at resource files
print(f"DEBUG: texteditor _open preamble={datafile_controller.preamble}")
# if hasattr(datafile_controller, 'preamble'): # DEBUG: Is failing at resource files
# print(f"DEBUG: texteditor _open preamble={datafile_controller.preamble}")
if hasattr(datafile_controller, 'language'):
self._doc_language = datafile_controller.language
self._editor.language = datafile_controller.language
print(f"DEBUG: texteditor _open language={datafile_controller.language}")
# print(f"DEBUG: texteditor _open language={datafile_controller.language}")
self._open_data_for_controller(datafile_controller)
self._editor.store_position()

Expand Down Expand Up @@ -690,7 +691,7 @@ def open(self, data):
self.reset()
self._data = data
self.language = self._data._doc_language
print(f"DEBUG: texteditor.py SourceEditor open ENTER language={self.language}")
# print(f"DEBUG: texteditor.py SourceEditor open ENTER language={self.language}")
try:
if isinstance(self._data.wrapper_data, ResourceFileController):
self._controller_for_context = DummyController(self._data.wrapper_data, self._data.wrapper_data)
Expand All @@ -704,7 +705,9 @@ def open(self, data):
self.datafile = self.plugin.datafile
if not self.source_editor:
self._stored_text = self._data.content
self._create_editor_text_control(text=self._stored_text, language=self.language)
else:
self.source_editor.set_language(self.language)
self.source_editor.set_text(self._data.content)
self.set_editor_caret_position()

Expand Down Expand Up @@ -2088,8 +2091,14 @@ def __init__(self, editor, settings, readonly=False, language=None):
self.settings = settings
self._readonly = readonly
self._ensure_default_font_is_valid()
self.language = language
try:
set_lang = shared_memory.ShareableList(name="language")
except AttributeError: # Unittests fails here
set_lang = []
set_lang[0] = language[0] if language is not None else 'en'
self.language = [set_lang[0]]
options = { 'language': self.language }
# print(f"DEBUG: texteditor.py RobotStylizer _init_ language={self.language}\n")
if robotframeworklexer:
self.lexer = robotframeworklexer.RobotFrameworkLexer(**options)
else:
Expand Down Expand Up @@ -2213,7 +2222,7 @@ def stylize(self):
self.editor.ConvertEOLs(2)
shift = 0
for position, token, value in self.lexer.get_tokens_unprocessed(self.editor.GetText()):
print(f"DEBUG: texteditor.py RobotStylizer stylize token={token} value={value}")
# print(f"DEBUG: texteditor.py RobotStylizer stylize token={token} value={value}")
if wx.VERSION < (4, 1, 0):
self.editor.StartStyling(position + shift, 31)
else:
Expand Down
121 changes: 75 additions & 46 deletions src/robotide/lib/compat/pygments/robotframework.py

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/robotide/lib/robot/parsing/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def _data_as_list(self):


class ImportSetting(Setting):
setting_name = None

def __init__(self, parent, name, args=None, alias=None, comment=None):
self.parent = parent
Expand Down Expand Up @@ -378,7 +379,10 @@ class Resource(ImportSetting):
def __init__(self, parent, name, invalid_args=None, comment=None):
if invalid_args:
name += ' ' + ' '.join(invalid_args)
self.setting_name = get_localized_setting(parent.language, 'Resource')
try:
self.setting_name = get_localized_setting(parent.language, 'Resource')
except AttributeError: # Unit tests were failing here
self.setting_name = get_localized_setting(None, 'Resource')
ImportSetting.__init__(self, parent, name, comment=comment)


Expand Down
3 changes: 3 additions & 0 deletions src/robotide/lib/robot/writer/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def _format_row(self, row, table=None):
# print(f"DEBUG: formatters.py format_row ENTER row={row}")
if table and table.type == 'comments':
return row
# Unit tests failing here with row[0]==None
if row and row[0] is None:
row[0] = ' '
row = self._escape(row)
aligner = self._aligner_for(table)
return aligner.align_row(row)
Expand Down
10 changes: 9 additions & 1 deletion src/robotide/ui/mainframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import wx.lib.agw.aui as aui
from wx import Colour
from wx.adv import TaskBarIcon, TBI_DOCK, EVT_TASKBAR_LEFT_DOWN
from multiprocessing import shared_memory

from .actiontriggers import (MenuBar, ToolBarButton, ShortcutRegistry, _RideSearchMenuItem)
from .filedialogs import (NewProjectDialog, InitFileFormatDialog)
Expand Down Expand Up @@ -85,6 +86,8 @@ def __init__(self, application, controller):
pos=application.settings.get(MAINFRAME_POSITION, (50, 30)),
size=size, style=wx.DEFAULT_FRAME_STYLE | wx.SUNKEN_BORDER | wx.BORDER_THEME)

# Shared memory to store language definition
self.sharemem = shared_memory.ShareableList(['en'], name="language")
# set Left to Right direction (while we don't have localization)
self.SetLayoutDirection(wx.Layout_LeftToRight)
# self.SetLayoutDirection(wx.Layout_RightToLeft)
Expand Down Expand Up @@ -414,7 +417,10 @@ def open_suite(self, path):
from ..lib.compat.parsing.language import check_file_language
self.controller.file_language = check_file_language(path)
if self.controller.file_language:
print(f"DEBUG: project.py Project load_data file_language = {self.controller.file_language}")
set_lang=shared_memory.ShareableList(name="language")
set_lang[0] = self.controller.file_language[0]
# print(f"DEBUG: project.py Project load_data file_language = {self.controller.file_language}\n"
# f"sharedmem={set_lang}")
try:
err = self.controller.load_datafile(path, LoadProgressObserver(self))
if isinstance(err, UserWarning):
Expand Down Expand Up @@ -474,6 +480,8 @@ def _show_format_dialog_for(file_controller_without_format):

def on_exit(self, event):
_ = event
self.sharemem.shm.close()
self.sharemem.shm.unlink()
self.Close()

def on_manage_plugins(self, event):
Expand Down
2 changes: 1 addition & 1 deletion utest/controller/test_modifications_on_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from robotide.publish import PUBLISHER
from robotide.namespace.namespace import Namespace
from robotide.spec.librarymanager import LibraryManager
from resources.mocks import FakeSettings
from ..resources.mocks import FakeSettings


def create_test_data(path, filepath, resourcepath, initpath):
Expand Down
4 changes: 4 additions & 0 deletions utest/editor/test_texteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import wx
from wx.lib.agw.aui import AuiManager
import wx.lib.agw.aui as aui
from multiprocessing import shared_memory
from functools import total_ordering
from robotide.ui.tagdialogs import ViewAllTagsDialog
from utest.resources import datafilereader, MessageRecordingLoadObserver
Expand Down Expand Up @@ -122,6 +123,7 @@ class TestEditorCommands(unittest.TestCase):
def setUp(self):
self.app = MyApp()
settings = self.app.settings
self.shared_mem = shared_memory.ShareableList(['en'], name="language")
self.frame = self.app.frame
self.frame.actions = ActionRegisterer(AuiManager(self.frame), MenuBar(self.frame), ToolBar(self.frame),
ShortcutRegistry(self.frame))
Expand All @@ -148,6 +150,8 @@ def tearDown(self):
wx.CallAfter(self.app.ExitMainLoop)
self.app.MainLoop() # With this here, there is no Segmentation fault
# wx.CallAfter(wx.Exit)
self.shared_mem.shm.close()
self.shared_mem.shm.unlink()
self.app.Destroy()
self.app = None

Expand Down
4 changes: 4 additions & 0 deletions utest/editor/test_z_editor_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import unittest
from wx.lib.agw.aui import AuiManager
import wx.lib.agw.aui as aui
from multiprocessing import shared_memory
from functools import total_ordering
from robotide.ui.tagdialogs import ViewAllTagsDialog
from utest.resources import datafilereader, MessageRecordingLoadObserver
Expand Down Expand Up @@ -166,6 +167,7 @@ class EditorPluginTest(unittest.TestCase):

def setUp(self):
self.app = MyApp()
self.shared_mem = shared_memory.ShareableList(['en'], name="language")
settings = self.app.settings
self.frame = self.app.frame
self.frame.actions = ActionRegisterer(AuiManager(self.frame), MenuBar(self.frame), ToolBar(self.frame),
Expand Down Expand Up @@ -203,6 +205,8 @@ def tearDown(self):
wx.CallAfter(self.app.ExitMainLoop)
# self.app.MainLoop() # With this here, there is no Segmentation fault
# wx.CallAfter(wx.Exit)
self.shared_mem.shm.close()
self.shared_mem.shm.unlink()
self.app.Destroy()
self.app = None
if os.path.exists(DATADIR):
Expand Down
33 changes: 33 additions & 0 deletions utest/resources/robotdata/language/en/gherkin_en.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This is the preamble
Language: English

# A blank line

*** Settings ***
Documentation This is the documentation for Gherkin test
... A continued line of documentation
*** Test Cases ***
third test
Given "Mr. Smith" is registered
And "cart" has objects
When "Mr. Smith" clicks in checkout
Then the total is presented and awaits confirmation
But it is shown the unavailable payment method

*** Keywords ***
${user} is registered
No Operation

${cart} has objects
No Operation

${user} clicks in checkout
No Operation

the total is presented and awaits confirmation
No Operation

it is shown the unavailable payment method
No Operation

35 changes: 35 additions & 0 deletions utest/resources/robotdata/language/pt/gherkin_pt.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Este é o preâmbulo
Language: Portuguese

# Mais uma linha em branco

*** Definições ***
Documentação Esta é a documentação para o teste Gherkin
... Uma linha de continuação da documentação

*** Casos de Teste ***
teste terceiro
Dado "Sr. José" está registado
E "carrinho" tem objectos
Quando "Sr. José" clica em finalizar compra
Então é apresentado o total e aguarda confirmação
Mas é apresentado meio de pagamento indisponível
# Comment at end of test case, next is empty line followed by the section keywords

*** Palavras-Chave ***
${utilizador} está registado
No Operation

# Comment before keyword, next is keyword name

${carrinho de compras} tem objectos
No Operation

${utilizador} clica em finalizar compra
No Operation

é apresentado o total e aguarda confirmação
No Operation

é apresentado meio de pagamento indisponível
No Operation

0 comments on commit 692b283

Please sign in to comment.