Skip to content

Commit 75a6cde

Browse files
Add unit tests for Preferences panel. WIP
1 parent f187172 commit 75a6cde

File tree

9 files changed

+240
-9
lines changed

9 files changed

+240
-9
lines changed

src/robotide/application/CHANGELOG.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Changelog</title><link rel="stylesheet" type="text/css" href="docbook-xsl.css" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /></head><body><div xml:lang="en" class="article" lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="id1337"></a>Changelog</h2></div></div><hr /></div><p>All notable changes to this project will be documented in this file.</p><p>The format is based on <a class="ulink" href="http://keepachangelog.com/en/1.0.0/" target="_top">Keep a Changelog</a>
33
and this project adheres to <a class="ulink" href="http://semver.org/spec/v2.0.0.html" target="_top">Semantic Versioning</a>.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_ulink_url_https_github_com_robotframework_ride_unreleased_ulink"></a>1. <a class="ulink" href="https://github.com/robotframework/RIDE" target="_top">Unreleased</a></h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_added"></a>1.1. Added</h3></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
4+
Added Settings Editor button to Preferences dialog, to edit settings.cfg.
5+
</li><li class="listitem">
6+
Created backup of settings.cfg to allow recovering some settings when broken upgrades.
7+
</li><li class="listitem">
48
Added current executing keyword and other statuses to TestRunner status bar.
59
</li><li class="listitem">
610
Added Config Panel button to supported installed Plugins next to their name in Plugin Manager dialog.

src/robotide/application/releasenotes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ def set_content(self, html_win, content):
234234
<pre class="literal-block">python -m robotide.postinstall -install</pre>
235235
<p>or</p>
236236
<pre class="literal-block">ride_postinstall.py -install</pre>
237-
<p>RIDE {VERSION} was released on 13/April/2025.</p>
238-
<br/>
239-
<h3>Happy International Kiss Day!</h3>
237+
<p>RIDE {VERSION} was released on 14/April/2025.</p>
240238
<!-- <br/>
241239
<h3>May The Fourth Be With You!</h3>
242240
<h3>Celebrate the bank holiday, 10th June, Day of Portugal, Portuguese Communities and Camões!!</h3>

src/robotide/editor/customsourceeditor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ def main(filepath, frame=None):
537537
CodeEditorPanel(frame, None, filepath)
538538
image_provider = ImageProvider()
539539
frame.SetTitle(filepath)
540+
frame.SetSize((800, 600))
540541
frame.SetIcon(wx.Icon(image_provider.RIDE_ICON))
541542
frame.CenterOnScreen()
542543
frame.Show(True)

src/robotide/preferences/editor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def __init__(self, *args, **kwargs):
210210
hsizer = wx.BoxSizer(wx.HORIZONTAL)
211211
config_button = ButtonWithHandler(self, _('Settings'), bitmap='wrench_orange.png',
212212
fsize=self.settings[FONT_SIZE],
213-
handler=lambda e: self.on_edit_settings(self._settings.user_path))
213+
handler=lambda e: self.on_edit_settings())
214214
config_button.SetBackgroundColour(self.settings['background'])
215215
config_button.SetOwnBackgroundColour(self.settings['background'])
216216
config_button.SetForegroundColour(self.settings['foreground'])
@@ -270,7 +270,7 @@ def SetTitle(self, title):
270270
"""Set the title of the panel"""
271271
self.title.SetLabel(title)
272272

273-
def on_edit_settings(self, settings_path):
273+
def on_edit_settings(self):
274274
"""Starts Text Editor for settings file and closes all if changed"""
275275
from ..editor import customsourceeditor
276276
from ..context import SETTINGS_DIRECTORY

utest/resources/mocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def GetMenuItemCount(self):
8989
class FakeSettings(Settings):
9090
def __init__(self, settings=None):
9191
self.fake_cfg = os.path.join(os.path.dirname(__file__), 'fake.cfg')
92-
92+
self._default_path = self.fake_cfg
9393
# make sure fake cfg is clean
9494
with open(self.fake_cfg, 'wb') as f:
9595
f.write(_FAKE_CFG_CONTENT)

utest/settings/test_settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ def tearDown(self):
310310
self._remove_path(self.user_settings_path)
311311
self._remove_path((self.user_settings_path+'_old_broken'))
312312
self._remove_path(os.path.join(self.settings_dir, 'new_settings.cfg'))
313+
self._remove_path(os.path.join(self.settings_dir, 'new_settings.cfg._backup'))
313314
self._remove_path(os.path.join(self.settings_dir, 'my_settings.cfg'))
314315
os.removedirs(self.settings_dir)
315316

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Copyright 2008-2015 Nokia Networks
2+
# Copyright 2016- Robot Framework Foundation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import builtins
17+
import os
18+
19+
import pytest
20+
DISPLAY = os.getenv('DISPLAY')
21+
if not DISPLAY:
22+
pytest.skip("Skipped because of missing DISPLAY", allow_module_level=True) # Avoid failing unit tests in system without X11
23+
import wx
24+
import unittest
25+
from robotide.preferences.managesettingsdialog import SaveLoadSettings
26+
from time import sleep
27+
from utest.resources import FakeSettings, UIUnitTestBase
28+
29+
30+
_ = wx.GetTranslation # To keep linter/code analyser happy
31+
builtins.__dict__['_'] = wx.GetTranslation
32+
33+
ID_LOAD = 5551
34+
ID_SAVE = 5552
35+
ID_CANCEL = -1
36+
settings = FakeSettings()
37+
38+
class MyEvent(object):
39+
def __init__(self, iid):
40+
self.id = iid
41+
42+
def GetId(self):
43+
return self.id
44+
45+
def Skip(self):
46+
pass
47+
48+
49+
class TestSaveLoadSettings(UIUnitTestBase):
50+
51+
def test_on_load_cancel(self):
52+
self.frame = wx.Frame(None)
53+
self.frame.CenterOnScreen()
54+
self.frame.Show()
55+
dlg = SaveLoadSettings(self.frame, settings)
56+
# wx.CallLater(5000, dlg.EndModal,ID_CANCEL)
57+
dlg.CenterOnParent()
58+
dlg.Show()
59+
sleep(5)
60+
result = dlg.on_load(MyEvent(ID_SAVE))
61+
assert dlg.GetTitle() == _("Save or Load Settings")
62+
assert result==ID_CANCEL
63+
64+
def test_on_load(self):
65+
self.frame = wx.Frame(None)
66+
self.frame.CenterOnScreen()
67+
self.frame.Show()
68+
dlg = SaveLoadSettings(self.frame, settings)
69+
wx.CallLater(5000, dlg.Close, True)
70+
dlg.CenterOnParent()
71+
# dlg.Show()
72+
sleep(2)
73+
# TODO: mock wx.FileDialog
74+
# result = dlg.on_load(MyEvent(ID_LOAD))
75+
assert dlg.GetTitle() == _("Save or Load Settings")
76+
# assert result==ID_LOAD
77+
78+
def test_on_save_cancel(self):
79+
self.frame = wx.Frame(None)
80+
self.frame.CenterOnScreen()
81+
self.frame.Show()
82+
dlg = SaveLoadSettings(self.frame, settings)
83+
# wx.CallLater(5000, dlg.EndModal,ID_CANCEL)
84+
dlg.CenterOnParent()
85+
dlg.Show()
86+
sleep(5)
87+
result = dlg.on_save(MyEvent(ID_LOAD))
88+
assert dlg.GetTitle() == _("Save or Load Settings")
89+
assert result==ID_CANCEL
90+
91+
def test_on_save(self):
92+
self.frame = wx.Frame(None)
93+
self.frame.CenterOnScreen()
94+
self.frame.Show()
95+
dlg = SaveLoadSettings(self.frame, settings)
96+
wx.CallLater(5000, dlg.Close, True)
97+
dlg.CenterOnParent()
98+
# dlg.Show()
99+
sleep(2)
100+
# TODO: mock wx.FileDialog
101+
# result = dlg.on_save(MyEvent(ID_SAVE)
102+
assert dlg.GetTitle() == _("Save or Load Settings")
103+
# assert result==ID_SAVE
104+
105+
def test_on_close(self):
106+
self.frame = wx.Frame(None)
107+
self.frame.CenterOnScreen()
108+
self.frame.Show()
109+
dlg = SaveLoadSettings(self.frame, settings)
110+
# wx.CallLater(5000, dlg.EndModal,ID_CANCEL)
111+
dlg.CenterOnParent()
112+
dlg.Show()
113+
sleep(5)
114+
result = dlg.on_close()
115+
assert dlg.GetTitle() == _("Save or Load Settings")
116+
assert result==ID_CANCEL
117+
118+
def test_load_and_merge_fails(self):
119+
self.frame = wx.Frame(None)
120+
self.frame.CenterOnScreen()
121+
self.frame.Show()
122+
settings.add_section('Plugins')
123+
settings.get_without_default('Plugins').add_section('Grid')
124+
dlg = SaveLoadSettings(self.frame, settings)
125+
# wx.CallLater(5000, dlg.EndModal,ID_CANCEL)
126+
dlg.CenterOnParent()
127+
dlg.Show()
128+
sleep(2)
129+
# TODO: assert Exception
130+
try:
131+
dlg.load_and_merge('nonvalid_path.cfg')
132+
except KeyError:
133+
pass
134+
135+
136+
137+
138+
if __name__ == '__main__':
139+
unittest.main()
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright 2008-2015 Nokia Networks
2+
# Copyright 2016- Robot Framework Foundation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import builtins
17+
import os
18+
19+
import pytest
20+
DISPLAY = os.getenv('DISPLAY')
21+
if not DISPLAY:
22+
pytest.skip("Skipped because of missing DISPLAY", allow_module_level=True) # Avoid failing unit tests in system without X11
23+
import wx
24+
import unittest
25+
from robotide.preferences import Preferences, PreferenceEditor
26+
from robotide.preferences.general import GeneralPreferences
27+
from time import sleep
28+
from utest.resources import FakeSettings, UIUnitTestBase
29+
30+
31+
_ = wx.GetTranslation # To keep linter/code analyser happy
32+
builtins.__dict__['_'] = wx.GetTranslation
33+
34+
35+
settings = FakeSettings()
36+
37+
38+
class MyEvent(object):
39+
def __init__(self, iid):
40+
self.id = iid
41+
42+
def GetId(self):
43+
return self.id
44+
45+
def Skip(self):
46+
pass
47+
48+
class MyGeneralPreferences(GeneralPreferences):
49+
location = 'General'
50+
51+
def create_colors_sizer(self):
52+
sizer = wx.BoxSizer()
53+
return sizer
54+
55+
56+
class TestPreferenceEditor(UIUnitTestBase):
57+
58+
def test_preferences_dialog(self):
59+
self.frame = wx.Frame(None)
60+
self.frame.CenterOnScreen()
61+
self.frame.Show()
62+
settings.set('font size',11)
63+
generalpanel = MyGeneralPreferences(settings, self.frame)
64+
preferences = Preferences(settings)
65+
preferences.add(generalpanel)
66+
dlg = PreferenceEditor(self.frame, title='Test Preferences Dialog', preferences=preferences)
67+
# wx.CallLater(5000, dlg.EndModal,ID_CANCEL)
68+
dlg.CenterOnParent()
69+
dlg.Show()
70+
sleep(2)
71+
generalpanel.Show()
72+
# panel_title = generalpanel.GetTitle()
73+
sleep(5)
74+
generalpanel.Close(True)
75+
dlg.on_close(MyEvent(0))
76+
assert dlg.GetTitle() == "Test Preferences Dialog"
77+
assert generalpanel.name == 'General'
78+
assert dlg._closing == True
79+
80+
"""
81+
TODO: Make missing tests
82+
"""
83+
84+
85+
86+
if __name__ == '__main__':
87+
unittest.main()

utest/ui/test_tree.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
from robotide.ui.actiontriggers import MenuBar, ShortcutRegistry
3434
from robotide.ui.mainframe import ActionRegisterer, ToolBar
35-
from utest.resources import FakeSettings
35+
from utest.resources import FakeSettings, FakeEditor
3636
from robotide.ui import treeplugin as st
3737
from robotide.ui import treenodehandlers as th
3838
from robotide.publish import PUBLISHER
@@ -43,7 +43,7 @@
4343
th.FakeDirectorySuiteHandler = th.FakeUserKeywordHandler = \
4444
th.FakeSuiteHandler = th.FakeTestCaseHandler = \
4545
th.FakeResourceHandler = th.TestDataDirectoryHandler
46-
st.Editor = lambda *args: _FakeEditor()
46+
st.Editor = lambda *args: FakeEditor()
4747
Tree._show_correct_editor = lambda self, x: None
4848
Tree.get_active_datafile = lambda self: None
4949
Tree._select = lambda self, node: self.SelectItem(node)\
@@ -79,10 +79,11 @@ def setUp(self):
7979
self.app = wx.App()
8080
self.frame = wx.Frame(None)
8181
self._model = self._create_model()
82+
self._settings = FakeSettings()
8283
self._tree = Tree(self.frame, ActionRegisterer(AuiManager(self.frame),
8384
MenuBar(self.frame),
8485
ToolBar(self.frame),
85-
ShortcutRegistry(self.frame)))
86+
ShortcutRegistry(self.frame)), self._settings)
8687
images = TreeImageList()
8788
self._tree._images = images
8889
self._tree.SetImageList(images)

0 commit comments

Comments
 (0)