forked from robotframework/robotframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.py
More file actions
116 lines (93 loc) · 3.24 KB
/
Copy pathcontrol.py
File metadata and controls
116 lines (93 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright 2008-2015 Nokia Networks
# Copyright 2016- Robot Framework Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from robot.utils import setter
from .body import Body, BodyItem, IfBranches
from .keyword import Keywords
@Body.register
class For(BodyItem):
type = BodyItem.FOR
body_class = Body
repr_args = ('variables', 'flavor', 'values')
__slots__ = ['variables', 'flavor', 'values']
def __init__(self, variables=(), flavor='IN', values=(), parent=None):
self.variables = variables
self.flavor = flavor
self.values = values
self.parent = parent
self.body = None
@setter
def body(self, body):
return self.body_class(self, body)
@property
def keywords(self):
"""Deprecated since Robot Framework 4.0. Use :attr:`body` instead."""
return Keywords(self, self.body)
@keywords.setter
def keywords(self, keywords):
Keywords.raise_deprecation_error()
def visit(self, visitor):
visitor.visit_for(self)
def __str__(self):
variables = ' '.join(self.variables)
values = ' '.join(self.values)
return 'FOR %s %s %s' % (variables, self.flavor, values)
@Body.register
class If(BodyItem):
"""IF/ELSE structure root. Branches are stored in :attr:`body`."""
type = BodyItem.IF_ELSE_ROOT
body_class = IfBranches
__slots__ = ['parent']
def __init__(self, parent=None):
self.parent = parent
self.body = None
@setter
def body(self, body):
return self.body_class(self, body)
@property
def id(self):
"""Root IF/ELSE id is always ``None``."""
return None
def visit(self, visitor):
visitor.visit_if(self)
@IfBranches.register
class IfBranch(BodyItem):
body_class = Body
repr_args = ('type', 'condition')
__slots__ = ['type', 'condition']
def __init__(self, type=BodyItem.IF, condition=None, parent=None):
self.type = type
self.condition = condition
self.parent = parent
self.body = None
@setter
def body(self, body):
return self.body_class(self, body)
@property
def id(self):
"""Branch id omits the root IF/ELSE object from the parent id part."""
if not self.parent:
return 'k1'
index = self.parent.body.index(self) + 1
if not self.parent.parent:
return 'k%d' % index
return '%s-k%d' % (self.parent.parent.id, index)
def __str__(self):
if self.type == self.IF:
return 'IF %s' % self.condition
if self.type == self.ELSE_IF:
return 'ELSE IF %s' % self.condition
return 'ELSE'
def visit(self, visitor):
visitor.visit_if_branch(self)