@@ -39,16 +39,6 @@ def switch_cwd(new_cwd):
39
39
os .chdir (prev_cwd )
40
40
41
41
42
- @contextmanager
43
- def switch_cwd (new_cwd ):
44
- prev_cwd = Path .cwd ()
45
- os .chdir (new_cwd )
46
- try :
47
- yield
48
- finally :
49
- os .chdir (prev_cwd )
50
-
51
-
52
42
class TestCli :
53
43
@pytest .mark .parametrize (
54
44
"name, similar" ,
@@ -320,28 +310,46 @@ def test_help(self, flag):
320
310
result = run_tidy ([flag ])
321
311
assert f"Robotidy is a tool for formatting" in result .output
322
312
323
- @pytest .mark .parametrize ("source, return_status" , [("golden.robot" , 0 ), ("not_golden.robot" , 1 )])
324
- def test_check (self , source , return_status ):
313
+ @pytest .mark .parametrize (
314
+ "source, return_status, expected_output" ,
315
+ [
316
+ ("golden.robot" , 0 , "\n 0 files would be reformatted, 1 file would be left unchanged.\n " ),
317
+ ("not_golden.robot" , 1 , "\n 1 file would be reformatted, 0 files would be left unchanged.\n " ),
318
+ ],
319
+ )
320
+ def test_check (self , source , return_status , expected_output ):
325
321
source = TEST_DATA_DIR / "check" / source
322
+ if return_status :
323
+ expected_output = f"Would reformat { source } \n { expected_output } "
326
324
with patch ("robotidy.utils.misc.ModelWriter" ) as mock_writer :
327
- run_tidy (
325
+ result = run_tidy (
328
326
["--check" , "--transform" , "NormalizeSectionHeaderName" , str (source )],
329
327
exit_code = return_status ,
330
328
)
331
329
mock_writer .assert_not_called ()
330
+ assert result .output == expected_output
332
331
333
- @pytest .mark .parametrize ("source, return_status" , [("golden.robot" , 0 ), ("not_golden.robot" , 1 )])
334
- def test_check_overwrite (self , source , return_status ):
332
+ @pytest .mark .parametrize (
333
+ "source, return_status, expected_output" ,
334
+ [
335
+ ("golden.robot" , 0 , "\n 0 files reformatted, 1 file left unchanged.\n " ),
336
+ ("not_golden.robot" , 1 , "\n 1 file reformatted, 0 files left unchanged.\n " ),
337
+ ],
338
+ )
339
+ def test_check_overwrite (self , source , return_status , expected_output ):
335
340
source = TEST_DATA_DIR / "check" / source
341
+ if return_status :
342
+ expected_output = f"Reformatted { source } \n { expected_output } "
336
343
with patch ("robotidy.utils.misc.ModelWriter" ) as mock_writer :
337
- run_tidy (
344
+ result = run_tidy (
338
345
["--check" , "--overwrite" , "--transform" , "NormalizeSectionHeaderName" , str (source )],
339
346
exit_code = return_status ,
340
347
)
341
348
if return_status :
342
349
mock_writer .assert_called ()
343
350
else :
344
351
mock_writer .assert_not_called ()
352
+ assert result .output == expected_output
345
353
346
354
@pytest .mark .parametrize ("color_flag" , ["--color" , "--no-color" , None ])
347
355
@pytest .mark .parametrize ("color_env" , [True , False ])
@@ -409,26 +417,38 @@ def test_exclude_gitignore(self, exclude, extend_exclude, skip_gitignore, allowe
409
417
assert paths == allowed_paths
410
418
411
419
@pytest .mark .parametrize (
412
- "source, should_parse" ,
420
+ "source, should_parse, summary " ,
413
421
[
414
- (None , ["test.robot" , "resources/test.robot" ]), # calls: robotidy
415
- ("test3.robot" , ["test3.robot" ]), # calls: robotidy test3.robot
416
- ("test.robot" , ["test.robot" ]),
417
- ("." , ["test.robot" , "test3.robot" , "resources/test.robot" ]),
422
+ (
423
+ None ,
424
+ ["test.robot" , "resources/test.robot" ],
425
+ "0 files reformatted, 2 files left unchanged." ,
426
+ ), # calls: robotidy
427
+ (
428
+ "test3.robot" ,
429
+ ["test3.robot" ],
430
+ "0 files reformatted, 1 file left unchanged." ,
431
+ ), # calls: robotidy test3.robot
432
+ ("test.robot" , ["test.robot" ], "0 files reformatted, 1 file left unchanged." ),
433
+ (
434
+ "." ,
435
+ ["test.robot" , "test3.robot" , "resources/test.robot" ],
436
+ "0 files reformatted, 3 files left unchanged." ,
437
+ ),
418
438
],
419
439
)
420
- def test_src_and_space_in_param_in_configuration (self , source , should_parse ):
440
+ def test_src_and_space_in_param_in_configuration (self , source , should_parse , summary ):
421
441
source_dir = TEST_DATA_DIR / "pyproject_with_src"
422
442
os .chdir (source_dir )
423
443
if source is not None :
424
444
source = source_dir / source
425
445
result = run_tidy ([str (source )])
426
446
else :
427
447
result = run_tidy ()
428
- expected = [f"Loaded configuration from { source_dir / 'pyproject.toml' } " ]
448
+ expected = [f"Loaded configuration from { source_dir / 'pyproject.toml' } " , summary ]
429
449
for file in should_parse :
430
450
path = source_dir / file
431
- expected .append (f"Transforming { path } file" )
451
+ expected .append (f"Found { path } file" )
432
452
actual = sorted (line for line in result .output .split ("\n " ) if line .strip ())
433
453
assert actual == sorted (expected )
434
454
0 commit comments