Skip to content

Commit c843738

Browse files
committed
Merge pull request #1573 from HelioGuilherme66/CleanUP_PR17
This is a review for PR#17 by @SimonElfvingElekta dated nov. 2013.
2 parents fc181e2 + 6758abb commit c843738

File tree

10 files changed

+330
-172
lines changed

10 files changed

+330
-172
lines changed

src/robotide/controller/macrocontrollers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def create_keyword(self, name, argstr):
232232

233233
def _remove_bdd_prefix(self, name):
234234
matcher = name.lower()
235-
for match in ['given ', 'when ', 'then ', 'and ']:
235+
for match in ['given ', 'when ', 'then ', 'and ', 'but ']:
236236
if matcher.startswith(match):
237237
return name[len(match):]
238238
return name

src/robotide/controller/stepcontrollers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
class StepController(_BaseController):
2626

27-
_GIVEN_WHEN_THEN_MATCHER = re.compile(r'^(given|when|then|and)\s*', re.I)
27+
_GIVEN_WHEN_THEN_MATCHER = re.compile(r'^(given|when|then|and|but)\s*',
28+
re.I)
2829

2930
def __init__(self, parent, step):
3031
self._init(parent, step)

src/robotide/editor/contentassist.py

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def __init__(self, suggestion_source):
3737
self.Bind(wx.EVT_MOVE, self.OnFocusLost)
3838
self._showing_content_assist = False
3939
self._row = None
40+
self.gherkin_prefix = '' # Store gherkin prefix from input to add \
41+
# later after search is performed
4042

4143
def set_row(self, row):
4244
self._row = row
@@ -48,7 +50,7 @@ def OnChar(self, event):
4850
if keycode == wx.WXK_SPACE and event.ControlDown():
4951
self.show_content_assist()
5052
return
51-
if keycode in [wx.WXK_UP, wx.WXK_DOWN, wx.WXK_PAGEUP, wx.WXK_PAGEDOWN] \
53+
if keycode in [wx.WXK_UP, wx.WXK_DOWN, wx.WXK_PAGEUP, wx.WXK_PAGEDOWN]\
5254
and self._popup.is_shown():
5355
self._popup.select_and_scroll(keycode)
5456
return
@@ -62,14 +64,16 @@ def OnChar(self, event):
6264
return
6365
elif self._popup.is_shown() and keycode < 256:
6466
self._populate_content_assist(event)
65-
elif keycode in (ord('1'), ord('2')) and event.ControlDown() and not event.AltDown():
66-
self.execute_variable_creator(list_variable=(keycode==ord('2')))
67+
elif keycode in (ord('1'), ord('2')) and event.ControlDown() and not \
68+
event.AltDown():
69+
self.execute_variable_creator(list_variable=(keycode == ord('2')))
6770
event.Skip()
6871

6972
def execute_variable_creator(self, list_variable=False):
7073
from_, to_ = self.GetSelection()
7174
symbol = '@' if list_variable else '$'
72-
self.SetValue(self._variable_creator_value(self.Value, symbol, from_, to_))
75+
self.SetValue(self._variable_creator_value(
76+
self.Value, symbol, from_, to_))
7377
if from_ == to_:
7478
self.SetInsertionPoint(from_ + 2)
7579
else:
@@ -81,7 +85,7 @@ def _variable_creator_value(self, value, symbol, from_, to_):
8185
def OnFocusLost(self, event, set_value=True):
8286
if not self._popup.is_shown():
8387
return
84-
value = self._popup.get_value()
88+
value = self.gherkin_prefix + self._popup.get_value()
8589
if set_value and value:
8690
self.SetValue(value)
8791
self.SetInsertionPoint(len(self.Value))
@@ -113,26 +117,41 @@ def _populate_content_assist(self, event=None):
113117
return False
114118
else:
115119
value += unichr(event.GetRawKeyCode())
120+
(self.gherkin_prefix, value) = self._remove_bdd_prefix(value)
116121
return self._popup.content_assist_for(value, row=self._row)
117122

123+
def _remove_bdd_prefix(self, name):
124+
for match in ['given ', 'when ', 'then ', 'and ', 'but ']:
125+
if name.lower().startswith(match):
126+
return (name[:len(match)], name[len(match):])
127+
return ('', name)
128+
118129
def _show_content_assist(self):
119130
height = self.GetSizeTuple()[1]
120131
x, y = self.ClientToScreenXY(0, 0)
121132
self._popup.show(x, y, height)
122133

123134
def content_assist_value(self):
124-
return self._popup.content_assist_value(self.Value)
135+
suggestion = self._popup.content_assist_value(self.Value)
136+
if suggestion is None:
137+
return suggestion
138+
else:
139+
return self.gherkin_prefix + suggestion
125140

126141
def hide(self):
127142
self._popup.hide()
128143
self._showing_content_assist = False
129144

130145

131-
class ExpandingContentAssistTextCtrl(_ContentAssistTextCtrlBase, ExpandoTextCtrl):
146+
class ExpandingContentAssistTextCtrl(_ContentAssistTextCtrlBase,
147+
ExpandoTextCtrl):
132148

133149
def __init__(self, parent, plugin, controller):
134-
ExpandoTextCtrl.__init__(self, parent, size=wx.DefaultSize, style=wx.WANTS_CHARS)
135-
_ContentAssistTextCtrlBase.__init__(self, SuggestionSource(plugin, controller))
150+
ExpandoTextCtrl.__init__(self, parent, size=wx.DefaultSize,
151+
style=wx.WANTS_CHARS)
152+
_ContentAssistTextCtrlBase.__init__(self,
153+
SuggestionSource(plugin,
154+
controller))
136155

137156

138157
class ContentAssistTextCtrl(_ContentAssistTextCtrlBase, wx.TextCtrl):
@@ -144,10 +163,11 @@ def __init__(self, parent, suggestion_source, size=wx.DefaultSize):
144163

145164
class ContentAssistFileButton(_ContentAssistTextCtrlBase, FileBrowseButton):
146165

147-
def __init__(self, parent, suggestion_source, label, controller, size=wx.DefaultSize):
166+
def __init__(self, parent, suggestion_source, label, controller,
167+
size=wx.DefaultSize):
148168
FileBrowseButton.__init__(self, parent, labelText=label,
149-
size=size, fileMask="*",
150-
changeCallback=self.OnFileChanged)
169+
size=size, fileMask="*",
170+
changeCallback=self.OnFileChanged)
151171
self._parent = parent
152172
self._controller = controller
153173
self._browsed = False
@@ -183,10 +203,11 @@ def SelectAll(self):
183203
def _relative_path(self, value):
184204
src = self._controller.datafile.source
185205
if utils.is_same_drive(src, value):
186-
path = relpath(value, src if isdir(src) else dirname(src))
206+
path = relpath(value, src if isdir(src) else dirname(src))
187207
else:
188208
path = value
189-
return path.replace('\\', '/') if context.IS_WINDOWS else path.replace('\\', '\\\\')
209+
return path.replace('\\', '/') if context.IS_WINDOWS else\
210+
path.replace('\\', '\\\\')
190211

191212

192213
class Suggestions(object):
@@ -199,7 +220,7 @@ def __init__(self, suggestion_source):
199220
def get_for(self, value, row=None):
200221
self._previous_choices = self._get_choices(value, row)
201222
self._previous_value = value
202-
return [k for k,_ in self._previous_choices]
223+
return [k for k, _ in self._previous_choices]
203224

204225
def get_item(self, name):
205226
for k, v in self._previous_choices:
@@ -210,7 +231,7 @@ def get_item(self, name):
210231
def _get_choices(self, value, row):
211232
if self._previous_value and value.startswith(self._previous_value):
212233
return [(key, val) for key, val in self._previous_choices
213-
if utils.normalize(key).startswith(utils.normalize(value))]
234+
if utils.normalize(key).startswith(utils.normalize(value))]
214235
choices = self._suggestion_source.get_suggestions(value, row)
215236
duplicate_names = self._get_duplicate_names(choices)
216237
return self._format_choices(choices, value, duplicate_names)
@@ -225,15 +246,18 @@ def _get_duplicate_names(self, choices):
225246
return results
226247

227248
def _format_choices(self, choices, prefix, duplicate_names):
228-
return [(self._format(val, prefix, duplicate_names), val) for val in choices]
249+
return [(self._format(val, prefix, duplicate_names), val) for val in
250+
choices]
229251

230252
def _format(self, choice, prefix, duplicate_names):
231-
return choice.name if self._matches_unique_shortname(choice, prefix, duplicate_names) else choice.longname
253+
return choice.name if self._matches_unique_shortname(
254+
choice, prefix, duplicate_names) else choice.longname
232255

233256
def _matches_unique_shortname(self, choice, prefix, duplicate_names):
234257
if isinstance(choice, VariableInfo):
235258
return True
236-
if not utils.normalize(choice.name).startswith(utils.normalize(prefix)):
259+
if not utils.normalize(choice.name).startswith(
260+
utils.normalize(prefix)):
237261
return False
238262
if utils.normalize(choice.name) in duplicate_names:
239263
return False
@@ -247,15 +271,17 @@ def __init__(self, parent, suggestion_source):
247271
self._main_popup = RidePopupWindow(parent, _PREFERRED_POPUP_SIZE)
248272
self._details_popup = HtmlPopupWindow(parent, _PREFERRED_POPUP_SIZE)
249273
self._selection = -1
250-
self._list = ContentAssistList(self._main_popup, self.OnListItemSelected,
274+
self._list = ContentAssistList(self._main_popup,
275+
self.OnListItemSelected,
251276
self.OnListItemActivated)
252277
self._suggestions = Suggestions(suggestion_source)
253278

254279
def reset(self):
255280
self._selection = -1
256281

257282
def get_value(self):
258-
return self._selection != -1 and self._list.get_text(self._selection) or None
283+
return self._selection != -1 and self._list.get_text(
284+
self._selection) or None
259285

260286
def content_assist_for(self, value, row=None):
261287
self._choices = self._suggestions.get_for(value, row=row)
@@ -275,9 +301,12 @@ def content_assist_value(self, value):
275301
return None
276302

277303
def show(self, xcoord, ycoord, cell_height):
278-
self._main_popup.SetPosition((xcoord, self._move_y_where_room(ycoord, cell_height)))
304+
self._main_popup.SetPosition((xcoord,
305+
self._move_y_where_room(ycoord,
306+
cell_height)))
279307
self._details_popup.SetPosition((self._move_x_where_room(xcoord),
280-
self._move_y_where_room(ycoord, cell_height)))
308+
self._move_y_where_room(ycoord,
309+
cell_height)))
281310
self._main_popup.Show()
282311
self._list.SetFocus()
283312

@@ -303,13 +332,13 @@ def is_shown(self):
303332

304333
def select_and_scroll(self, keycode):
305334
sel = self._list.GetFirstSelected()
306-
if keycode == wx.WXK_DOWN :
335+
if keycode == wx.WXK_DOWN:
307336
if sel < (self._list.GetItemCount() - 1):
308337
self._select_and_scroll(sel + 1)
309338
else:
310339
self._select_and_scroll(0)
311340
elif keycode == wx.WXK_UP:
312-
if sel > 0 :
341+
if sel > 0:
313342
self._select_and_scroll(sel - 1)
314343
else:
315344
self._select_and_scroll(self._list.GetItemCount() - 1)

src/robotide/editor/robotframeworklexer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def _tokenize(self, value, index):
275275

276276

277277
class GherkinTokenizer(object):
278-
_gherkin_prefix = re.compile('^(Given|When|Then|And) ', re.IGNORECASE)
278+
_gherkin_prefix = re.compile('^(Given|When|Then|And|But) ', re.IGNORECASE)
279279

280280
def tokenize(self, value, token):
281281
match = self._gherkin_prefix.match(value)
@@ -321,7 +321,7 @@ def tokenize(self, value, index):
321321

322322
def _continues(self, value, index):
323323
return value == '...' and all(self._is_empty(t)
324-
for t in self._prev_values_on_row)
324+
for t in self._prev_values_on_row)
325325

326326
def _is_empty(self, value):
327327
return value in ('', '\\')
@@ -367,8 +367,8 @@ class TestCaseTable(_Table):
367367

368368
@property
369369
def _tokenizer_class(self):
370-
if self._test_template or (self._default_template and
371-
self._test_template is not False):
370+
if self._test_template or (self._default_template
371+
and self._test_template is not False):
372372
return TemplatedKeywordCall
373373
return KeywordCall
374374

@@ -470,7 +470,7 @@ def _split(self, string):
470470
self._state(char, index)
471471
except StopIteration:
472472
return
473-
if index == max_index and not self._scanning_list_variable_index():
473+
if index == max_index and not self._scanning_list_variable_index():
474474
return
475475

476476
def _scanning_list_variable_index(self):

src/robotide/namespace/namespace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def _add_resource(self, res, ctx, items):
521521

522522
class _Keywords(object):
523523

524-
regexp = re.compile("\s*(given|when|then|and)\s*(.*)", re.IGNORECASE)
524+
regexp = re.compile("\s*(given|when|then|and|but)\s*(.*)", re.IGNORECASE)
525525

526526
def __init__(self, keywords):
527527
self.keywords = robotapi.NormalizedDict(ignore=['_'])

utest/controller/test_macro_commands.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
from robotide.robotapi import TestCaseFile
55
from robotide.controller.filecontrollers import TestCaseFileController
6-
from robotide.publish.messages import RideUserKeywordAdded, RideUserKeywordRemoved,\
7-
RideTestCaseAdded, RideTestCaseRemoved, RideItemNameChanged
6+
from robotide.publish.messages import RideUserKeywordAdded,\
7+
RideUserKeywordRemoved, RideTestCaseAdded, RideTestCaseRemoved,\
8+
RideItemNameChanged
89
from robotide.controller.commands import AddKeyword, RemoveMacro, Undo,\
910
AddTestCase, AddKeywordFromCells, RenameTest
1011
from robotide.publish import PUBLISHER
@@ -16,7 +17,8 @@ class _TestMacroCommands(object):
1617

1718
def setUp(self):
1819
for listener, topic in [(self._on_keyword_added, RideUserKeywordAdded),
19-
(self._on_keyword_deleted, RideUserKeywordRemoved),
20+
(self._on_keyword_deleted,
21+
RideUserKeywordRemoved),
2022
(self._on_test_added, RideTestCaseAdded),
2123
(self._on_test_deleted, RideTestCaseRemoved)]:
2224
PUBLISHER.subscribe(listener, topic)
@@ -99,7 +101,8 @@ def test_add_keyword_with_bdd_given(self):
99101

100102
def _bdd_test(self, prefix, new_kw_name):
101103
self._exec(AddKeyword(prefix + ' ' + new_kw_name))
102-
assert_equals(self._new_keyword.name, self._bdd_name(prefix, new_kw_name))
104+
assert_equals(self._new_keyword.name, self._bdd_name(prefix,
105+
new_kw_name))
103106
assert_equals(self._new_keyword.arguments.value, '')
104107

105108
def test_add_keyword_with_bdd_when(self):
@@ -114,7 +117,13 @@ def test_add_keyword_with_bdd_and(self):
114117
self._bdd_test('And', 'the end')
115118
self._bdd_test('and', 'really no more')
116119

117-
class TestMacroCommandsInTestCaseContext(_TestMacroCommands, unittest.TestCase):
120+
def test_add_keyword_with_bdd_but(self):
121+
self._bdd_test('But', 'george awakes')
122+
self._bdd_test('but', 'steve says bye')
123+
124+
125+
class TestMacroCommandsInTestCaseContext(_TestMacroCommands,
126+
unittest.TestCase):
118127

119128
def setUp(self):
120129
_TestMacroCommands.setUp(self)
@@ -124,7 +133,8 @@ def _bdd_name(self, prefix, name):
124133
return name
125134

126135

127-
class TestMacroCommandsInDataFileContext(_TestMacroCommands, unittest.TestCase):
136+
class TestMacroCommandsInDataFileContext(_TestMacroCommands,
137+
unittest.TestCase):
128138

129139
def setUp(self):
130140
_TestMacroCommands.setUp(self)

0 commit comments

Comments
 (0)