Coverage for src/robotide/controller/tablecontrollers.py: 100%

345 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-06 10:40 +0100

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 

16from .. import utils 1ab

17from ..publish import (RideTestCaseRemoved, RideVariableAdded, RideVariableRemoved, RideVariableMovedUp, 1ab

18 RideVariableMovedDown, RideUserKeywordRemoved, RideUserKeywordAdded, RideTestCaseAdded) 

19from ..publish.messages import RideItemMovedUp, RideItemMovedDown 1ab

20from ..robotapi import is_list_var, is_scalar_var, is_dict_var 1ab

21from ..utils import variablematcher 1ab

22from .basecontroller import ControllerWithParent 1ab

23from . import macrocontrollers # TestCaseController, UserKeywordController 1ab

24from .settingcontrollers import MetadataController, import_controller, VariableController 1ab

25 

26 

27class WithListOperations(object): 1ab

28 

29 def move_up(self, index): 1ab

30 if index > 0: 2jbVcIeFb

31 self._swap(index - 1, index) 2jbVcFb

32 

33 def move_down(self, index): 1ab

34 if index < len(self._items) - 1: 2kbWcJeGb

35 self._swap(index, index + 1) 2kbWcGb

36 

37 def _swap(self, ind1, ind2): 1ab

38 self._items[ind1], self._items[ind2] = self._items[ind2], self._items[ind1] 2kbjbWcVcGbFb

39 self.mark_dirty() 2kbjbWcVcGbFb

40 

41 def delete(self, index): 1ab

42 if isinstance(self._items, list): 2s F fb2cL f g

43 self._items.pop(index) 22c

44 else: 

45 self._items.data.pop(index) 2s F fbL f g

46 self.mark_dirty() 2s F fb2cL f g

47 

48 @property 1ab

49 def _items(self): 1ab

50 raise NotImplementedError(self.__class__) 2Ke

51 

52 def mark_dirty(self): 1ab

53 raise NotImplementedError(self.__class__) 2Le

54 

55 

56class _TableController(ControllerWithParent): 1ab

57 

58 def __init__(self, parent_controller, table): 1ab

59 self._parent = parent_controller 2a 4b5bAbs 6bHb7b8 9 ! 1 2 3 4 5 # ' P ( p Q H IbtbubnbobvbpbJbu v t n w x y z A ) o j B XcL 8bKbLbC D I J ,b-bM R BbMbNbObPb.b/b:bQbRbSbCbTbDbUbVbWbXbYbZb;b=bEbi f k l m g S T ?bYcZc5c6c7c8c0c1c9b!b#b$b%b'b(b* + , - . / U V W X : ; = Y Z 0 wb3c

60 self._table = table 2a 4b5bAbs 6bHb7b8 9 ! 1 2 3 4 5 # ' P ( p Q H IbtbubnbobvbpbJbu v t n w x y z A ) o j B XcL 8bKbLbC D I J ,b-bM R BbMbNbObPb.b/b:bQbRbSbCbTbDbUbVbWbXbYbZb;b=bEbi f k l m g S T ?bYcZc5c6c7c8c0c1c9b!b#b$b%b'b(b* + , - . / U V W X : ; = Y Z 0 wb3c

61 

62 @staticmethod 1ab

63 def _index_difference(original_list, sorted_list): 1ab

64 """Determines the difference in sorting order for undo/redo""" 

65 index_difference = [] 1NpQH

66 for item in original_list: 1NpQH

67 counter = 0 1NpQH

68 for item2 in sorted_list: 1NpQH

69 if item.name == item2.name: 1NpQH

70 index_difference.append(counter) 1NpQH

71 break 1NpQH

72 counter += 1 1NpQH

73 return index_difference 1NpQH

74 

75 

76class VariableTableController(_TableController, WithListOperations): 1ab

77 

78 def __init__(self, parent_controller, table): 1ab

79 _TableController.__init__(self, parent_controller, table) 2a 4 5 H XcI J M 0c1c

80 self._variable_cache = {} 2a 4 5 H XcI J M 0c1c

81 

82 def _get(self, variable): 1ab

83 if variable not in self._variable_cache: 2a qbAcxbBcN kbjbncoc? 4 5 H I J 6 c d e h r

84 self._variable_cache[variable] = VariableController(self, variable) 2a qbAcxbBcN kbjbncoc? 4 5 H I J 6 c d e h r

85 return self._variable_cache[variable] 2a qbAcxbBcN kbjbncoc? 4 5 H I J 6 c d e h r

86 

87 def __iter__(self): 1ab

88 return iter(self._get(v) for v in self._table) 2a qbxbN ? 4 5 H I J 6 )b*bc d 7 e h r

89 

90 def __getitem__(self, index): 1ab

91 return self._get(self._items[index]) 2qbAcxbBcN kbjbncoc4 5 I J 6 c d e h r

92 

93 def index(self, ctrl): 1ab

94 return [v for v in self].index(ctrl) 2qbN 4 5 I J 6 c d e h r

95 

96 @property 1ab

97 def _items(self): 1ab

98 return self._table.variables 2qbAcxbBcN kbjbncoc4 5 I J 6 M ybR zbc d e h r

99 

100 def move_up(self, index): 1ab

101 if index == 0: 2jbnc

102 return False 2nc

103 ctrl = self[index] 2jb

104 WithListOperations.move_up(self, index) 2jb

105 other = self[index] 2jb

106 self.mark_dirty() 2jb

107 RideVariableMovedUp(item=ctrl, other=other).publish() 2jb

108 

109 def move_down(self, index): 1ab

110 if index + 1 == len(self._items): 2kboc

111 return False 2oc

112 ctrl = self[index] 2kb

113 WithListOperations.move_down(self, index) 2kb

114 other = self[index] 2kb

115 self.mark_dirty() 2kb

116 RideVariableMovedDown(item=ctrl, other=other).publish() 2kb

117 

118 def add_variable(self, name, value, comment=None): 1ab

119 self._table.add(name, value, comment) 2qbN 4 5 I J 6 c d e h r

120 self.mark_dirty() 2qbN 4 5 I J 6 c d e h r

121 var_controller = self[-1] 2qbN 4 5 I J 6 c d e h r

122 self.notify_variable_added(var_controller) 2qbN 4 5 I J 6 c d e h r

123 return var_controller 2qbN 4 5 I J 6 c d e h r

124 

125 def validate_scalar_variable_name(self, name, item=None): 1ab

126 return self._validate_name(_ScalarVarValidator(), name, item) 1cd7eh

127 

128 def validate_list_variable_name(self, name, item=None): 1ab

129 return self._validate_name(_ListVarValidator(), name, item) 1cd7eh

130 

131 def validate_dict_variable_name(self, name, item=None): 1ab

132 return self._validate_name(_DictVarValidator(), name, item) 1?

133 

134 def _validate_name(self, validator, name, item=None): 1ab

135 return VariableNameValidation(self, validator, name, item) 1?cd7eh

136 

137 def delete(self, index): 1ab

138 self.remove_var(self[index]) 2xb

139 

140 def remove_var(self, var_controller): 1ab

141 self._items.remove(var_controller.data) 2xbI J 6

142 del self._variable_cache[var_controller.data] 2xbI J 6

143 self.mark_dirty() 2xbI J 6

144 self.notify_variable_removed(var_controller) 2xbI J 6

145 

146 def notify_variable_added(self, ctrl): 1ab

147 self.datafile_controller.update_namespace() 2qbN 4 5 I J 6 c d e h r

148 RideVariableAdded(datafile=self.datafile, 2qbN 4 5 I J 6 c d e h r

149 name=ctrl.name, item=ctrl, 

150 index=ctrl.index).publish() 

151 

152 def notify_variable_removed(self, ctrl): 1ab

153 self.datafile_controller.update_namespace() 2xbI J 6

154 RideVariableRemoved(datafile=self.datafile, name=ctrl.name, item=ctrl).publish() 2xbI J 6

155 

156 def contains_variable(self, name): 1ab

157 vars_as_list = [] 2M ybR zb

158 for var in self._items: 2M ybR zb

159 vars_as_list += var.as_list() 2M ybR zb

160 return any(variablematcher.value_contains_variable(string, name) 2M ybR zb

161 for string in vars_as_list) 

162 

163 def sort(self): 1ab

164 """Sorts the variables of the controller by name""" 

165 variables_sorted = sorted(self._table.variables, key=lambda variable: variable.name) 1H

166 index_difference = self._index_difference(self._table.variables, variables_sorted) 1H

167 self._table.variables = variables_sorted 1H

168 return index_difference 1H

169 

170 def restore_variable_order(self, rlist): 1ab

171 """Restores the old order of the variable list""" 

172 variables_temp = [] 1H

173 for i in rlist: 1H

174 variables_temp.append(self._table.variables[i]) 1H

175 self._table.variables = variables_temp 1H

176 

177 

178class _ScalarVarValidator(object): 1ab

179 __call__ = lambda self, name: is_scalar_var(name) 1abcd7eh

180 name = 'Scalar' 1ab

181 prefix = '$' 1ab

182 

183 

184class _ListVarValidator(object): 1ab

185 __call__ = lambda self, name: is_list_var(name) 1abcd7eh

186 name = 'List' 1ab

187 prefix = '@' 1ab

188 

189 

190class _DictVarValidator(object): 1ab

191 __call__ = lambda self, name: is_dict_var(name) 1ab?

192 name = 'Dictionary' 1ab

193 prefix = '&' 1ab

194 

195 

196class _NameValidation(object): 1ab

197 

198 def __init__(self, table, name, named_ctrl=None): 1ab

199 self._table = table 2q ? u v t n w x y z A o j E G 0b1b+b2bc d 7 e h

200 self.error_message = '' 2q ? u v t n w x y z A o j E G 0b1b+b2bc d 7 e h

201 self._named_ctrl = named_ctrl 2q ? u v t n w x y z A o j E G 0b1b+b2bc d 7 e h

202 self._validate(name.strip()) 2q ? u v t n w x y z A o j E G 0b1b+b2bc d 7 e h

203 

204 def _name_taken(self, name): 1ab

205 return any(utils.eq(name, item.name, ignore=['_']) 2q ? u v t n w x y z A o j E G 0b1b+b2bc d 7 e h

206 for item in self._table if item != self._named_ctrl) 

207 

208 

209class VariableNameValidation(_NameValidation): 1ab

210 

211 def __init__(self, table, validator, name, named_ctrl=None): 1ab

212 self._validator = validator 1?cd7eh

213 _NameValidation.__init__(self, table, name, named_ctrl) 1?cd7eh

214 

215 def _validate(self, name): 1ab

216 if not self._validator(name): 1?cd7eh

217 self.error_message = '%s variable name must be in format %s{name}' % \ 1?

218 (self._validator.name, self._validator.prefix) 

219 if self._name_taken(name): 1?cd7eh

220 self.error_message = 'Variable with this name already exists.' 1?cde

221 

222 

223class MacroNameValidation(_NameValidation): 1ab

224 

225 def _validate(self, name): 1ab

226 if not name: 2q u v t n w x y z A o j E G 0b1b+b2bc d 7 e h

227 self.error_message = '%s name cannot be empty.' % \ 20b1b

228 self._table.item_type 

229 if self._name_taken(name): 2q u v t n w x y z A o j E G 0b1b+b2bc d 7 e h

230 self.error_message = '%s with this name already exists.' % \ 1Ecde

231 self._table.item_type 

232 if "\n" in name: 2q u v t n w x y z A o j E G 0b1b+b2bc d 7 e h

233 self.error_message = '%s name contains newlines' % \ 22b

234 self._table.item_type 

235 

236 

237class _MacroTable(_TableController): 1ab

238 

239 @property 1ab

240 def items(self): 1ab

241 raise NotImplementedError(self.__class__) 23c

242 

243 def __iter__(self): 1ab

244 return iter(self._create_controller(item) for item in self._table) 2a q 8 9 ! 1 @ [ ] p u v t n w x y z A o j ,b-bCcDcEcFcGcHcIcM ybR zbBbMbNbObPb.b/b:bQbRbSbCbTbDbUbVbWbXbYbZb;bJcKcLcMc=bNcOcPcQcRcScTc@b[bpcEbE G 0b1b+b?b)b*b2bc d 7 e h

245 

246 def _create_controller(self, item): 1ab

247 if item not in self._item_to_controller: 2a 4b5bq 8 9 ! 1 @ [ ] 2 3 # ' P ( p Ib]b^b_b`b{b|bqc}b~bacbcccrcdcecfcgcschcicjckcu v t n w x y z A ) o j B ^ _ ` { gbhbKbLbC D K O ,b-bCcDcEcFcGcHcIcM ybR zbBbMbNbObPb.b/b:bQbRbSbCbTbDbUbVbWbXbYbZb;bJcKcLcMc=bNcOcPcQcRcScTc@b[bpcEbi f k l m g ibE G S | T } ?bvc9b!b#b$b%b'b(b* + , - . / U V W X : ; = Y Z 0 lbmbwcxc)b*bc d e h r

248 self._item_to_controller[item] = self._controller_class(self, item) 2a 4b5bq 8 9 ! 1 @ [ ] 2 3 # ' P ( p Ib]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckcu v t n w x y z A ) o j B ^ _ ` { gbhbKbLbC D K O ,b-bBbMbNbObPb.b/b:bQbRbSbCbTbDbUbVbWbXbYbZb;b=bEbi f k l m g ibE G S | T } ?b9b!b#b$b%b'b(b* + , - . / U V W X : ; = Y Z 0 lbmbc d e h r

249 return self._item_to_controller[item] 2a 4b5bq 8 9 ! 1 @ [ ] 2 3 # ' P ( p Ib]b^b_b`b{b|bqc}b~bacbcccrcdcecfcgcschcicjckcu v t n w x y z A ) o j B ^ _ ` { gbhbKbLbC D K O ,b-bCcDcEcFcGcHcIcM ybR zbBbMbNbObPb.b/b:bQbRbSbCbTbDbUbVbWbXbYbZb;bJcKcLcMc=bNcOcPcQcRcScTc@b[bpcEbi f k l m g ibE G S | T } ?bvc9b!b#b$b%b'b(b* + , - . / U V W X : ; = Y Z 0 lbmbwcxc)b*bc d e h r

250 

251 @property 1ab

252 def _item_to_controller(self): 1ab

253 if not hasattr(self, '_item_to_controller_attribute'): 2a 4b5bq 8 9 ! 1 @ [ ] 2 3 # ' P ( p Ib]b^b_b`b{b|bqc}b~bacbcccrcdcecfcgcschcicjckcu v t n w x y z A ) o j B ^ _ ` { 3bgbhbKbLbC D K O ,b-bCcDcEcFcGcHcIcM ybR zbBbMbNbObPb.b/b:bQbRbSbCbTbDbUbVbWbXbYbZb;bJcKcLcMc=bNcOcPcQcRcScTc@b[bpcEbi f k l m g ibE G S | T } ?bvc9b!b#b$b%b'b(b* + , - . / U V W X : ; = Y Z 0 lbmbwcxc)b*bc d e h r

254 self._item_to_controller_attribute = {} 2a 4b5b8 9 ! 2 3 # ' P ( p Ibu v t n w x y z A ) o j B ^ _ ` { 3bgbhbKbLbC D ,b-bBbMbNbObPb.b/b:bQbRbSbCbTbDbUbVbWbXbYbZb;b=bEbi f k l m g ibE G S T ?b9b!b#b$b%b'b(b* + , - . / U V W X : ; = Y Z 0 c d e h r

255 return self._item_to_controller_attribute 2a 4b5bq 8 9 ! 1 @ [ ] 2 3 # ' P ( p Ib]b^b_b`b{b|bqc}b~bacbcccrcdcecfcgcschcicjckcu v t n w x y z A ) o j B ^ _ ` { 3bgbhbKbLbC D K O ,b-bCcDcEcFcGcHcIcM ybR zbBbMbNbObPb.b/b:bQbRbSbCbTbDbUbVbWbXbYbZb;bJcKcLcMc=bNcOcPcQcRcScTc@b[bpcEbi f k l m g ibE G S | T } ?bvc9b!b#b$b%b'b(b* + , - . / U V W X : ; = Y Z 0 lbmbwcxc)b*bc d e h r

256 

257 def __len__(self): 1ab

258 return len(self.items) 2a 9c!c#c$c%cq 'c(c)c*c+c,c-cs F ~ abbb.c/c:c;c=c?c@c[c]c^c1 _c`c{c@ [ ] |c}c~cadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d2 3 4 5 # P p Q Ib]b^b_b`b{b|bqc}b~bacbcccrcdcecfcgcschcicjckc.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekelemeneoepeqeresetet n o j B ^ _ ueve` { 3bweKbLbC D K O BbMbNbObPbQbRbSbCbTbDbUbVbWbXbYbZb@b[bpcEbi f k l m g xeyezeAeBeCeDeS | T } YcZcEeU V W X Y Z 0 )b*b

259 

260 def __getitem__(self, index): 1ab

261 return self._create_controller(self.items[index]) 2a 4b5b# Ib]b^b_b`b{b|bqc}b~bacbcccrcdcecfcgcschcicjckcKbLbC D K O i S | T } vc9b!b#b$b%b'b(bwcxc)b*b

262 

263 def move_up(self, item): 1ab

264 items = self.items 2hb

265 idx = items.index(item) 2hb

266 if idx == 0: 2hb

267 return False 2hb

268 upper = idx - 1 2hb

269 items[upper], items[idx] = items[idx], items[upper] 2hb

270 self.mark_dirty() 2hb

271 RideItemMovedUp(item=self._create_controller(item)).publish() 2hb

272 return True 2hb

273 

274 def move_down(self, item): 1ab

275 items = self.items 2gb

276 idx = items.index(item) 2gb

277 if idx + 1 == len(items): 2gb

278 return False 2gb

279 lower = idx + 1 2gb

280 items[idx], items[lower] = items[lower], items[idx] 2gb

281 self.mark_dirty() 2gb

282 RideItemMovedDown(item=self._create_controller(item)).publish() 2gb

283 return True 2gb

284 

285 def validate_name(self, name, named_ctrl=None): 1ab

286 return MacroNameValidation(self, name, named_ctrl) 2q u v t n w x y z A o j E G 0b1b+b2bc d 7 e h

287 

288 def delete(self, ctrl): 1ab

289 self.items.remove(ctrl.data) 2q n o j B 3bC D K O

290 if ctrl.data in self._item_to_controller: 2q n o j B 3bC D K O

291 del self._item_to_controller[ctrl.data] 1qnojBCDKO

292 self.datafile_controller.update_namespace() 2q n o j B 3bC D K O

293 self.mark_dirty() 2q n o j B 3bC D K O

294 self._notify_removal(ctrl) 2q n o j B 3bC D K O

295 

296 def add(self, ctrl): 1ab

297 item = ctrl.data 1#pjCDKO

298 item.parent = self._table 1#pjCDKO

299 self.items.append(item) 1#pjCDKO

300 new_controller = self._create_controller(item) 1#pjCDKO

301 self.datafile_controller.update_namespace() 1#pjCDKO

302 self.mark_dirty() 1#pjCDKO

303 self._notify_creation(new_controller.name, new_controller) 1#pjCDKO

304 

305 def _create_new(self, name, config=None): 1ab

306 name = name.strip() 2a q 8 9 ! 1 @ [ ] 2 3 ' P ( u v t n w x y z A ) o j B ^ _ ` { i f k l m g ibE G S | T } * + , - . / U V W X : ; = Y Z 0 lbmbc d e h r

307 ctrl = self._create_controller(self._table.add(name)) 2a q 8 9 ! 1 @ [ ] 2 3 ' P ( u v t n w x y z A ) o j B ^ _ ` { i f k l m g ibE G S | T } * + , - . / U V W X : ; = Y Z 0 lbmbc d e h r

308 self._configure_controller(ctrl, config) 2a q 8 9 ! 1 @ [ ] 2 3 ' P ( u v t n w x y z A ) o j B ^ _ ` { i f k l m g ibE G S | T } * + , - . / U V W X : ; = Y Z 0 lbmbc d e h r

309 self.datafile_controller.update_namespace() 2a q 8 9 ! 1 @ [ ] 2 3 ' P ( u v t n w x y z A ) o j B ^ _ ` { i f k l m g ibE G S | T } * + , - . / U V W X : ; = Y Z 0 lbmbc d e h r

310 self.mark_dirty() 2a q 8 9 ! 1 @ [ ] 2 3 ' P ( u v t n w x y z A ) o j B ^ _ ` { i f k l m g ibE G S | T } * + , - . / U V W X : ; = Y Z 0 lbmbc d e h r

311 self._notify_creation(name, ctrl) 2a q 8 9 ! 1 @ [ ] 2 3 ' P ( u v t n w x y z A ) o j B ^ _ ` { i f k l m g ibE G S | T } * + , - . / U V W X : ; = Y Z 0 lbmbc d e h r

312 return ctrl 2a q 8 9 ! 1 @ [ ] 2 3 ' P ( u v t n w x y z A ) o j B ^ _ ` { i f k l m g ibE G S | T } * + , - . / U V W X : ; = Y Z 0 lbmbc d e h r

313 

314 def _configure_controller(self, ctrl, config): 1ab

315 """ Don't know this exists ;) """ 

316 pass 2a 8 9 ! 1 @ [ ] ( ) B ^ _ ibE G T } * + , - . / lbc d e h r

317 

318 

319class TestCaseTableController(_MacroTable): 1ab

320 __test__ = False 1ab

321 item_type = 'Test case' 1ab

322 _controller_class = macrocontrollers.TestCaseController 1ab

323 

324 @property 1ab

325 def items(self): 1ab

326 return self._table.tests 2a 4b5b9c!c#c$c%cq 'c(c)c*c+c,c-cs F ~ abbb.c?c@c[c]c^c1 _c`c{c@ [ ] |c}c~cadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d2 3 4 5 # p Ib]b^b_b`b{b|bqc}b~bacbcccrcdcecfcgcschcicjckc.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekelemeneoepeqereseteB ^ _ ueveKbC D K O BbMbNbObPbQbRbCbTbDbUbVbWbXbYb@b[bEbxeyezeAeBeCeDeT } YcZcEevc#b)b*b

327 

328 def _notify_creation(self, name, ctrl): 1ab

329 RideTestCaseAdded(datafile=self.datafile, name=name, item=ctrl).publish() 2a 8 9 ! 1 @ [ ] # ( p ) B ^ _ O ibE G T } * + , - . / lbc d e h r

330 

331 def _notify_removal(self, item): 1ab

332 RideTestCaseRemoved(datafile=self.datafile, name=item.name, item=item).publish() 1BO

333 

334 def new(self, name): 1ab

335 return self._create_new(name) 2a 8 9 ! 1 @ [ ] ( ) B ^ _ ibE G T } * + , - . / lbc d e h r

336 

337 def sort(self): 1ab

338 """Sorts the tests of the controller by name""" 

339 tests_sorted = sorted(self._table.tests, key=lambda testcase: testcase.name) 1p

340 index_difference = self._index_difference(self._table.tests, tests_sorted) 1p

341 self._table.tests = tests_sorted 1p

342 return index_difference 1p

343 

344 def restore_test_order(self, rlist): 1ab

345 """Restores the old order of the test list""" 

346 tests_temp = [] 1p

347 for i in rlist: 1p

348 tests_temp.append(self._table.tests[i]) 1p

349 self._table.tests = tests_temp 1p

350 

351 

352class KeywordTableController(_MacroTable): 1ab

353 item_type = 'User keyword' 1ab

354 _controller_class = macrocontrollers.UserKeywordController 1ab

355 

356 @property 1ab

357 def items(self): 1ab

358 return self._table.keywords 2a q /c:c;c=cP Q t n o j ` { 3bwegbhbLbC D K BbSbCbDbZb@b[bpcEbi f k l m g S | 9b!b$b%b'b(bU V W X Y Z 0 wcxc)b*b

359 

360 def _notify_creation(self, name, ctrl): 1ab

361 # print("DEBUG notify_creation %s" % name) 

362 RideUserKeywordAdded(datafile=self.datafile, name=name, item=ctrl).publish() 2q 2 3 ' P u v t n w x y z A o j ` { C D K i f k l m g S | U V W X : ; = Y Z 0 mbc d e h r

363 

364 def _notify_removal(self, item): 1ab

365 # print("DEBUG notify_removal %s" % item.name) 

366 RideUserKeywordRemoved(datafile=self.datafile, name=item.name, item=item).publish() 2q n o j 3bC D K

367 

368 def new(self, name, argstr=''): 1ab

369 return self._create_new(name, argstr) 2q 2 3 ' P u v t n w x y z A o j ` { i f k l m g S | U V W X : ; = Y Z 0 mbc d e h r

370 

371 def _configure_controller(self, ctrl, config): 1ab

372 if config: 2q 2 3 ' P u v t n w x y z A o j ` { i f k l m g S | U V W X : ; = Y Z 0 mbc d e h r

373 ctrl.arguments.set_value(config) 1qPtifklmgUVWXYZ0

374 

375 def sort(self): 1ab

376 """Sorts the keywords of the controller by name""" 

377 keywords_sorted = sorted(self._table.keywords, key=lambda userkeyword: userkeyword.name) 1Q

378 index_difference = self._index_difference(self._table.keywords, keywords_sorted) 1Q

379 self._table.keywords = keywords_sorted 1Q

380 return index_difference 1Q

381 

382 def restore_keyword_order(self, rlist): 1ab

383 """Restores the old order of the keyword list""" 

384 keywords_temp = [] 1Q

385 for i in rlist: 1Q

386 keywords_temp.append(self._table.keywords[i]) 1Q

387 self._table.keywords = keywords_temp 1Q

388 

389 

390class ImportSettingsController(_TableController, WithListOperations): 1ab

391 

392 def __init__(self, parent_controller, table, resource_file_controller_factory=None): 1ab

393 _TableController.__init__(self, parent_controller, table) 2a Abs 6bHb7btbubnbobvbpbJbL 8bM R i f k l m g wb

394 self._resource_file_controller_factory = resource_file_controller_factory 2a Abs 6bHb7btbubnbobvbpbJbL 8bM R i f k l m g wb

395 self.__import_controllers = None 2a Abs 6bHb7btbubnbobvbpbJbL 8bM R i f k l m g wb

396 

397 def __iter__(self): 1ab

398 return iter(self._import_controllers) 2a Ab6bHb7btbubnbobvbpbJbL 8bM ybR zbi f k l m g GbFbwb

399 

400 def __getitem__(self, index): 1ab

401 return self._import_controllers[index] 2a s F ~ abbbyczclctcuccb$ rbmcfbdb% sbtbubnbobvbpbL i f k l m g wbeb4c

402 

403 @property 1ab

404 def _import_controllers(self): 1ab

405 if self.__import_controllers is None: 2a Abs F ~ abbb6bHb7byczclctcuccb$ rbmcfbdb% sbtbubnbobvbpbJbL 8bM ybR zbi f k l m g GbFbwbeb4c

406 self.__import_controllers = [self._import_controller(imp) for imp in self._items] 2a Abs 6bHb7byczclctcuccb$ rbmcfbdb% sbtbubnbobvbpbJbL 8bM R i f k l m g wb

407 return self.__import_controllers 2a Abs F ~ abbb6bHb7byczclctcuccb$ rbmcfbdb% sbtbubnbobvbpbJbL 8bM ybR zbi f k l m g GbFbwbeb4c

408 

409 def _import_controller(self, import_): 1ab

410 return import_controller(self, import_) 2a Abs F ~ abbbHbyczclctcuccb$ rbmcfbdb% sbtbubnbobvbpbJbL M i f k l m g wbeb

411 

412 @property 1ab

413 def _items(self): 1ab

414 return self._table.imports 2a Abs F 6bHb7byczclctcuccb$ rbmcfbdb% sbMetbubnbobvbpbJbL 8bM R i f k l m g GbFbwb

415 

416 @property 1ab

417 def resource_file_controller_factory(self): 1ab

418 return self._resource_file_controller_factory 2a Ablc$ mcfb% tbubnbobvbpbNeOePeL R i f k l m g wbeb

419 

420 def _swap(self, ind1, ind2): 1ab

421 imps = self._import_controllers 2GbFb

422 imps[ind1], imps[ind2] = imps[ind2], imps[ind1] 2GbFb

423 WithListOperations._swap(self, ind1, ind2) 2GbFb

424 

425 def remove_import_data(self, imp): 1ab

426 self.delete(self._items.data.index(imp)) 1Lf

427 

428 def delete(self, index): 1ab

429 item = self[index] 2s F fbL f g

430 WithListOperations.delete(self, index) 2s F fbL f g

431 self._import_controllers.pop(index) 2s F fbL f g

432 item.publish_removed() 2s F fbL f g

433 self.notify_imports_modified() 2s F fbL f g

434 

435 def add_library(self, name, argstr, alias, comment=None): 1ab

436 self._import_controllers # Call property since it has to exist before adding new 2a s F ~ abbbcbdb

437 import_ = self._table.add_library(name, utils.split_value(argstr), 2a s F ~ abbbcbdb

438 comment) 

439 import_.alias = alias 2a s F ~ abbbcbdb

440 self._parent.mark_dirty() 2a s F ~ abbbcbdb

441 self._add_controller(import_) 2a s F ~ abbbcbdb

442 self.notify_imports_modified() 2a s F ~ abbbcbdb

443 return self[-1] 2a s F ~ abbbcbdb

444 

445 def _add_controller(self, import_): 1ab

446 ctrl = self._import_controller(import_) 2a s F ~ abbbcb$ rbdb% sbi f k l m g eb

447 ctrl.publish_added() 2a s F ~ abbbcb$ rbdb% sbi f k l m g eb

448 self._import_controllers.append(ctrl) 2a s F ~ abbbcb$ rbdb% sbi f k l m g eb

449 

450 def add_resource(self, path, comment=None): 1ab

451 self._import_controllers # Have to exist before adding new 2$ % i f k l m g eb

452 import_ = self._table.add_resource(path, comment) 2$ % i f k l m g eb

453 self._parent.mark_dirty() 2$ % i f k l m g eb

454 self.resource_import_modified(path) 2$ % i f k l m g eb

455 self._add_controller(import_) 2$ % i f k l m g eb

456 self.notify_imports_modified() 2$ % i f k l m g eb

457 return self[-1] 2$ % i f k l m g eb

458 

459 def add_variables(self, path, argstr, comment=None): 1ab

460 self._import_controllers # Have to exist before adding new 2rbsb

461 import_ = self._table.add_variables(path, utils.split_value(argstr), comment) 2rbsb

462 self._parent.mark_dirty() 2rbsb

463 self._add_controller(import_) 2rbsb

464 return self[-1] 2rbsb

465 

466 def notify_imports_modified(self): 1ab

467 self.datafile_controller.update_namespace() 2a s F ~ abbblctcuccb$ mcfbdb% nbobpbL i f k l m g eb

468 

469 def resource_import_modified(self, path): 1ab

470 return self._parent.resource_import_modified(path) 2$ % i f k l m g eb

471 

472 

473class MetadataListController(_TableController, WithListOperations): 1ab

474 

475 def __iter__(self): 1ab

476 return iter(MetadataController(self, m) for m in self._items) 2Fe

477 

478 def __getitem__(self, index): 1ab

479 return MetadataController(self, self._items[index]) 2UcGeHe

480 

481 @property 1ab

482 def _items(self): 1ab

483 return self._table.metadata 2UcGeHeFe

484 

485 def add_metadata(self, name, value, comment=None): 1ab

486 self._table.add_metadata(name, value, comment) 2Uc

487 self._parent.mark_dirty() 2Uc

488 return self[-1] 2Uc