Skip to content

Commit 1e131fc

Browse files
authored
Merge pull request robotframework#3433 from robotframework/tidy
Tidy
2 parents 5916caa + cc5a187 commit 1e131fc

18 files changed

+382
-320
lines changed

atest/robot/tidy/format_documentation.robot

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,4 @@ Suite Teardown Remove Directory ${TEMP} recursive=True
55

66
*** Test Cases ***
77
Documentation in text file
8-
Verify documentation formatting robot
9-
10-
*** Keywords ***
11-
Verify documentation formatting
12-
[Arguments] ${format}
13-
Run tidy and check result --format=${format} documentation.robot expected=documentation_expected.${format}
8+
Run tidy and check result ${EMPTY} documentation.robot expected=documentation_expected.robot

atest/robot/tidy/tidy.robot

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@ Tidying single test case file
88
[Documentation] Test tidying to different formats
99
[Template] Run tidy with golden file and check result
1010
${EMPTY} golden.robot
11-
--usepipes -f txt golden_pipes.robot
12-
--for robot golden.robot
11+
--usepipes golden_pipes.robot
12+
# TODO: fix the commented test, split this test into smaller pieces
13+
# ${EMPTY} golden.robot input=pipes-input.robot
14+
--usepipes golden_pipes.robot input=pipes-input.robot
1315
--spacecount 2 golden_two_spaces.robot
1416

1517
Tidying single resource file
1618
[Template] Run tidy with golden resource file and check result
1719
${EMPTY} golden_resource.robot
1820
-p golden_pipes_resource.robot
19-
--FOR ROBOT golden_resource.robot
2021

2122
Tidying single init file
2223
Run tidy and check result input=__init__.robot
2324
File Should Exist ${OUTFILE}
2425

2526
Tidying single file without output file prints output to console
2627
[Documentation] Depending on console encoding, non-ASCII characters may not be shown correctly.
27-
${stdout} = Run tidy input=golden.robot output=None
28+
${stdout} = Run tidy input=golden-input.robot output=None
2829
Compare tidy results ${stdout} golden.robot \\s+Log Many\\s+Non-ASCII:.*\\s+\\$\\{CURDIR\\}
2930
File Should Not Exist ${OUTFILE}
3031

@@ -35,7 +36,7 @@ Default format is got from output file
3536
Tidying directory
3637
[Setup] Copy Directory ${DATA}/tests ${TEMP}/tests
3738
${result_before}= Run Tests sources=${DATA}/tests
38-
Run Tidy --recursive --format robot ${TEMP}/tests
39+
Run Tidy --recursive ${TEMP}/tests
3940
Check file count ${TEMP}/tests *.robot 2
4041
Check file count ${TEMP}/tests/sub *.robot 1
4142
Check file count ${TEMP}/tests *.txt 0

atest/robot/tidy/tidy_resource.robot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ ${OUTFILE} ${TEMP}${/}tidy-test-file.robot
99

1010
*** Keywords ***
1111
Run tidy with golden file and check result
12-
[Arguments] ${options} ${expected}
13-
${output} = Run tidy and check result ${options} golden-input.robot expected=${expected}
12+
[Arguments] ${options} ${expected} ${input}=golden-input.robot
13+
${output} = Run tidy and check result ${options} ${input} expected=${expected}
1414
[Return] ${output}
1515

1616
Run tidy with golden resource file and check result

atest/testdata/tidy/for_loops_expected.robot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ For loop in test
44
Log ${x}
55
END
66

7+
Missing END
8+
FOR ${x} IN foo bar
9+
Log ${x}
10+
Keyword
11+
END
12+
713
Old for loop in test
814
FOR ${x} IN foo bar
915
Log ${x}

atest/testdata/tidy/for_loops_input.robot

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ For loop in test
44
Log ${x}
55
END
66

7+
Missing END
8+
FOR ${x} IN foo bar
9+
Log ${x}
10+
Keyword
11+
712
Old for loop in test
813
:FOR ${x} IN foo bar
914
\ Log ${x}

atest/testdata/tidy/pipes-input.robot

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
| This data is ignored at runtime but should be preserved by Tidy. |
2+
3+
| *** Settings *** |
4+
| Library | MyLibrary | argument | WITH NAME | My Alias | # My library comment |
5+
| Variables | MyVariables | args | args 2 | args 3 | args 4 | args 5 | args 6 |
6+
| ... | args 7 | args 8 | args 9 | args 10 | args 11 | args 12 |
7+
| Resource | resource.robot |
8+
|
9+
| *** Variables *** |
10+
| # standalone | comment |
11+
| ${VALID} | Value |
12+
| MyVar | val1 | val2 | val3 | val4 | val5 | val6 | val7 |
13+
| ... | val8 | val9 | val10 | # var comment |
14+
| # standalone |
15+
16+
| *** Test Cases *** |
17+
| My Test Case |
18+
| | [Documentation] | This is a documentation |
19+
| | ... | in two lines |
20+
| | My TC Step 1 | my step arg | # step 1 comment |
21+
| | My TC Step 2 | my step 2 arg | second \ arg | # step 2 comment |
22+
| | ... | third arg split to own row |
23+
| | ... | fourth and | fifth as well | # comment |
24+
| | [Teardown] | 1 minute | args |
25+
26+
| Another Test |
27+
| | Log Many | Non-ASCII: ääöö§§ | ${CURDIR} |
28+
29+
| *** Keyword *** |
30+
| My Keyword |
31+
| | [Documentation] | Documentation | # Comment for doc |
32+
| | [Tags] | keyword | tags |
33+
| | # Comment row |
34+
| | # Comment row 2 |
35+
| | My Step 1 | args | args 2 | args 3 | args 4 | args 5 | args 6 |
36+
| | ... | args 7 | args 8 | args 9 | # step 1 comment |
37+
| | FOR | ${param1} | ${param2} | IN | ${data 1} | ${data 2} | ${data 3} |
38+
| | ... | ${data 4} | ${data 5} | ${data 6} | # FOR comment |
39+
| | | Loop Step | args | args 2 | args 3 | args 4 | args 5 |
40+
| | | ... | args 6 | args 7 | args 8 | args 9 | # loop step comment |
41+
| | | Loop Step 2 |
42+
| | END |
43+
| | My Step 2 | my step 2 arg | second arg | # step 2 comment |
44+
| | [Return] | args 1 | args 2 |

src/robot/parsing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ def print_suite(suite):
5151

5252
from .builders import get_model, get_resource_model
5353
from .lexer import get_tokens, get_resource_tokens, Token
54-
from .model import ModelVisitor
54+
from .model import ModelTransformer
5555
from .suitestructure import SuiteStructureBuilder, SuiteStructureVisitor

src/robot/parsing/builders.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323

2424
def get_model(source, data_only=False, curdir=None):
2525
tokens = get_tokens(source, data_only)
26-
return _build_model(get_statements(tokens, curdir))
26+
return _build_model(source, get_statements(tokens, curdir))
2727

2828

2929
def get_resource_model(source, data_only=False, curdir=None):
3030
tokens = get_resource_tokens(source, data_only)
31-
return _build_model(get_statements(tokens, curdir))
31+
return _build_model(source, get_statements(tokens, curdir))
3232

3333

34-
def _build_model(statements):
35-
builder = FileBuilder()
34+
def _build_model(source, statements):
35+
builder = FileBuilder(source)
3636
stack = [builder]
3737
for statement in statements:
3838
while not stack[-1].handles(statement):
@@ -57,8 +57,8 @@ def statement(self, statement):
5757

5858
class FileBuilder(Builder):
5959

60-
def __init__(self, model=None):
61-
Builder.__init__(self, model or File())
60+
def __init__(self, source=None):
61+
Builder.__init__(self, File(source))
6262

6363
def statement(self, statement):
6464
try:
@@ -90,6 +90,8 @@ class TestCaseSectionBuilder(SectionBuilder):
9090

9191
def statement(self, statement):
9292
if statement.type == Token.EOL:
93+
if self.model.body.items:
94+
self.model.body.add(statement)
9395
return self
9496
model = TestCase(statement)
9597
self.model.body.add(model)
@@ -100,6 +102,8 @@ class KeywordSectionBuilder(SectionBuilder):
100102

101103
def statement(self, statement):
102104
if statement.type == Token.EOL:
105+
if self.model.body.items:
106+
self.model.body.add(statement)
103107
return self
104108
model = Keyword(statement)
105109
self.model.body.add(model)

src/robot/parsing/lexer/readers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def get_tokens(self):
125125
yield EOS.from_token(prev_token)
126126

127127
def _handle_old_for(self, statements):
128-
end_statement = [Token(Token.END)]
128+
end_statement = [Token(Token.SEPARATOR), Token(Token.END)]
129129
old_for = False
130130
for statement in statements:
131131
marker = self._get_first_data_token(statement)

src/robot/parsing/model/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
from .blocks import (File, SettingSection, VariableSection, TestCaseSection,
1717
KeywordSection, CommentSection, TestCase, Keyword, ForLoop)
1818
from .statements import get_statements
19-
from .visitor import ModelVisitor
19+
from .visitor import ModelTransformer

0 commit comments

Comments
 (0)