Skip to content

Commit 8156133

Browse files
Avoid import of partial defined class. Augment macroeditors tests
1 parent 3284082 commit 8156133

2 files changed

Lines changed: 81 additions & 19 deletions

File tree

src/robotide/ui/treeplugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
RideOpenResource, RideSuiteAdded, RideSelectResource, RideDataFileSet, RideItemNameChanged,
3838
RideSaving, RideSettingsChanged)
3939
from ..controller.ctrlcommands import MoveTo
40-
from ..controller.filecontrollers import TestDataDirectoryController
4140
from ..pluginapi import Plugin
4241
from ..action import ActionInfo
4342
from ..widgets import PopupCreator
@@ -273,6 +272,7 @@ def on_tree_selection(self, message):
273272
self._tree.tree_node_selected(message.item)
274273

275274
def on_saving(self, message):
275+
from ..controller.filecontrollers import TestDataDirectoryController
276276
if not isinstance(message.datafile, TestDataDirectoryController):
277277
return
278278
# Saving a directory's __init__.robot invalidates every controller, so the whole

utest/editor/test_macroeditors.py

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,35 @@
2020
# if not DISPLAY:
2121
# pytest.skip("Skipped because of missing DISPLAY", allow_module_level=True) # Avoid failing unit tests in system without X11
2222
import wx
23+
24+
import robotide.editor.editors
2325
from .fakeplugin import FakePlugin
2426
from robotide.controller.macrocontrollers import TestCaseController
25-
from robotide.editor.macroeditors import TestCaseEditor
27+
from robotide.publish.messages import RideItemNameChanged
28+
from robotide.editor.editors import FindUsagesHeader
29+
from robotide.editor.macroeditors import TestCaseEditor, UserKeywordEditor
2630

31+
DELEGATED_METHODS =[('save', 'save'),
32+
# ('undo', 'on_undo'), # Disabled because of double Ctrl-Z
33+
('redo', 'on_redo'),
34+
('cut', 'on_cut'),
35+
('copy', 'on_copy'),
36+
('paste', 'on_paste'),
37+
('insert', 'on_insert'),
38+
('insert_cells', 'on_insert_cells'),
39+
('insert_rows', 'on_insert_rows'),
40+
('delete_rows', 'on_delete_rows'),
41+
('delete_cells', 'on_delete_cells'),
42+
('delete', 'on_delete'),
43+
('show_content_assist', 'show_content_assist'),
44+
('on_move_rows_up', 'on_move_rows_up'),
45+
('on_move_rows_down', 'on_move_rows_down'),
46+
('comment_rows', 'on_comment_rows'),
47+
('uncomment_rows', 'on_uncomment_rows'),
48+
('sharp_comment_rows', 'on_sharp_comment_rows'),
49+
('sharp_uncomment_rows', 'on_sharp_uncomment_rows'),
50+
('comment_cells', 'on_comment_cells'),
51+
('uncomment_cells', 'on_uncomment_cells')]
2752

2853
TestCaseEditor._populate = lambda self: None
2954

@@ -60,33 +85,70 @@ class MacroEditorTest(unittest.TestCase):
6085

6186
def setUp(self):
6287
myapp = wx.App(None)
63-
controller = TestCaseController(IncredibleMock(), IncredibleMock())
64-
plugin = FakePlugin({}, controller)
88+
self.controller = TestCaseController(IncredibleMock(), IncredibleMock())
89+
plugin = FakePlugin({}, self.controller)
6590
self.tc_editor = TestCaseEditor(
66-
plugin, wx.Frame(None), controller, None)
91+
plugin, wx.Frame(None), self.controller, None)
6792

6893
def test_delegation_to_kw_editor(self):
69-
for method, kw_method in \
70-
[('save', 'save'),
71-
# ('undo', 'on_undo'), # Disabled because of double Ctrl-Z
72-
('redo', 'on_redo'),
73-
('cut', 'on_cut'),
74-
('copy', 'on_copy'),
75-
('paste', 'on_paste'),
76-
('insert', 'on_insert'),
77-
('insert_cells', 'on_insert_cells'),
78-
('insert_rows', 'on_insert_rows'),
79-
('delete_rows', 'on_delete_rows'),
80-
('delete_cells', 'on_delete_cells'),
81-
('delete', 'on_delete'),
82-
('show_content_assist', 'show_content_assist')]:
94+
for method, kw_method in DELEGATED_METHODS:
95+
kw_mock = MockKwEditor()
96+
self.tc_editor.kweditor = kw_mock
97+
getattr(kw_mock, kw_method).is_to_be_called()
98+
getattr(self.tc_editor, method)()
99+
assert getattr(kw_mock, kw_method).has_been_called(), (f"Should have called \""
100+
f"{kw_method}\" when calling \"{method}\"")
101+
102+
self.tc_editor._populate()
103+
RideItemNameChanged(item=self.controller, old_name='Title of User Keyword', new_name="New Name").publish()
104+
# self.tc_editor._name_changed(message)
105+
# print(f"DEBUG: Name={self.tc_editor.header}")
106+
# assert self.tc_editor.title == "New Name"
107+
108+
109+
class MacroEditorUserKWTest(unittest.TestCase):
110+
111+
def setUp(self):
112+
myapp = wx.App(None)
113+
self.controller = TestCaseController(IncredibleMock(), IncredibleMock())
114+
plugin = FakePlugin({}, self.controller)
115+
self.tc_editor = UserKeywordEditor(
116+
plugin, wx.Frame(None), self.controller, None)
117+
118+
def test_delegation_to_kw_editor(self):
119+
for method, kw_method in DELEGATED_METHODS:
83120
kw_mock = MockKwEditor()
84121
self.tc_editor.kweditor = kw_mock
85122
getattr(kw_mock, kw_method).is_to_be_called()
86123
getattr(self.tc_editor, method)()
87124
assert getattr(kw_mock, kw_method).has_been_called(), (f"Should have called \""
88125
f"{kw_method}\" when calling \"{method}\"")
89126

127+
def test_header(self):
128+
myapp = wx.App(None)
129+
kw_mock = MockKwEditor()
130+
self.tc_editor.kweditor = kw_mock
131+
header = self.tc_editor._create_header(text="Title of User Keyword", readonly=False)
132+
assert isinstance(header, FindUsagesHeader)
133+
label = header._header.GetLabel()
134+
assert label == "Title of User Keyword"
135+
136+
def test_header_read_only(self):
137+
myapp = wx.App(None)
138+
kw_mock = MockKwEditor()
139+
self.tc_editor.kweditor = kw_mock
140+
header = self.tc_editor._create_header(text="Title of User Keyword", readonly=True)
141+
assert isinstance(header, FindUsagesHeader)
142+
label = header._header.GetLabel()
143+
assert label == "Title of User Keyword (READ ONLY)"
144+
145+
def test_misc(self):
146+
myapp = wx.App(None)
147+
kw_mock = MockKwEditor()
148+
self.tc_editor.kweditor = kw_mock
149+
self.tc_editor.undo() # Should do nothing
150+
self.tc_editor.close()
151+
90152

91153
if __name__ == '__main__':
92154
app = wx.App()

0 commit comments

Comments
 (0)