Skip to content

Commit b419da5

Browse files
committed
Fix tests for using same setting multiple times
The first value will be used instead of ignoring the whole setting
1 parent f6d2ee4 commit b419da5

File tree

5 files changed

+124
-57
lines changed

5 files changed

+124
-57
lines changed

atest/robot/parsing/same_setting_multiple_times.robot

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ Resource atest_resource.robot
44

55
*** Test Cases ***
66
Suite Documentation
7-
Should Be Equal ${SUITE.doc} ${EMPTY}
7+
Should Be Equal ${SUITE.doc} S1
88
Setting multiple times 0 Documentation
99

1010
Suite Metadata
1111
Should Be Equal ${SUITE.metadata['Foo']} M2
1212

1313
Suite Setup
14-
Should Be Equal ${SUITE.setup} ${NONE}
14+
Should Be Equal ${SUITE.setup.name} BuiltIn.Log Many
1515
Setting multiple times 1 Suite Setup
1616

1717
Suite Teardown
18-
Should Be Equal ${SUITE.teardown} ${NONE}
18+
Should Be Equal ${SUITE.teardown.name} BuiltIn.Comment
1919
Setting multiple times 2 Suite Teardown
2020

2121
Force and Default Tags
22-
Check Test Tags Use Defaults
22+
Check Test Tags Use Defaults D1
2323
Setting multiple times 7 Force Tags
2424
Setting multiple times 8 Force Tags
2525
Setting multiple times 9 Default Tags
2626
Setting multiple times 10 Default Tags
2727

2828
Test Setup
2929
${tc} = Check Test Case Use Defaults
30-
Should Be Equal ${tc.setup} ${NONE}
30+
Should Be Equal ${tc.setup.name} BuiltIn.Log Many
3131
Setting multiple times 3 Test Setup
3232

3333
Test Teardown
@@ -37,91 +37,80 @@ Test Teardown
3737

3838
Test Template
3939
${tc} = Check Test Case Use Defaults
40-
Check Keyword Data ${tc.kws[0]} BuiltIn.Sleep args=0.1s
40+
Check Keyword Data ${tc.kws[0]} BuiltIn.Log Many args=Sleep, 0.1s
4141
Setting multiple times 6 Test Template
4242

4343
Test Timeout
4444
${tc} = Check Test Case Use Defaults
45-
Should Be Equal ${tc.timeout} ${NONE}
45+
Should Be Equal ${tc.timeout} 1 second
4646
Setting multiple times 11 Test Timeout
4747

4848
Test [Documentation]
4949
${tc} = Check Test Case Test Settings
50-
Should Be Equal ${tc.doc} ${EMPTY}
51-
Setting multiple times in test case table 12 [Documentation]
50+
Should Be Equal ${tc.doc} T1
51+
Setting multiple times 12 Documentation
5252

5353
Test [Tags]
5454
Check Test Tags Test Settings
55-
Setting multiple times in test case table 13 [Tags]
56-
Setting multiple times in test case table 14 [Tags]
55+
Setting multiple times 13 Tags
56+
Setting multiple times 14 Tags
5757

5858
Test [Setup]
5959
${tc} = Check Test Case Test Settings
60-
Should Be Equal ${tc.setup} ${NONE}
61-
Setting multiple times in test case table 15 [Setup]
60+
Should Be Equal ${tc.setup.name} BuiltIn.Log Many
61+
Setting multiple times 15 Setup
6262

6363
Test [Teardown]
6464
${tc} = Check Test Case Test Settings
6565
Should Be Equal ${tc.teardown} ${NONE}
66-
Setting multiple times in test case table 16 [Teardown]
67-
Setting multiple times in test case table 17 [Teardown]
66+
Setting multiple times 16 Teardown
67+
Setting multiple times 17 Teardown
6868

6969
Test [Template]
7070
${tc} = Check Test Case Test Settings
71-
Check Keyword Data ${tc.kws[0]} BuiltIn.No Operation
72-
Setting multiple times in test case table 18 [Template]
71+
Check Keyword Data ${tc.kws[0]} BuiltIn.Log args=No Operation
72+
Setting multiple times 18 Template
7373

7474
Test [Timeout]
7575
${tc} = Check Test Case Test Settings
76-
Should Be Equal ${tc.timeout} ${NONE}
77-
Setting multiple times in test case table 19 [Timeout]
76+
Should Be Equal ${tc.timeout} 2 seconds
77+
Setting multiple times 19 Timeout
7878

7979
Keyword [Arguments]
8080
${tc} = Check Test Case Keyword Settings
81-
Check Keyword Data ${tc.kws[0]} Keyword Settings assign=\${ret}
82-
Check Log Message ${tc.kws[0].msgs[0]} Arguments: [ \ ] TRACE
83-
Setting multiple times in keyword table 20 [Arguments]
81+
Check Keyword Data ${tc.kws[0]} Keyword Settings assign=\${ret} args=1, 2, 3 tags=K1
82+
Check Log Message ${tc.kws[0].msgs[0]} Arguments: [ \${a1}='1' | \${a2}='2' | \${a3}='3' ] TRACE
83+
Setting multiple times 20 Arguments
8484

8585
Keyword [Documentation]
8686
${tc} = Check Test Case Keyword Settings
8787
Should Be Equal ${tc.kws[0].doc} ${EMPTY}
88-
Setting multiple times in keyword table 21 [Documentation]
89-
Setting multiple times in keyword table 22 [Documentation]
88+
Setting multiple times 21 Documentation
89+
Setting multiple times 22 Documentation
9090

9191
Keyword [Tags]
9292
${tc} = Check Test Case Keyword Settings
93-
Should Be Empty ${tc.kws[0].tags}
94-
Setting multiple times in keyword table 23 [Tags]
93+
Should Be True list($tc.kws[0].tags) == ['K1']
94+
Setting multiple times 23 Tags
9595

9696
Keyword [Timeout]
9797
${tc} = Check Test Case Keyword Settings
9898
Should Be Equal ${tc.kws[0].timeout} ${NONE}
99-
Setting multiple times in keyword table 24 [Timeout]
100-
Setting multiple times in keyword table 25 [Timeout]
99+
Setting multiple times 24 Timeout
100+
Setting multiple times 25 Timeout
101101

102102
Keyword [Return]
103103
${tc} = Check Test Case Keyword Settings
104-
Check Log Message ${tc.kws[0].msgs[1]} Return: None TRACE
105-
Check Log Message ${tc.kws[0].msgs[2]} \${ret} = None
106-
Setting multiple times in keyword table 26 [Return]
107-
Setting multiple times in keyword table 27 [Return]
104+
Check Log Message ${tc.kws[0].msgs[1]} Return: 'R0' TRACE
105+
Check Log Message ${tc.kws[0].msgs[2]} \${ret} = R0
106+
Setting multiple times 26 Return
107+
Setting multiple times 27 Return
108108

109109
*** Keywords ***
110110
Setting multiple times
111-
[Arguments] ${index} ${setting} @{extra}
111+
[Arguments] ${index} ${setting}
112112
${path} = Normalize Path ${DATADIR}/parsing/same_setting_multiple_times.robot
113113
${message} = Catenate
114114
... Error in file '${path}':
115-
... @{extra}
116-
... Setting '${setting}' used multiple times.
117-
Check Log Message ${ERRORS}[${index}] ${message} ERROR
118-
119-
Setting multiple times in test case table
120-
[Arguments] ${index} ${setting}
121-
Setting multiple times ${index} ${setting}
122-
... Invalid syntax in test case 'Test Settings':
123-
124-
Setting multiple times in keyword table
125-
[Arguments] ${index} ${setting}
126-
Setting multiple times ${index} ${setting}
127-
... Invalid syntax in keyword 'Keyword Settings':
115+
... Setting '${setting}' allowed only once. Only the first value is used.
116+
Check Log Message @{ERRORS}[${index}] ${message} ERROR

atest/testdata/parsing/same_setting_multiple_times.robot

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ Test Setup Comment T2
1212
Test Teardown
1313
Test Teardown Comment T1
1414
Test Teardown Log Many T2
15-
Test Template Log
16-
Test Template Many
15+
Test Template Log Many
16+
Test Template Ignored
1717
Force Tags
1818
Force Tags F1
1919
Force Tags F2
2020
Default Tags D1
2121
Default Tags D2
2222
Default Tags D3
23-
Test Timeout 1 ms
23+
Test Timeout 1 s
2424
Test Timeout 0.001 s
2525

2626
*** Test Cases ***
@@ -38,15 +38,16 @@ Test Settings
3838
[Teardown]
3939
[Teardown] Log Many And
4040
[Teardown] also here
41-
[Template] S
42-
[Template] leep
43-
[Timeout] 2 ms
41+
[Template] Log
42+
[Template] ignored
4443
[Timeout] 2 s
44+
[Timeout] 2 ms
4545
No Operation
4646

4747
Keyword Settings
48-
${ret} = Keyword Settings
49-
Should Be Equal ${ret} ${NONE}
48+
[Template] NONE
49+
${ret} = Keyword Settings 1 2 3
50+
Should Be Equal ${ret} R0
5051

5152
*** Keywords ***
5253
Keyword Settings
@@ -61,7 +62,7 @@ Keyword Settings
6162
[Timeout] 1s
6263
[Timeout] 2s
6364
No Operation
64-
[Return]
65+
[Return] R0
6566
[Return] R1
6667
[Return] R2
6768
[Return] R3
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
*** Settings ***
2+
Library MyLibrary argument WITH NAME My Alias # My library comment
3+
Variables MyVariables args args 2 args 3 args 4 args 5 args 6
4+
... args 7 args 8 args 9 args 10 args 11 args 12
5+
Resource MyResource args that are part of the name
6+
7+
*** Variables ***
8+
# standalone comment
9+
MyVar val1 val2 val3 val4 val5 val6 val7
10+
... val8 val9 val10 # var comment
11+
# standalone
12+
13+
*** Test Cases ***
14+
My Test Case
15+
[Documentation] This is a long comment that spans several columns
16+
My TC Step 1 my step arg # step 1 comment
17+
My TC Step 2 my step 2 arg second \ arg # step 2 comment
18+
[Teardown] 1 minute args
19+
20+
Another Test
21+
Log Many Non-ASCII: ääöö§§ ${CURDIR}
22+
23+
*** Keywords ***
24+
My Keyword
25+
[Documentation] Documentation # Comment for doc
26+
[Tags] keyword tags
27+
# Comment row
28+
# Comment row 2
29+
My Step 1 args args 2 args 3 args 4 args 5 args 6
30+
... args 7 args 8 args 9 # step 1 comment
31+
FOR ${param1} ${param2} IN ${data 1} ${data 2} ${data 3}
32+
... ${data 4} ${data 5} ${data 6} # FOR comment
33+
Loop Step args args 2 args 3 args 4 args 5
34+
... args 6 args 7 args 8 args 9 # loop step comment
35+
Loop Step 2
36+
END
37+
My Step 2 my step 2 arg second arg # step 2 comment
38+
[Return] args 1 args 2

atest/testdata/tidy/golden.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
*** Settings ***
2+
Library MyLibrary argument WITH NAME My Alias # My library comment
3+
Variables MyVariables args args 2 args 3 args 4 args 5 args 6
4+
... args 7 args 8 args 9 args 10 args 11 args 12
5+
Resource MyResource args that are part of the name
6+
7+
*** Variables ***
8+
# standalone comment
9+
MyVar val1 val2 val3 val4 val5 val6 val7
10+
... val8 val9 val10 # var comment
11+
# standalone
12+
13+
*** Test Cases ***
14+
My Test Case
15+
[Documentation] This is a long comment that spans several columns
16+
My TC Step 1 my step arg # step 1 comment
17+
My TC Step 2 my step 2 arg second \ arg # step 2 comment
18+
[Teardown] 1 minute args
19+
20+
Another Test
21+
Log Many Non-ASCII: ääöö§§ ${CURDIR}
22+
23+
*** Keywords ***
24+
My Keyword
25+
[Documentation] Documentation # Comment for doc
26+
[Tags] keyword tags
27+
# Comment row
28+
# Comment row 2
29+
My Step 1 args args 2 args 3 args 4 args 5 args 6
30+
... args 7 args 8 args 9 # step 1 comment
31+
FOR ${param1} ${param2} IN ${data 1} ${data 2} ${data 3}
32+
... ${data 4} ${data 5} ${data 6} # FOR comment
33+
Loop Step args args 2 args 3 args 4 args 5
34+
... args 6 args 7 args 8 args 9 # loop step comment
35+
Loop Step 2
36+
END
37+
My Step 2 my step 2 arg second arg # step 2 comment
38+
[Return] args 1 args 2

src/robot/parsing/lexer/settings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ def lex(self, statement):
4343
def _validate(self, name, normalized, statement):
4444
if normalized not in self.settings:
4545
raise ValueError("Non-existing setting '%s'." % name) # TODO: Hints?
46-
if self.settings[normalized] and normalized not in self.multi_use:
47-
raise ValueError("Setting '%s' allowed only once." % name)
46+
if self.settings[normalized] is not None and normalized not in self.multi_use:
47+
raise ValueError("Setting '%s' allowed only once. "
48+
"Only the first value is used." % name)
4849
if normalized in self.single_value and len(statement) > 2:
4950
raise ValueError("Setting '%s' accepts only one value, got %s."
5051
% (name, len(statement) - 1))

0 commit comments

Comments
 (0)