Skip to content

Commit

Permalink
fix unit test (#155)
Browse files Browse the repository at this point in the history
* Cleanup code (robotframework#2905)

* clean duplicates

* clean duplicates

* clean duplicates

* clean duplicates

* rename function

* Refactor TextEdit, WIP

* Fix unit tests with language transform

* Fix insecure save of tmp file

* Set Sonar for banches, update version

* Set Sonar for banches, update version

* Set Sonar for branches, update version

* Separated key commands in TextEdit. Breaks some, TAB functions, Enter..

* Improve keys calls in TextEditor

* Improve key use in TextEditor on Windows

* Increase utest in TextEditor

* Add requests to setup.py

* First develop version

* Cleanup code (#154)

* Refactor TextEdit, WIP

* Fix unit tests with language transform

* Separated key commands in TextEdit. Breaks some, TAB functions, Enter..

* Delete commented code, renamve arguments

* Refactor change_locale

* Increase unit tests
  • Loading branch information
HelioGuilherme66 authored Oct 26, 2024
1 parent a1bca91 commit 6b39294
Show file tree
Hide file tree
Showing 19 changed files with 562 additions and 500 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ on:
push:
branches:
- master
- develop
- cleanup_code
jobs:
sonarcloud:
name: SonarCloud
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
'psutil',
'Pywin32; sys_platform=="win32"',
'wxPython',
'packaging']
'packaging',
'requests>=2.32.2']

PACKAGE_DATA = {
'robotide.preferences': ['settings.cfg'],
Expand Down
1 change: 1 addition & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ sonar.projectKey=HelioGuilherme66_RIDE
sonar.organization=helioguilherme66
sonar.host.url=https://sonarcloud.io
sonar.python.version=3.10
sonar.projectVersion=v2.1
sonar.sources=src/
sonar.tests=utest/
sonar.exclusions=**/lib/robot/**/*
Expand Down
95 changes: 16 additions & 79 deletions src/robotide/application/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from ..ui.mainframe import RideFrame
from .. import publish
from .. import context, contrib
# from ..context import coreplugins
from ..preferences import Preferences, RideSettings
from ..application.pluginloader import PluginLoader
from ..application.editorprovider import EditorProvider
Expand Down Expand Up @@ -176,27 +175,14 @@ def _ApplyThemeToWidget(widget, fore_color=wx.BLUE, back_color=wx.LIGHT_GREY, th
aui_default_tool_bar_art = AuiDefaultToolBarArt()
aui_default_tool_bar_art.SetDefaultColours(wx.GREEN)
widget.SetBackgroundColour(background)
# widget.SetOwnBackgroundColour(background)
widget.SetForegroundColour(foreground)
# widget.SetOwnForegroundColour(foreground)
"""
widget.SetBackgroundColour(Colour(200, 222, 40))
widget.SetOwnBackgroundColour(Colour(200, 222, 40))
widget.SetForegroundColour(Colour(7, 0, 70))
widget.SetOwnForegroundColour(Colour(7, 0, 70))
"""
# or
elif isinstance(widget, wx.Control):
if not isinstance(widget, (wx.Button, wx.BitmapButton, ButtonWithHandler)):
widget.SetForegroundColour(foreground)
widget.SetBackgroundColour(background)
# widget.SetOwnBackgroundColour(background)
# widget.SetOwnForegroundColour(foreground)
else:
widget.SetForegroundColour(secondary_foreground)
widget.SetBackgroundColour(secondary_background)
# widget.SetOwnBackgroundColour(secondary_background)
# widget.SetOwnForegroundColour(secondary_foreground)
elif isinstance(widget, (wx.TextCtrl, TabFrame, AuiTabCtrl)):
widget.SetForegroundColour(foreground_text) # or fore_color
widget.SetBackgroundColour(background_help) # or back_color
Expand All @@ -206,19 +192,14 @@ def _ApplyThemeToWidget(widget, fore_color=wx.BLUE, back_color=wx.LIGHT_GREY, th
elif isinstance(widget, wx.MenuItem):
widget.SetTextColour(foreground)
widget.SetBackgroundColour(background)
# print(f"DEBUG: Application ApplyTheme wx.MenuItem {type(widget)}")
else:
widget.SetBackgroundColour(background)
# widget.SetOwnBackgroundColour(background)
widget.SetForegroundColour(foreground)
# widget.SetOwnForegroundColour(foreground)

def _WalkWidgets(self, widget, indent=0, indent_level=4, theme=None):
# print(' ' * indent + widget.__class__.__name__)
if theme is None:
theme = {}
widget.Freeze()
# print(f"DEBUG Application General : _WalkWidgets background {theme['background']}")
self._ApplyThemeToWidget(widget=widget, theme=theme)
for child in widget.GetChildren():
if not child.IsTopLevel(): # or isinstance(child, wx.PopupWindow)):
Expand All @@ -230,7 +211,6 @@ def _WalkWidgets(self, widget, indent=0, indent_level=4, theme=None):
def SetGlobalColour(self, message):
if message.keys[0] != "General":
return
# print(f"DEBUG Application General : Enter SetGlobalColour message= {message.keys[0]}")
app = wx.App.Get()
_root = app.GetTopWindow()
theme = self.settings.get_without_default('General')
Expand All @@ -241,7 +221,6 @@ def SetGlobalColour(self, message):
font.SetPointSize(font_size)
_root.SetFont(font)
self._WalkWidgets(_root, theme=theme)
# print(f"DEBUG Application General : SetGlobalColour AppliedWidgets check Filexplorer and Tree")
if theme['apply to panels'] and self.fileexplorerplugin.settings['_enabled']:
self.fileexplorerplugin.settings['background'] = theme['background']
self.fileexplorerplugin.settings['foreground'] = theme['foreground']
Expand All @@ -260,69 +239,12 @@ def SetGlobalColour(self, message):
self.treeplugin.settings[FONT_FACE] = theme[FONT_FACE]
if self.treeplugin.settings['opened']:
self.treeplugin.on_show_tree(None)
"""
all_windows = list()
general = self.settings.get('General', None)
# print(f"DEBUG: Application General {general['background']} Type message {type(message)}")
# print(f"DEBUG: Application General message keys {message.keys} old {message.old} new {message.new}")
background = general['background']
foreground = general['foreground']
background_help = general[BACKGROUND_HELP]
foreground_text = general[FOREGROUND_TEXT]
font_size = general[FONT_SIZE]
font_face = general[FONT_FACE]
font = _root.GetFont()
font.SetFaceName(font_face)
font.SetPointSize(font_size)
_root.SetFont(font)
def _iterate_all_windows(root):
if hasattr(root, 'GetChildren'):
children = root.GetChildren()
if children:
for c in children:
_iterate_all_windows(c)
all_windows.append(root)
_iterate_all_windows(_root)
for w in all_windows:
if hasattr(w, 'SetHTMLBackgroundColour'):
w.SetHTMLBackgroundColour(wx.Colour(background_help))
w.SetForegroundColour(wx.Colour(foreground_text)) # 7, 0, 70))
elif hasattr(w, 'SetBackgroundColour'):
w.SetBackgroundColour(wx.Colour(background)) # 44, 134, 179))
# if hasattr(w, 'SetOwnBackgroundColour'):
# w.SetOwnBackgroundColour(wx.Colour(background)) # 44, 134, 179))
if hasattr(w, 'SetForegroundColour'):
w.SetForegroundColour(wx.Colour(foreground)) # 7, 0, 70))
# if hasattr(w, 'SetOwnForegroundColour'):
# w.SetOwnForegroundColour(wx.Colour(foreground)) # 7, 0, 70))
if hasattr(w, 'SetFont'):
w.SetFont(font)
"""

def change_locale(self, message):
if message.keys[0] != "General":
return
initial_locale = self._locale.GetName()
if languages:
from ..preferences import Languages
names = [n for n in Languages.names]
else:
names = [('English', 'en', wx.LANGUAGE_ENGLISH)]
general = self.settings.get_without_default('General')
language = general.get('ui language', 'English')
try:
idx = [lang[0] for lang in names].index(language)
code = names[idx][2]
except (IndexError, ValueError):
print(f"DEBUG: application.py RIDE change_locale ERROR: Could not find {language=}")
code = wx.LANGUAGE_ENGLISH_WORLD
code = self._get_language_code()
del self._locale
self._locale = wx.Locale(code)
if not self._locale.IsOk():
Expand Down Expand Up @@ -352,6 +274,21 @@ def change_locale(self, message):
except FileNotFoundError:
pass

def _get_language_code(self) -> str:
if languages:
from ..preferences import Languages
names = [n for n in Languages.names]
else:
names = [('English', 'en', wx.LANGUAGE_ENGLISH)]
general = self.settings.get_without_default('General')
language = general.get('ui language', 'English')
try:
idx = [lang[0] for lang in names].index(language)
code = names[idx][2]
except (IndexError, ValueError):
print(f"DEBUG: application.py RIDE change_locale ERROR: Could not find {language=}")
code = wx.LANGUAGE_ENGLISH_WORLD
return code

@staticmethod
def update_excludes(message):
Expand Down
32 changes: 18 additions & 14 deletions src/robotide/editor/dialoghelps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
_ = GetTranslation # To keep linter/code analyser happy
builtins.__dict__['_'] = GetTranslation

PH_ESCAPE ="%(ESCAPE)s" # PH = Place Holder
INHERIT_TAG = "Inherited tags are not shown in this view."
PH_TAGS = "%(TAG)s"
PH_FIXTURE = "%(FIXTURE)s"

def get_help(title):
_HELPS = {}
Expand All @@ -46,44 +50,44 @@ def get_help(title):
_("Give name, optional arguments and optional alias of the library to import."),
_("Separate multiple arguments with a pipe character like 'arg 1 | arg 2'."), "%(ALIAS)s", '',
"Variables", _("Give path and optional arguments of the variable file to import."),
_("Separate multiple arguments with a pipe character like 'arg 1 | arg 2'."), "%(ESCAPE)s", '',
_("Separate multiple arguments with a pipe character like 'arg 1 | arg 2'."), PH_ESCAPE, '',
"Resource", _("Give path to the resource file to import."),
_("Existing resources will be automatically loaded to the resource tree."),
_("New resources must be created separately."), '', "Documentation", _("Give the documentation."),
_("Simple formatting like *bold* and _italic_ can be used."),
_("Additionally, URLs are converted to clickable links."), '', "Force Tags",
_("These tags are set to all test cases in this test suite."),
_("Inherited tags are not shown in this view."), "%(TAG)s", "%(ESCAPE)s", '', "Default Tags",
_(INHERIT_TAG), PH_TAGS, PH_ESCAPE, '', "Default Tags",
_("These tags are set to all test cases in this test suite unless test cases have their own tags."),
"%(TAG)s", "%(ESCAPE)s", '', "Test Tags",
PH_TAGS, PH_ESCAPE, '', "Test Tags",
_("These tags are applied to all test cases in this test suite. "
"This field exists since Robot Framework 6.0 and will replace "
"Force and Default Tags after version 7.0."), _("Inherited tags are not shown in this view."),
"%(TAG)s", "%(ESCAPE)s", '', "Tags",
"Force and Default Tags after version 7.0."), _(INHERIT_TAG),
PH_TAGS, PH_ESCAPE, '', "Tags",
_("These tags are set to this test case in addition to "
"Force Tags and they override possible Default Tags."),
_("Inherited tags are not shown in this view."), "%(TAG)s", "%(ESCAPE)s", '', "Suite Setup",
_(INHERIT_TAG), PH_TAGS, PH_ESCAPE, '', "Suite Setup",
_("This keyword is executed before executing any of the test cases or lower level suites."),
"%(FIXTURE)s", "%(ESCAPE)s", '', "Suite Teardown",
PH_FIXTURE, PH_ESCAPE, '', "Suite Teardown",
_("This keyword is executed after all test cases and lower level suites have been executed."),
"%(FIXTURE)s", "%(ESCAPE)s", '', "Test Setup",
PH_FIXTURE, PH_ESCAPE, '', "Test Setup",
_("This keyword is executed before every test case in this suite unless test cases override it."),
"%(FIXTURE)s", "%(ESCAPE)s", '', "Test Teardown",
PH_FIXTURE, PH_ESCAPE, '', "Test Teardown",
_("This keyword is executed after every test case in this suite unless test cases override it."),
"%(FIXTURE)s", "%(ESCAPE)s", '', "Setup",
PH_FIXTURE, PH_ESCAPE, '', "Setup",
_("This keyword is executed before other keywords in this test case or keyword."),
_("In test cases, overrides possible Test Setup set on the suite level."),
_("Setup in keywords exists since Robot v7.0."), "%(FIXTURE)s", "%(ESCAPE)s", '', "Teardown",
_("Setup in keywords exists since Robot v7.0."), PH_FIXTURE, PH_ESCAPE, '', "Teardown",
_("This keyword is executed after other keywords in this test case or keyword even if the test or "
"keyword fails."),
_("In test cases, overrides possible Test Teardown set on the suite level."),
"%(FIXTURE)s", "%(ESCAPE)s", '', "Test Template",
PH_FIXTURE, PH_ESCAPE, '', "Test Template",
_("Specifies the default template keyword used by tests in this suite."),
_("The test cases will contain only data to use as arguments to that keyword."), '', "Template",
_("Specifies the template keyword to use."),
_("The test itself will contain only data to use as arguments to that keyword."), '', "Arguments",
"%(ARGUMENTS)s", "%(ESCAPE)s", '', "Return Value",
_("Specify the return value. Use a pipe character to separate multiple values."), "%(ESCAPE)s",
"%(ARGUMENTS)s", PH_ESCAPE, '', "Return Value",
_("Specify the return value. Use a pipe character to separate multiple values."), PH_ESCAPE,
"The '[Return]' setting is deprecated since Robot v7.0. Use the 'RETURN' statement instead.", '',
"Test Timeout",
_("Maximum time test cases in this suite are allowed to execute before aborting them forcefully."),
Expand Down
Loading

0 comments on commit 6b39294

Please sign in to comment.