Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e23a60d

Browse files
committed
JSON serialization: Fix WHILE and FOR body #3902
1 parent f405f90 commit e23a60d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/robot/model/control.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def to_dict(self):
5858
return {'type': self.type,
5959
'variables': list(self.variables),
6060
'flavor': self.flavor,
61-
'values': list(self.values)}
61+
'values': list(self.values),
62+
'body': self.body.to_dicts()}
6263

6364

6465
@Body.register
@@ -85,9 +86,12 @@ def __str__(self):
8586
return f'WHILE {self.condition}' + (f' {self.limit}' if self.limit else '')
8687

8788
def to_dict(self):
88-
data = {'type': self.type, 'condition': self.condition}
89+
data = {'type': self.type}
90+
if self.condition:
91+
data['condition'] = self.condition
8992
if self.limit:
9093
data['limit'] = self.limit
94+
data['body'] = self.body.to_dicts()
9195
return data
9296

9397

utest/running/test_run_model.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,17 @@ def test_keyword(self):
244244
name='Setup', lineno=1)
245245

246246
def test_for(self):
247-
self._verify(For(), type='FOR', variables=[], flavor='IN', values=[])
248-
self._verify(For(['${i}'], 'IN RANGE', ['10'], lineno=2), type='FOR',
249-
variables=['${i}'], flavor='IN RANGE', values=['10'], lineno=2)
247+
self._verify(For(), type='FOR', variables=[], flavor='IN', values=[], body=[])
248+
self._verify(For(['${i}'], 'IN RANGE', ['10'], lineno=2),
249+
type='FOR', variables=['${i}'], flavor='IN RANGE', values=['10'],
250+
body=[], lineno=2)
250251

251252
def test_while(self):
252-
self._verify(While(), type='WHILE', condition=None)
253+
self._verify(While(), type='WHILE', body=[])
253254
self._verify(While('1 > 0', '1 min'),
254-
type='WHILE', condition='1 > 0', limit='1 min')
255+
type='WHILE', condition='1 > 0', limit='1 min', body=[])
255256
self._verify(While('True', lineno=3, error='x'),
256-
type='WHILE', condition='True', lineno=3, error='x')
257+
type='WHILE', condition='True', body=[], lineno=3, error='x')
257258

258259
def test_if(self):
259260
self._verify(If(), type='IF/ELSE ROOT', body=[])

0 commit comments

Comments
 (0)