22
22
23
23
from tests .common import build_temp_workspace
24
24
25
+ from yamllint .config import YamlLintConfigError
25
26
from yamllint import cli
26
27
from yamllint import config
27
28
@@ -429,10 +430,10 @@ def test_extend_config_override_rule_partly(self):
429
430
self .assertEqual (new .rules ['empty-lines' ]['max-end' ], 0 )
430
431
431
432
432
- class IgnorePathConfigTestCase (unittest .TestCase ):
433
+ class IgnoreConfigTestCase (unittest .TestCase ):
433
434
@classmethod
434
435
def setUpClass (cls ):
435
- super (IgnorePathConfigTestCase , cls ).setUpClass ()
436
+ super ().setUpClass ()
436
437
437
438
bad_yaml = ('---\n '
438
439
'- key: val1\n '
@@ -452,36 +453,208 @@ def setUpClass(cls):
452
453
's/s/ign-trail/file.yaml' : bad_yaml ,
453
454
's/s/ign-trail/s/s/file.yaml' : bad_yaml ,
454
455
's/s/ign-trail/s/s/file2.lint-me-anyway.yaml' : bad_yaml ,
455
-
456
- '.yamllint' : 'ignore: |\n '
457
- ' *.dont-lint-me.yaml\n '
458
- ' /bin/\n '
459
- ' !/bin/*.lint-me-anyway.yaml\n '
460
- '\n '
461
- 'extends: default\n '
462
- '\n '
463
- 'rules:\n '
464
- ' key-duplicates:\n '
465
- ' ignore: |\n '
466
- ' /ign-dup\n '
467
- ' trailing-spaces:\n '
468
- ' ignore: |\n '
469
- ' ign-trail\n '
470
- ' !*.lint-me-anyway.yaml\n ' ,
471
456
})
472
457
473
458
cls .backup_wd = os .getcwd ()
474
459
os .chdir (cls .wd )
475
460
476
461
@classmethod
477
462
def tearDownClass (cls ):
478
- super (IgnorePathConfigTestCase , cls ).tearDownClass ()
463
+ super ().tearDownClass ()
479
464
480
465
os .chdir (cls .backup_wd )
481
466
482
467
shutil .rmtree (cls .wd )
483
468
484
- def test_run_with_ignored_path (self ):
469
+ def test_mutually_exclusive_ignore_keys (self ):
470
+ self .assertRaises (
471
+ YamlLintConfigError ,
472
+ config .YamlLintConfig , 'extends: default\n '
473
+ 'ignore-from-file: .gitignore\n '
474
+ 'ignore: |\n '
475
+ ' *.dont-lint-me.yaml\n '
476
+ ' /bin/\n ' )
477
+
478
+ def test_ignore_from_file_not_exist (self ):
479
+ self .assertRaises (
480
+ FileNotFoundError ,
481
+ config .YamlLintConfig , 'extends: default\n '
482
+ 'ignore-from-file: not_found_file\n ' )
483
+
484
+ def test_ignore_from_file_incorrect_type (self ):
485
+ self .assertRaises (
486
+ YamlLintConfigError ,
487
+ config .YamlLintConfig , 'extends: default\n '
488
+ 'ignore-from-file: 0\n ' )
489
+ self .assertRaises (
490
+ YamlLintConfigError ,
491
+ config .YamlLintConfig , 'extends: default\n '
492
+ 'ignore-from-file: [0]\n ' )
493
+
494
+ def test_no_ignore (self ):
495
+ sys .stdout = StringIO ()
496
+ with self .assertRaises (SystemExit ):
497
+ cli .run (('-f' , 'parsable' , '.' ))
498
+
499
+ out = sys .stdout .getvalue ()
500
+ out = '\n ' .join (sorted (out .splitlines ()))
501
+
502
+ keydup = '[error] duplication of key "key" in mapping (key-duplicates)'
503
+ trailing = '[error] trailing spaces (trailing-spaces)'
504
+ hyphen = '[error] too many spaces after hyphen (hyphens)'
505
+
506
+ self .assertEqual (out , '\n ' .join ((
507
+ './bin/file.lint-me-anyway.yaml:3:3: ' + keydup ,
508
+ './bin/file.lint-me-anyway.yaml:4:17: ' + trailing ,
509
+ './bin/file.lint-me-anyway.yaml:5:5: ' + hyphen ,
510
+ './bin/file.yaml:3:3: ' + keydup ,
511
+ './bin/file.yaml:4:17: ' + trailing ,
512
+ './bin/file.yaml:5:5: ' + hyphen ,
513
+ './file-at-root.yaml:3:3: ' + keydup ,
514
+ './file-at-root.yaml:4:17: ' + trailing ,
515
+ './file-at-root.yaml:5:5: ' + hyphen ,
516
+ './file.dont-lint-me.yaml:3:3: ' + keydup ,
517
+ './file.dont-lint-me.yaml:4:17: ' + trailing ,
518
+ './file.dont-lint-me.yaml:5:5: ' + hyphen ,
519
+ './ign-dup/file.yaml:3:3: ' + keydup ,
520
+ './ign-dup/file.yaml:4:17: ' + trailing ,
521
+ './ign-dup/file.yaml:5:5: ' + hyphen ,
522
+ './ign-dup/sub/dir/file.yaml:3:3: ' + keydup ,
523
+ './ign-dup/sub/dir/file.yaml:4:17: ' + trailing ,
524
+ './ign-dup/sub/dir/file.yaml:5:5: ' + hyphen ,
525
+ './ign-trail/file.yaml:3:3: ' + keydup ,
526
+ './ign-trail/file.yaml:4:17: ' + trailing ,
527
+ './ign-trail/file.yaml:5:5: ' + hyphen ,
528
+ './include/ign-dup/sub/dir/file.yaml:3:3: ' + keydup ,
529
+ './include/ign-dup/sub/dir/file.yaml:4:17: ' + trailing ,
530
+ './include/ign-dup/sub/dir/file.yaml:5:5: ' + hyphen ,
531
+ './s/s/ign-trail/file.yaml:3:3: ' + keydup ,
532
+ './s/s/ign-trail/file.yaml:4:17: ' + trailing ,
533
+ './s/s/ign-trail/file.yaml:5:5: ' + hyphen ,
534
+ './s/s/ign-trail/s/s/file.yaml:3:3: ' + keydup ,
535
+ './s/s/ign-trail/s/s/file.yaml:4:17: ' + trailing ,
536
+ './s/s/ign-trail/s/s/file.yaml:5:5: ' + hyphen ,
537
+ './s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:3:3: ' + keydup ,
538
+ './s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:4:17: ' + trailing ,
539
+ './s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:5:5: ' + hyphen ,
540
+ )))
541
+
542
+ def test_run_with_ignore (self ):
543
+ with open (os .path .join (self .wd , '.yamllint' ), 'w' ) as f :
544
+ f .write ('extends: default\n '
545
+ 'ignore: |\n '
546
+ ' *.dont-lint-me.yaml\n '
547
+ ' /bin/\n '
548
+ ' !/bin/*.lint-me-anyway.yaml\n '
549
+ 'rules:\n '
550
+ ' key-duplicates:\n '
551
+ ' ignore: |\n '
552
+ ' /ign-dup\n '
553
+ ' trailing-spaces:\n '
554
+ ' ignore: |\n '
555
+ ' ign-trail\n '
556
+ ' !*.lint-me-anyway.yaml\n ' )
557
+
558
+ sys .stdout = StringIO ()
559
+ with self .assertRaises (SystemExit ):
560
+ cli .run (('-f' , 'parsable' , '.' ))
561
+
562
+ out = sys .stdout .getvalue ()
563
+ out = '\n ' .join (sorted (out .splitlines ()))
564
+
565
+ docstart = '[warning] missing document start "---" (document-start)'
566
+ keydup = '[error] duplication of key "key" in mapping (key-duplicates)'
567
+ trailing = '[error] trailing spaces (trailing-spaces)'
568
+ hyphen = '[error] too many spaces after hyphen (hyphens)'
569
+
570
+ self .assertEqual (out , '\n ' .join ((
571
+ './.yamllint:1:1: ' + docstart ,
572
+ './bin/file.lint-me-anyway.yaml:3:3: ' + keydup ,
573
+ './bin/file.lint-me-anyway.yaml:4:17: ' + trailing ,
574
+ './bin/file.lint-me-anyway.yaml:5:5: ' + hyphen ,
575
+ './file-at-root.yaml:3:3: ' + keydup ,
576
+ './file-at-root.yaml:4:17: ' + trailing ,
577
+ './file-at-root.yaml:5:5: ' + hyphen ,
578
+ './ign-dup/file.yaml:4:17: ' + trailing ,
579
+ './ign-dup/file.yaml:5:5: ' + hyphen ,
580
+ './ign-dup/sub/dir/file.yaml:4:17: ' + trailing ,
581
+ './ign-dup/sub/dir/file.yaml:5:5: ' + hyphen ,
582
+ './ign-trail/file.yaml:3:3: ' + keydup ,
583
+ './ign-trail/file.yaml:5:5: ' + hyphen ,
584
+ './include/ign-dup/sub/dir/file.yaml:3:3: ' + keydup ,
585
+ './include/ign-dup/sub/dir/file.yaml:4:17: ' + trailing ,
586
+ './include/ign-dup/sub/dir/file.yaml:5:5: ' + hyphen ,
587
+ './s/s/ign-trail/file.yaml:3:3: ' + keydup ,
588
+ './s/s/ign-trail/file.yaml:5:5: ' + hyphen ,
589
+ './s/s/ign-trail/s/s/file.yaml:3:3: ' + keydup ,
590
+ './s/s/ign-trail/s/s/file.yaml:5:5: ' + hyphen ,
591
+ './s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:3:3: ' + keydup ,
592
+ './s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:4:17: ' + trailing ,
593
+ './s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:5:5: ' + hyphen ,
594
+ )))
595
+
596
+ def test_run_with_ignore_from_file (self ):
597
+ with open (os .path .join (self .wd , '.yamllint' ), 'w' ) as f :
598
+ f .write ('extends: default\n '
599
+ 'ignore-from-file: .gitignore\n ' )
600
+ with open (os .path .join (self .wd , '.gitignore' ), 'w' ) as f :
601
+ f .write ('*.dont-lint-me.yaml\n '
602
+ '/bin/\n '
603
+ '!/bin/*.lint-me-anyway.yaml\n ' )
604
+
605
+ sys .stdout = StringIO ()
606
+ with self .assertRaises (SystemExit ):
607
+ cli .run (('-f' , 'parsable' , '.' ))
608
+
609
+ out = sys .stdout .getvalue ()
610
+ out = '\n ' .join (sorted (out .splitlines ()))
611
+
612
+ docstart = '[warning] missing document start "---" (document-start)'
613
+ keydup = '[error] duplication of key "key" in mapping (key-duplicates)'
614
+ trailing = '[error] trailing spaces (trailing-spaces)'
615
+ hyphen = '[error] too many spaces after hyphen (hyphens)'
616
+
617
+ self .assertEqual (out , '\n ' .join ((
618
+ './.yamllint:1:1: ' + docstart ,
619
+ './bin/file.lint-me-anyway.yaml:3:3: ' + keydup ,
620
+ './bin/file.lint-me-anyway.yaml:4:17: ' + trailing ,
621
+ './bin/file.lint-me-anyway.yaml:5:5: ' + hyphen ,
622
+ './file-at-root.yaml:3:3: ' + keydup ,
623
+ './file-at-root.yaml:4:17: ' + trailing ,
624
+ './file-at-root.yaml:5:5: ' + hyphen ,
625
+ './ign-dup/file.yaml:3:3: ' + keydup ,
626
+ './ign-dup/file.yaml:4:17: ' + trailing ,
627
+ './ign-dup/file.yaml:5:5: ' + hyphen ,
628
+ './ign-dup/sub/dir/file.yaml:3:3: ' + keydup ,
629
+ './ign-dup/sub/dir/file.yaml:4:17: ' + trailing ,
630
+ './ign-dup/sub/dir/file.yaml:5:5: ' + hyphen ,
631
+ './ign-trail/file.yaml:3:3: ' + keydup ,
632
+ './ign-trail/file.yaml:4:17: ' + trailing ,
633
+ './ign-trail/file.yaml:5:5: ' + hyphen ,
634
+ './include/ign-dup/sub/dir/file.yaml:3:3: ' + keydup ,
635
+ './include/ign-dup/sub/dir/file.yaml:4:17: ' + trailing ,
636
+ './include/ign-dup/sub/dir/file.yaml:5:5: ' + hyphen ,
637
+ './s/s/ign-trail/file.yaml:3:3: ' + keydup ,
638
+ './s/s/ign-trail/file.yaml:4:17: ' + trailing ,
639
+ './s/s/ign-trail/file.yaml:5:5: ' + hyphen ,
640
+ './s/s/ign-trail/s/s/file.yaml:3:3: ' + keydup ,
641
+ './s/s/ign-trail/s/s/file.yaml:4:17: ' + trailing ,
642
+ './s/s/ign-trail/s/s/file.yaml:5:5: ' + hyphen ,
643
+ './s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:3:3: ' + keydup ,
644
+ './s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:4:17: ' + trailing ,
645
+ './s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:5:5: ' + hyphen ,
646
+ )))
647
+
648
+ def test_run_with_ignored_from_file (self ):
649
+ with open (os .path .join (self .wd , '.yamllint' ), 'w' ) as f :
650
+ f .write ('ignore-from-file: [.gitignore, .yamlignore]\n '
651
+ 'extends: default\n ' )
652
+ with open (os .path .join (self .wd , '.gitignore' ), 'w' ) as f :
653
+ f .write ('*.dont-lint-me.yaml\n '
654
+ '/bin/\n ' )
655
+ with open (os .path .join (self .wd , '.yamlignore' ), 'w' ) as f :
656
+ f .write ('!/bin/*.lint-me-anyway.yaml\n ' )
657
+
485
658
sys .stdout = StringIO ()
486
659
with self .assertRaises (SystemExit ):
487
660
cli .run (('-f' , 'parsable' , '.' ))
@@ -502,18 +675,23 @@ def test_run_with_ignored_path(self):
502
675
'./file-at-root.yaml:3:3: ' + keydup ,
503
676
'./file-at-root.yaml:4:17: ' + trailing ,
504
677
'./file-at-root.yaml:5:5: ' + hyphen ,
678
+ './ign-dup/file.yaml:3:3: ' + keydup ,
505
679
'./ign-dup/file.yaml:4:17: ' + trailing ,
506
680
'./ign-dup/file.yaml:5:5: ' + hyphen ,
681
+ './ign-dup/sub/dir/file.yaml:3:3: ' + keydup ,
507
682
'./ign-dup/sub/dir/file.yaml:4:17: ' + trailing ,
508
683
'./ign-dup/sub/dir/file.yaml:5:5: ' + hyphen ,
509
684
'./ign-trail/file.yaml:3:3: ' + keydup ,
685
+ './ign-trail/file.yaml:4:17: ' + trailing ,
510
686
'./ign-trail/file.yaml:5:5: ' + hyphen ,
511
687
'./include/ign-dup/sub/dir/file.yaml:3:3: ' + keydup ,
512
688
'./include/ign-dup/sub/dir/file.yaml:4:17: ' + trailing ,
513
689
'./include/ign-dup/sub/dir/file.yaml:5:5: ' + hyphen ,
514
690
'./s/s/ign-trail/file.yaml:3:3: ' + keydup ,
691
+ './s/s/ign-trail/file.yaml:4:17: ' + trailing ,
515
692
'./s/s/ign-trail/file.yaml:5:5: ' + hyphen ,
516
693
'./s/s/ign-trail/s/s/file.yaml:3:3: ' + keydup ,
694
+ './s/s/ign-trail/s/s/file.yaml:4:17: ' + trailing ,
517
695
'./s/s/ign-trail/s/s/file.yaml:5:5: ' + hyphen ,
518
696
'./s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:3:3: ' + keydup ,
519
697
'./s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:4:17: ' + trailing ,
0 commit comments