diff --git a/CHANGES.md b/CHANGES.md index 16011d82..011ac71f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -41,6 +41,9 @@ robotidy --check --overwrite src ``` +### Fixes +- Unmodified files are now not saved to the disk ([#237](https://github.com/MarketSquare/robotframework-tidy/issues/237)) + ## 1.6.2 ### Fixes diff --git a/robotidy/app.py b/robotidy/app.py index 2ed324cd..0cafda75 100644 --- a/robotidy/app.py +++ b/robotidy/app.py @@ -67,7 +67,7 @@ def transform_files(self): self.output_diff(model.source, old_model, new_model) if stdin: self.print_to_stdout(new_model) - else: + elif diff: self.save_model(model.source, model) except DataError: click.echo( diff --git a/tests/atest/transformers/AlignTestCases/expected/empty_line.robot b/tests/atest/transformers/AlignTestCases/expected/empty_line.robot deleted file mode 100644 index d4c340b3..00000000 --- a/tests/atest/transformers/AlignTestCases/expected/empty_line.robot +++ /dev/null @@ -1,12 +0,0 @@ -*** Settings *** -Test Template bar - -*** Test Cases *** baz qux -test1 - hi hello -test2 long test name - asdfasdf asdsdfgsdfg - -*** Keywords *** -bar - [Arguments] ${baz} ${qux} \ No newline at end of file diff --git a/tests/atest/transformers/AlignTestCases/expected/for_loops.robot b/tests/atest/transformers/AlignTestCases/expected/for_loops.robot deleted file mode 100644 index c9467798..00000000 --- a/tests/atest/transformers/AlignTestCases/expected/for_loops.robot +++ /dev/null @@ -1,22 +0,0 @@ -*** Test Cases *** header1 header2 -My Test Case - [Documentation] This is a documentation - ... in two lines - My TC Step 1 my step arg # step 1 comment - My TC Step 2 my step \ 2 arg second arg # step 2 comment - ... third arg split to own row - ... fourth and fifth as well # comment - [Teardown] 1 minute - -A very long named test case - My step 1 This is arg - My step 2 This also is arg - ... Split line Longest argument on split - -Test with for FOR ${i} IN RANGE 100 - Log ${i} - ${result} = My kw - Log Many 1st - ... 2nd - ... 3rd - END \ No newline at end of file diff --git a/tests/atest/transformers/AlignTestCases/expected/no_header_col_only_headers.robot b/tests/atest/transformers/AlignTestCases/expected/no_header_col_only_headers.robot deleted file mode 100644 index f24b159c..00000000 --- a/tests/atest/transformers/AlignTestCases/expected/no_header_col_only_headers.robot +++ /dev/null @@ -1,13 +0,0 @@ -*** Settings *** -Test Template bar - -*** Test Cases *** -# some comment -test1 hi hello -test2 long test name asdfasdf asdsdfgsdfg - bar1 bar2 -# some comment - -*** Keywords *** -bar - [Arguments] ${baz} ${qux} diff --git a/tests/atest/transformers/AlignTestCases/test_transformer.py b/tests/atest/transformers/AlignTestCases/test_transformer.py index 4f86fd59..7f4964b2 100644 --- a/tests/atest/transformers/AlignTestCases/test_transformer.py +++ b/tests/atest/transformers/AlignTestCases/test_transformer.py @@ -11,21 +11,23 @@ class TestAlignTestCases(TransformerAcceptanceTest): [ "test.robot", "no_header_col.robot", - "for_loops.robot", "with_settings.robot", "templated_for_loops.robot", "templated_for_loops_and_without.robot", "templated_for_loops_header_cols.robot", - "empty_line.robot", ], ) def test_transformer(self, source): self.compare(source=source, expected=source) + @pytest.mark.parametrize("source", ["for_loops.robot", "empty_line.robot"]) + def test_should_not_modify(self, source): + self.compare(source=source, not_modified=True) + def test_only_with_headers(self): self.compare( source="no_header_col.robot", - expected="no_header_col_only_headers.robot", + not_modified=True, config=":only_with_headers=True", ) diff --git a/tests/atest/transformers/InlineIf/expected/invalid_if.robot b/tests/atest/transformers/InlineIf/expected/invalid_if.robot deleted file mode 100644 index 444484e3..00000000 --- a/tests/atest/transformers/InlineIf/expected/invalid_if.robot +++ /dev/null @@ -1,133 +0,0 @@ -*** Test Cases *** -IF without condition - [Documentation] FAIL IF must have a condition. - IF - Fail Should not be run - END - -IF without condition with ELSE - [Documentation] FAIL IF must have a condition. - IF - Fail Should not be run - ELSE - Fail Should not be run - END - -IF without END - [Documentation] FAIL IF has no closing END. - IF ${True} - Fail Should not be run - -Invalid END - [Documentation] FAIL END does not accept arguments, got 'this', 'is' and 'invalid'. - IF True - Fail Should not be run - END this is invalid - -IF with wrong case - [Documentation] FAIL 'If' is a reserved keyword. It must be an upper case 'IF' when used as a marker. - if ${True} - Fail Should not be run - END - -ELSE IF without condition - [Documentation] FAIL ELSE IF must have a condition. - IF 'mars' == 'mars' - Fail Should not be run - ELSE IF - Fail Should not be run - ELSE - Fail Should not be run - END - -ELSE IF with multiple conditions - [Documentation] FAIL ELSE IF cannot have more than one condition. - IF 'maa' == 'maa' - Fail Should not be run - ELSE IF ${False} ooops ${True} - Fail Should not be run - ELSE - Fail Should not be run - END - -ELSE with condition - [Documentation] FAIL ELSE does not accept arguments, got '\${True}'. - IF 'venus' != 'mars' - Fail Should not be run - ELSE ${True} - Fail Should not be run - END - -IF with empty body - [Documentation] FAIL IF branch cannot be empty. - IF 'jupiter' == 'saturnus' - END - -ELSE with empty body - [Documentation] FAIL ELSE branch cannot be empty. - IF 'kuu' == 'maa' - Fail Should not be run - ELSE - END - -ELSE IF with empty body - [Documentation] FAIL ELSE IF branch cannot be empty. - IF 'mars' == 'maa' - Fail Should not be run - ELSE IF ${False} - ELSE - Fail Should not be run - END - -ELSE after ELSE - [Documentation] FAIL Multiple ELSE branches. - IF 'kuu' == 'maa' - Fail Should not be run - ELSE - Fail Should not be run - ELSE - Fail Should not be run - END - -ELSE IF after ELSE - [Documentation] FAIL ELSE IF after ELSE. - IF 'kuu' == 'maa' - Fail Should not be run - ELSE - Fail Should not be run - ELSE IF ${True} - Log hei - END - -Invalid IF inside FOR - [Documentation] FAIL ELSE IF after ELSE. - FOR ${value} IN 1 2 3 - IF ${value} == 1 - Fail Should not be run - ELSE - Fail Should not be run - ELSE IF ${value} == 3 - Fail Should not be run - END - END - -Multiple errors - [Documentation] FAIL - ... Multiple errors: - ... - IF must have a condition. - ... - IF branch cannot be empty. - ... - ELSE IF after ELSE. - ... - Multiple ELSE branches. - ... - IF has no closing END. - ... - ELSE IF cannot have more than one condition. - ... - ELSE IF branch cannot be empty. - ... - ELSE does not accept arguments, got 'oops'. - ... - ELSE branch cannot be empty. - ... - ELSE IF must have a condition. - ... - ELSE IF branch cannot be empty. - ... - ELSE branch cannot be empty. - IF - ELSE IF too many - ELSE oops - ELSE IF - ELSE diff --git a/tests/atest/transformers/InlineIf/expected/invalid_inline_if.robot b/tests/atest/transformers/InlineIf/expected/invalid_inline_if.robot deleted file mode 100644 index 6fdef4bd..00000000 --- a/tests/atest/transformers/InlineIf/expected/invalid_inline_if.robot +++ /dev/null @@ -1,160 +0,0 @@ -*** Test Cases *** -Invalid condition - [Documentation] FAIL Evaluating IF condition failed: Evaluating expression 'ooops' failed: NameError: name 'ooops' is not defined nor importable as module - IF ooops Not run ELSE Not run either - -Condition with non-existing variable - [Documentation] FAIL Evaluating IF condition failed: Variable '\${ooops}' not found. - IF ${ooops} Not run - -Invalid condition with other error - [Documentation] FAIL ELSE branch cannot be empty. - IF bad Not run ELSE - -Empty IF - [Documentation] FAIL Multiple errors: - ... - IF must have a condition. - ... - IF branch cannot be empty. - ... - IF has no closing END. - IF - -IF without branch - [Documentation] FAIL Multiple errors: - ... - IF branch cannot be empty. - ... - IF has no closing END. - IF True - -IF without branch with ELSE IF - [Documentation] FAIL IF branch cannot be empty. - IF True ELSE IF True Not run - -IF without branch with ELSE - [Documentation] FAIL IF branch cannot be empty. - IF True ELSE Not run - -IF followed by ELSE IF - [Documentation] FAIL STARTS: Evaluating IF condition failed: Evaluating expression 'ELSE IF' failed: - IF ELSE IF False Not run - -IF followed by ELSE - [Documentation] FAIL Evaluating IF condition failed: Evaluating expression 'ELSE' failed: NameError: name 'ELSE' is not defined nor importable as module - IF ELSE Not run - -Empty ELSE IF 1 - [Documentation] FAIL Multiple errors: - ... - ELSE IF must have a condition. - ... - ELSE IF branch cannot be empty. - IF False Not run ELSE IF - -Empty ELSE IF 2 - [Documentation] FAIL Evaluating ELSE IF condition failed: Evaluating expression 'ELSE' failed: NameError: name 'ELSE' is not defined nor importable as module - IF False Not run ELSE IF ELSE Not run - -ELSE IF without branch 1 - [Documentation] FAIL ELSE IF branch cannot be empty. - IF False Not run ELSE IF False - -ELSE IF without branch 2 - [Documentation] FAIL ELSE IF branch cannot be empty. - IF False Not run ELSE IF False ELSE Not run - -Empty ELSE - [Documentation] FAIL ELSE branch cannot be empty. - IF True Not run ELSE IF True Not run ELSE - -ELSE IF after ELSE 1 - [Documentation] FAIL ELSE IF after ELSE. - IF True Not run ELSE Not run ELSE IF True Not run - -ELSE IF after ELSE 2 - [Documentation] FAIL ELSE IF after ELSE. - IF True Not run ELSE Not run ELSE IF True Not run ELSE IF True Not run - -Multiple ELSEs 1 - [Documentation] FAIL Multiple ELSE branches. - IF True Not run ELSE Not run ELSE Not run - -Multiple ELSEs 2 - [Documentation] FAIL Multiple ELSE branches. - IF True Not run ELSE Not run ELSE Not run ELSE Not run - -Nested IF 1 - [Documentation] FAIL Inline IF cannot be nested. - IF True IF True Not run - -Nested IF 2 - [Documentation] FAIL Inline IF cannot be nested. - IF True Not run ELSE IF True Not run - -Nested IF 3 - [Documentation] FAIL Inline IF cannot be nested. - IF True IF True Not run - ... ELSE IF True IF True Not run - ... ELSE IF True Not run - -Nested FOR - [Documentation] FAIL 'For' is a reserved keyword. It must be an upper case 'FOR' when used as a marker. - IF True FOR ${x} IN @{stuff} - -Unnecessary END - [Documentation] FAIL Keyword 'BuiltIn.No Operation' expected 0 arguments, got 1. - IF True No operation ELSE Log END - IF False Not run ELSE No operation END - -Invalid END after inline header - [Documentation] FAIL 'End' is a reserved keyword. It must be an upper case 'END' when used as a marker to close a block. - IF True Log Executed inside inline IF - Log Executed outside IF - END - -Assign in IF branch - [Documentation] FAIL Inline IF branches cannot contain assignments. - IF False ${x} = Whatever - -Assign in ELSE IF branch - [Documentation] FAIL Inline IF branches cannot contain assignments. - IF False Keyword ELSE IF False ${x} = Whatever - -Assign in ELSE branch - [Documentation] FAIL Inline IF branches cannot contain assignments. - IF False Keyword ELSE ${x} = Whatever - -Invalid assign mark usage - [Documentation] FAIL Assign mark '=' can be used only with the last variable. - ${x} = ${y} IF True Create list x y - -Too many list variables in assign - [Documentation] FAIL Assignment can contain only one list variable. - @{x} @{y} = IF True Create list x y ELSE Not run - -Invalid number of variables in assign - [Documentation] FAIL Cannot set variables: Expected 2 return values, got 3. - ${x} ${y} = IF False Create list x y ELSE Create list x y z - -Invalid value for list assign - [Documentation] FAIL Cannot set variable '\@{x}': Expected list-like value, got string. - @{x} = IF True Set variable String is not list - -Invalid value for dict assign - [Documentation] FAIL Cannot set variable '\&{x}': Expected dictionary-like value, got string. - &{x} = IF False Not run ELSE Set variable String is not dict either - -Assign when IF branch is empty - [Documentation] FAIL IF branch cannot be empty. - ${x} = IF False - -Assign when ELSE IF branch is empty - [Documentation] FAIL ELSE IF branch cannot be empty. - ${x} = IF True Not run ELSE IF True - -Assign when ELSE branch is empty - [Documentation] FAIL ELSE branch cannot be empty. - ${x} = IF True Not run ELSE - -Assign with RETURN - [Documentation] FAIL Inline IF with assignment can only contain keyword calls. - Assign with RETURN - -*** Keywords *** -Assign with RETURN - ${x} = IF False RETURN ELSE Not run diff --git a/tests/atest/transformers/InlineIf/test_transformer.py b/tests/atest/transformers/InlineIf/test_transformer.py index 3fa9126c..241ba8f7 100644 --- a/tests/atest/transformers/InlineIf/test_transformer.py +++ b/tests/atest/transformers/InlineIf/test_transformer.py @@ -11,7 +11,7 @@ def test_transformer_skip_else(self): self.compare(source="test.robot", expected="test_skip_else.robot", config=":skip_else=True:line_length=120") def test_invalid_if(self): - self.compare(source="invalid_if.robot") + self.compare(source="invalid_if.robot", not_modified=True) def test_invalid_inline_if(self): - self.compare(source="invalid_inline_if.robot", config=":line_length=120") + self.compare(source="invalid_inline_if.robot", not_modified=True, config=":line_length=120") diff --git a/tests/atest/transformers/MergeAndOrderSections/expected/order.robot b/tests/atest/transformers/MergeAndOrderSections/expected/order.robot deleted file mode 100644 index e674caef..00000000 --- a/tests/atest/transformers/MergeAndOrderSections/expected/order.robot +++ /dev/null @@ -1,16 +0,0 @@ -*** Comments *** -stuff - -*** Settings *** -Library stuff - -*** Variables *** -${variable} stuff - -*** Test Cases *** -Test - Keyword - -*** Keywords *** -Keyword - No Operation diff --git a/tests/atest/transformers/MergeAndOrderSections/expected/parsing_error.robot b/tests/atest/transformers/MergeAndOrderSections/expected/parsing_error.robot deleted file mode 100644 index b6b9d9b2..00000000 --- a/tests/atest/transformers/MergeAndOrderSections/expected/parsing_error.robot +++ /dev/null @@ -1,62 +0,0 @@ -*** Settings *** -Documentation doc - - -*** Test Cases *** -Test - [Documentation] doc - [Tags] sometag - Pass - Keyword - One More - - -*** Keywords *** -Keyword - [Documentation] this is doc - [Argument] - No Operation - Pass - No Operation - Fail - IF ${condition} - Keyword - End - IF ${condition} - Keyword - ELSE IF ${condition} Empty Body - END - IF ${condition} - Keyword - ELse IF ${condition} - Keyword - END - IF ${condition} - Keyword - ELSE IF ${condition} - Keyword - ElSE - Keyword - END - IF ${condition} ${condition} - Keyword - END - IF ${condition} == - \ ${flag} - Keyword - END - -For Loop - FOR IN RANGE 10 - Keyword - END - FOR ${var} IN @{list} - END - FOR ${var} IN RANGE - Keyword - END - FOR ${var} IN RANGE 10 - Keyword - FOR ${var} @{list} - Keyword - END \ No newline at end of file diff --git a/tests/atest/transformers/MergeAndOrderSections/test_transformer.py b/tests/atest/transformers/MergeAndOrderSections/test_transformer.py index 7736b807..67b02b16 100644 --- a/tests/atest/transformers/MergeAndOrderSections/test_transformer.py +++ b/tests/atest/transformers/MergeAndOrderSections/test_transformer.py @@ -25,13 +25,13 @@ def test_empty_section(self): self.compare(source="empty_section.robot") def test_parsing_error(self): - self.compare(source="parsing_error.robot") + self.compare(source="parsing_error.robot", not_modified=True) def test_too_few_calls_in_keyword(self): self.compare(source="too_few_calls_in_keyword.robot") def test_default_order(self): - self.compare(source="order.robot") + self.compare(source="order.robot", not_modified=True) def test_custom_order(self): self.compare( diff --git a/tests/atest/transformers/NormalizeNewLines/test_transformer.py b/tests/atest/transformers/NormalizeNewLines/test_transformer.py index e6c7787c..24116bd2 100644 --- a/tests/atest/transformers/NormalizeNewLines/test_transformer.py +++ b/tests/atest/transformers/NormalizeNewLines/test_transformer.py @@ -33,12 +33,11 @@ def test_templated_tests_separated(self): config=":separate_templated_tests=True", ) - @pytest.mark.parametrize("lines_at_the_end", [0, 1]) - def test_test_case_last(self, lines_at_the_end): - self.compare( - source=f"test_case_last_{lines_at_the_end}_lines.robot", - expected="test_case_last.robot", - ) + def test_test_case_last_0(self): + self.compare(source=f"test_case_last_0_lines.robot", expected="test_case_last.robot") + + def test_test_case_last_1(self): + self.compare(source=f"test_case_last_1_lines.robot", not_modified=True) @pytest.mark.parametrize("empty_lines", [0, 1, 2]) def test_consecutive_empty_lines(self, empty_lines): diff --git a/tests/atest/transformers/NormalizeSeparators/expected/empty_sections.robot b/tests/atest/transformers/NormalizeSeparators/expected/empty_sections.robot deleted file mode 100644 index 7b2d47bb..00000000 --- a/tests/atest/transformers/NormalizeSeparators/expected/empty_sections.robot +++ /dev/null @@ -1,47 +0,0 @@ - # this is comment - -*** Settings *** -Library library.py WITH NAME alias - -Force Tags tag -... tag - -Documentation doc -... multi -... line - -*** Variables *** -${var} 3 - ${var2} 4 - -*** Test Cases *** -Test case - [Setup] Keyword - Keyword with arg - ... and multi lines - [Teardown] Keyword - -Test case with structures - FOR ${variable} IN 1 2 - Keyword - IF ${condition} - Log ${stuff} console=True - END - END - -*** Keywords *** -Keyword -Another Keyword - [Arguments] ${arg} - Should Be Equal 1 - ... ${arg} - IF ${condition} - FOR ${v} IN RANGE 10 - Keyword - END - END - -Keyword With Tabulators - Keyword - ... 2 - ... ${arg} diff --git a/tests/atest/transformers/NormalizeSeparators/test_transformer.py b/tests/atest/transformers/NormalizeSeparators/test_transformer.py index 2e282d51..2dfc8f8e 100644 --- a/tests/atest/transformers/NormalizeSeparators/test_transformer.py +++ b/tests/atest/transformers/NormalizeSeparators/test_transformer.py @@ -20,8 +20,12 @@ def test_pipes(self): ["", "comments,settings,variables", "comment,keywords", "comments,settings,variable,keywords,testcases"], ) def test_disable_section(self, sections): - expected = "empty_sections.robot" if not sections else sections.replace(",", "_") + ".robot" - self.compare(source="test.robot", expected=expected, config=f":sections={sections}") + if sections: + self.compare( + source="test.robot", expected=sections.replace(",", "_") + ".robot", config=f":sections={sections}" + ) + else: + self.compare(source="test.robot", not_modified=True, config=f":sections={sections}") def test_configure_invalid_section(self): result = self.run_tidy( diff --git a/tests/atest/transformers/OrderSettingsSection/expected/just_comment.robot b/tests/atest/transformers/OrderSettingsSection/expected/just_comment.robot deleted file mode 100644 index a22c71d5..00000000 --- a/tests/atest/transformers/OrderSettingsSection/expected/just_comment.robot +++ /dev/null @@ -1,2 +0,0 @@ -*** Settings *** -# comment diff --git a/tests/atest/transformers/OrderSettingsSection/test_transformer.py b/tests/atest/transformers/OrderSettingsSection/test_transformer.py index 51483fb0..6781b12a 100644 --- a/tests/atest/transformers/OrderSettingsSection/test_transformer.py +++ b/tests/atest/transformers/OrderSettingsSection/test_transformer.py @@ -13,7 +13,7 @@ def test_missing_group(self): self.compare(source="missing_group.robot") def test_just_comment(self): - self.compare(source="just_comment.robot") + self.compare(source="just_comment.robot", not_modified=True) def test_last_section(self): self.compare(source="last_section.robot") diff --git a/tests/atest/transformers/RenameTestCases/expected/empty_test_name.robot b/tests/atest/transformers/RenameTestCases/expected/empty_test_name.robot deleted file mode 100644 index f1e99d3d..00000000 --- a/tests/atest/transformers/RenameTestCases/expected/empty_test_name.robot +++ /dev/null @@ -1,11 +0,0 @@ -*** Test Cases *** - -# no test case name!!! - Log To Console hello - -Proper test - [documentation] doc - [tags] sometag - Pass - Keyword - One More diff --git a/tests/atest/transformers/RenameTestCases/test_transformer.py b/tests/atest/transformers/RenameTestCases/test_transformer.py index 481936d3..9e60cb94 100644 --- a/tests/atest/transformers/RenameTestCases/test_transformer.py +++ b/tests/atest/transformers/RenameTestCases/test_transformer.py @@ -8,7 +8,7 @@ def test_transformer(self): self.compare(source="test.robot", expected="test.robot") def test_test_without_name(self): - self.compare(source="empty_test_name.robot", expected="empty_test_name.robot") + self.compare(source="empty_test_name.robot", not_modified=True) def test_replace_pattern_to_empty(self): self.compare( diff --git a/tests/atest/transformers/ReplaceBreakContinue/expected/errors.robot b/tests/atest/transformers/ReplaceBreakContinue/expected/errors.robot deleted file mode 100644 index e8563d4a..00000000 --- a/tests/atest/transformers/ReplaceBreakContinue/expected/errors.robot +++ /dev/null @@ -1,13 +0,0 @@ -*** Test Cases *** -Missing condition - FOR ${var} IN RANGE 2 - Continue For Loop If - Exit For Loop If - END - -*** Keywords *** -Missing condition - FOR ${var} IN RANGE 2 - Continue For Loop If - Exit For Loop If - END diff --git a/tests/atest/transformers/ReplaceBreakContinue/test_transformer.py b/tests/atest/transformers/ReplaceBreakContinue/test_transformer.py index 198f9bd5..b93ce682 100644 --- a/tests/atest/transformers/ReplaceBreakContinue/test_transformer.py +++ b/tests/atest/transformers/ReplaceBreakContinue/test_transformer.py @@ -1,11 +1,11 @@ -import pytest - from .. import TransformerAcceptanceTest class TestReplaceBreakContinue(TransformerAcceptanceTest): TRANSFORMER_NAME = "ReplaceBreakContinue" - @pytest.mark.parametrize("source", ["test.robot", "errors.robot"]) - def test_transformer(self, source): - self.compare(source=source) + def test_transformer(self): + self.compare(source="test.robot") + + def test_with_errors(self): + self.compare(source="errors.robot", not_modified=True) diff --git a/tests/atest/transformers/ReplaceReturns/expected/errors.robot b/tests/atest/transformers/ReplaceReturns/expected/errors.robot deleted file mode 100644 index 916b81f7..00000000 --- a/tests/atest/transformers/ReplaceReturns/expected/errors.robot +++ /dev/null @@ -1,9 +0,0 @@ -*** Test Cases *** -Return From Keyword - Return From Keyword If - Run Keyword And Return If $condition - -*** Keywords *** -Return From Keyword - Return From Keyword If - Run Keyword And Return If $condition diff --git a/tests/atest/transformers/ReplaceReturns/expected/run_keyword_and_return.robot b/tests/atest/transformers/ReplaceReturns/expected/run_keyword_and_return.robot deleted file mode 100644 index 121f4a1b..00000000 --- a/tests/atest/transformers/ReplaceReturns/expected/run_keyword_and_return.robot +++ /dev/null @@ -1,12 +0,0 @@ -*** Test Cases *** -For and Ifs - FOR ${var} IN 1 2 - IF $var == 2 - Run Keyword And Return Keyword ${arg} - END - END - -*** Keywords *** -Testing - Run Keyword And Return Keyword ${arg} - ... ${arg2} diff --git a/tests/atest/transformers/ReplaceReturns/expected/run_keyword_and_return_if.robot b/tests/atest/transformers/ReplaceReturns/expected/run_keyword_and_return_if.robot deleted file mode 100644 index f8382391..00000000 --- a/tests/atest/transformers/ReplaceReturns/expected/run_keyword_and_return_if.robot +++ /dev/null @@ -1,14 +0,0 @@ -*** Keywords *** -First - ${var} Set Variable 1 - FOR ${variable} IN 1 2 - Run Keyword And Return If ${var}==2 Keyword 2 ${var} - Log ${variable} - END - -With IF - ${var} Set Variable 1 - IF ${var}>0 - Run Keyword And Return If $var Some Keyword ${var} - ... 1 - END diff --git a/tests/atest/transformers/ReplaceReturns/test_transformer.py b/tests/atest/transformers/ReplaceReturns/test_transformer.py index fe7bf921..f1f1dafa 100644 --- a/tests/atest/transformers/ReplaceReturns/test_transformer.py +++ b/tests/atest/transformers/ReplaceReturns/test_transformer.py @@ -9,17 +9,25 @@ class TestReplaceReturns(TransformerAcceptanceTest): @pytest.mark.parametrize( "source", [ - "errors.robot", "return_from_keyword.robot", "return_from_keyword_if.robot", - "run_keyword_and_return.robot", - "run_keyword_and_return_if.robot", "test.robot", ], ) def test_transformer(self, source): self.compare(source=source) + @pytest.mark.parametrize( + "source", + [ + "errors.robot", + "run_keyword_and_return.robot", + "run_keyword_and_return_if.robot", + ], + ) + def test_should_not_modify(self, source): + self.compare(source=source, not_modified=True) + def test_return_selected(self): self.compare( source="test.robot", diff --git a/tests/atest/transformers/ReplaceRunKeywordIf/expected/golden.robot b/tests/atest/transformers/ReplaceRunKeywordIf/expected/golden.robot deleted file mode 100644 index d0c589a5..00000000 --- a/tests/atest/transformers/ReplaceRunKeywordIf/expected/golden.robot +++ /dev/null @@ -1,121 +0,0 @@ -*** Test Cases *** -Leave existing if blocks - IF condition - Keyword - ELSE IF condition2 - Keyword2 - ELSE - Keyword - END - -Single Return Value - IF ${condition} - ${var} Keyword With ${var} ${arg} - END - -Multiple Return Values - IF ${condition} - ${var} ${var2} Keyword With ${var} ${arg} - END - -Run keyword if with else if - IF ${condition} - Keyword - ELSE IF ${other_condition} - Other Keyword - ELSE - Final Keyword - END - -Run keyword if with else if and args - IF ${condition} - Keyword a b c - ELSE IF ${other_condition} - Other Keyword - ELSE - Final Keyword 1 2 ${var} - END - -Run keyword if with else if and return values - IF ${condition} - ${var} ${var} Keyword - ELSE IF ${other_condition} - ${var} ${var} Other Keyword ${arg} - ELSE - ${var} ${var} Final Keyword - END - -Run keyword if with else if and run keywords - IF "${var}"=="a" - First Keyword - Second Keyword 1 2 - ELSE IF ${var}==1 - Single Keyword ${argument} - ELSE - Normal Keyword abc - END - -Run keyword if inside FOR loop - FOR ${var} IN @{elems} - IF ${condition} - Keyword - ELSE IF ${other_condition} - Other Keyword - ELSE - Final Keyword - END - END - -Run keyword if inside IF - IF ${condition} - IF ${condition} - Keyword - ELSE IF ${other_condition} - Other Keyword - ELSE - Final Keyword - END - END - -*** Keywords *** -Test Content Merged Into One Keyword - IF condition - Keyword - ELSE IF condition2 - Keyword2 - ELSE - Keyword - END - - IF ${condition} - Keyword - ELSE IF ${other_condition} - Other Keyword - ELSE - Final Keyword - END - - IF ${condition} - Keyword a b c - ELSE IF ${other_condition} - Other Keyword - ELSE - Final Keyword 1 2 ${var} - END - - IF ${condition} - ${var} ${var} Keyword - ELSE IF ${other_condition} - ${var} ${var} Other Keyword ${arg} - ELSE - ${var} ${var} Final Keyword - END - - IF "${var}"=="a" - First Keyword - Second Keyword 1 2 - ELSE IF ${var}==1 - Single Keyword ${argument} - ELSE - Normal Keyword abc - END diff --git a/tests/atest/transformers/ReplaceRunKeywordIf/test_transformer.py b/tests/atest/transformers/ReplaceRunKeywordIf/test_transformer.py index b00e43d3..bb2e99d1 100644 --- a/tests/atest/transformers/ReplaceRunKeywordIf/test_transformer.py +++ b/tests/atest/transformers/ReplaceRunKeywordIf/test_transformer.py @@ -18,7 +18,7 @@ def test_invalid_data(self): self.compare(source="invalid_data.robot") def test_golden_file(self): - self.compare(source="golden.robot") + self.compare(source="golden.robot", not_modified=True) def test_remove_useless_set_variable(self): self.compare(source="set_variable_workaround.robot") diff --git a/tests/atest/transformers/SmartSortKeywords/expected/empty_before_fist_keyword.robot b/tests/atest/transformers/SmartSortKeywords/expected/empty_before_fist_keyword.robot deleted file mode 100644 index a081fb21..00000000 --- a/tests/atest/transformers/SmartSortKeywords/expected/empty_before_fist_keyword.robot +++ /dev/null @@ -1,4 +0,0 @@ -*** Keywords *** - -# My Comment -my_kw \ No newline at end of file diff --git a/tests/atest/transformers/SmartSortKeywords/test_transformer.py b/tests/atest/transformers/SmartSortKeywords/test_transformer.py index 2d771742..3acea6b5 100644 --- a/tests/atest/transformers/SmartSortKeywords/test_transformer.py +++ b/tests/atest/transformers/SmartSortKeywords/test_transformer.py @@ -57,7 +57,7 @@ def test_(self): ) def test_empty_section(self): - self.compare(source="empty_before_fist_keyword.robot") + self.compare(source="empty_before_fist_keyword.robot", not_modified=True) def test_multiple_sections(self): self.compare(source="multiple_sections.robot") diff --git a/tests/atest/transformers/__init__.py b/tests/atest/transformers/__init__.py index ef60c60e..aaf91bb6 100644 --- a/tests/atest/transformers/__init__.py +++ b/tests/atest/transformers/__init__.py @@ -36,19 +36,33 @@ class TransformerAcceptanceTest: TRANSFORMER_NAME: str = "DUMMY" def compare( - self, source: str, expected: Optional[str] = None, config: str = "", target_version: Optional[int] = None + self, + source: str, + not_modified: bool = False, + expected: Optional[str] = None, + config: str = "", + target_version: Optional[int] = None, ): + """ + Compare actual (source) and expected files. If expected filename is not provided it's assumed to be the same + as source. + + Use not_modified flag if the content of the file shouldn't be modified by transformer. + """ if not self.enabled_in_version(target_version): pytest.skip(f"Test enabled only for RF {target_version}.0") if expected is None: expected = source self.run_tidy(args=f"--transform {self.TRANSFORMER_NAME}{config}".split(), source=source) - self.compare_file(source, expected) + if not not_modified: + self.compare_file(source, expected) - def run_tidy(self, args: List[str] = None, source: str = None, exit_code: int = 0): + def run_tidy(self, args: List[str] = None, source: str = None, exit_code: int = 0, not_modified: bool = False): runner = CliRunner() output_path = str(Path(Path(__file__).parent, "actual", source)) arguments = ["--output", output_path] + if not_modified: + arguments.append("--check") if args is not None: arguments += args if source is None: diff --git a/tests/utest/test_cli.py b/tests/utest/test_cli.py index 89d725d4..9fb0eb38 100644 --- a/tests/utest/test_cli.py +++ b/tests/utest/test_cli.py @@ -318,7 +318,10 @@ def test_check_overwrite(self, source, return_status, test_data_dir): ["--check", "--overwrite", "--transform", "NormalizeSectionHeaderName", str(source)], exit_code=return_status, ) - mock_writer.assert_called() + if return_status: + mock_writer.assert_called() + else: + mock_writer.assert_not_called() def test_diff(self, test_data_dir): source = test_data_dir / "check" / "not_golden.robot"