1- from unittest . mock import patch
1+ import os
22from pathlib import Path
3-
43from unittest .mock import MagicMock , Mock
4+
55import pytest
66from click import FileError , NoSuchOption
77
8- from .utils import run_tidy , save_tmp_model
98from robotidy .cli import (
109 find_project_root ,
1110 read_pyproject_config ,
1211 read_config
1312)
14- from robotidy .utils import node_within_lines
1513from robotidy .transformers import load_transformers
1614from robotidy .transformers .AlignSettingsSection import AlignSettingsSection
1715from robotidy .transformers .ReplaceRunKeywordIf import ReplaceRunKeywordIf
1816from robotidy .transformers .SmartSortKeywords import SmartSortKeywords
17+ from robotidy .utils import node_within_lines
1918from robotidy .version import __version__
19+ from .utils import run_tidy
2020
2121
22- @patch ('robotidy.app.Robotidy.save_model' , new = save_tmp_model )
2322class TestCli :
2423 @pytest .mark .parametrize ('src' , [
2524 None ,
@@ -88,7 +87,7 @@ def test_too_many_arguments_for_transform(self):
8887 def test_find_project_root_from_src (self ):
8988 src = Path (Path (__file__ ).parent , 'testdata' , 'nested' , 'test.robot' )
9089 path = find_project_root ([src ])
91- assert path == Path (Path (__file__ ).parent , 'testdata' )
90+ assert path == Path (Path (__file__ ).parent , 'testdata' , 'nested' )
9291
9392 def test_read_robotidy_config (self ):
9493 """ robotidy.toml follows the same format as pyproject starting from 1.2.0 """
@@ -101,7 +100,7 @@ def test_read_robotidy_config(self):
101100 'ReplaceRunKeywordIf'
102101 ]
103102 }
104- config_path = str (Path (Path (__file__ ).parent , 'testdata' , 'robotidy.toml' ))
103+ config_path = str (Path (Path (__file__ ).parent , 'testdata' , 'config' , ' robotidy.toml' ))
105104 config = read_pyproject_config (config_path )
106105 assert config == expected_config
107106
@@ -176,7 +175,7 @@ def test_read_config_from_param(self):
176175 'ReplaceRunKeywordIf'
177176 ]
178177 }
179- config_path = str (Path (Path (__file__ ).parent , 'testdata' , 'robotidy.toml' ))
178+ config_path = str (Path (Path (__file__ ).parent , 'testdata' , 'config' , ' robotidy.toml' ))
180179 ctx_mock = MagicMock ()
181180 ctx_mock .command .params = None
182181 param_mock = Mock ()
@@ -193,7 +192,7 @@ def test_read_config_without_param(self):
193192 'ReplaceRunKeywordIf'
194193 ]
195194 }
196- config_path = str (Path (Path (__file__ ).parent , 'testdata' , 'robotidy.toml' ))
195+ config_path = str (Path (Path (__file__ ).parent , 'testdata' , 'config' , ' robotidy.toml' ))
197196 ctx_mock = MagicMock ()
198197 ctx_mock .params = {'src' : [config_path ]}
199198 ctx_mock .command .params = None
@@ -300,3 +299,25 @@ def test_configure_transformer_overwrite(self):
300299 {'AlignVariablesSection' : ['up_to_column=4' ]}
301300 )
302301 assert transformers [0 ].up_to_column + 1 == 4
302+
303+ @pytest .mark .parametrize ('line_sep' , ['unix' , 'windows' , 'native' , None ])
304+ def test_line_sep (self , line_sep ):
305+ source = Path (Path (__file__ ).parent , 'testdata' , 'line_sep' , 'test.robot' )
306+ expected = Path (Path (__file__ ).parent , 'testdata' , 'line_sep' , 'expected.robot' )
307+ actual = Path (Path (__file__ ).parent , 'actual' , 'test.robot' )
308+ if line_sep is not None :
309+ run_tidy (['--lineseparator' , line_sep , str (source )], output = 'test.robot' )
310+ else :
311+ run_tidy ([str (source )], output = 'test.robot' )
312+ line_end = {
313+ 'unix' : '\n ' ,
314+ 'windows' : '\r \n ' ,
315+ 'native' : os .linesep ,
316+ None : os .linesep
317+ }[line_sep ]
318+ with open (str (expected )) as f :
319+ expected_str = f .read ()
320+ expected_str = expected_str .replace ('\n ' , line_end )
321+ with open (str (actual ), newline = '' ) as f :
322+ actual_str = f .read ()
323+ assert actual_str == expected_str , 'Line endings does not match'
0 commit comments