@@ -545,55 +545,95 @@ def test_get_native_path(self) -> None:
545
545
546
546
def test_PrependPath (self ) -> None :
547
547
"""Test prepending to a path"""
548
- p1 : list | str = r'C:\dir\num\one;C:\dir\num\two'
549
- p2 : list | str = r'C:\mydir\num\one;C:\mydir\num\two'
550
- # have to include the pathsep here so that the test will work on UNIX too.
551
- p1 = PrependPath (p1 , r'C:\dir\num\two' , sep = ';' )
552
- p1 = PrependPath (p1 , r'C:\dir\num\three' , sep = ';' )
553
- assert p1 == r'C:\dir\num\three;C:\dir\num\two;C:\dir\num\one' , p1
554
-
555
- p2 = PrependPath (p2 , r'C:\mydir\num\three' , sep = ';' )
556
- p2 = PrependPath (p2 , r'C:\mydir\num\one' , sep = ';' )
557
- assert p2 == r'C:\mydir\num\one;C:\mydir\num\three;C:\mydir\num\two' , p2
558
-
559
- # check (only) first one is kept if there are dupes in new
560
- p3 : list | str = r'C:\dir\num\one'
561
- p3 = PrependPath (p3 , r'C:\dir\num\two;C:\dir\num\three;C:\dir\num\two' , sep = ';' )
562
- assert p3 == r'C:\dir\num\two;C:\dir\num\three;C:\dir\num\one' , p3
548
+ # have to specify the pathsep when adding so it's cross-platform
549
+ # new duplicates existing - "moves to front"
550
+ with self .subTest ():
551
+ p1 : list | str = r'C:\dir\num\one;C:\dir\num\two'
552
+ p1 = PrependPath (p1 , r'C:\dir\num\two' , sep = ';' )
553
+ p1 = PrependPath (p1 , r'C:\dir\num\three' , sep = ';' )
554
+ self .assertEqual (p1 , r'C:\dir\num\three;C:\dir\num\two;C:\dir\num\one' )
555
+
556
+ # ... except with delete_existing false
557
+ with self .subTest ():
558
+ p2 : list | str = r'C:\dir\num\one;C:\dir\num\two'
559
+ p2 = PrependPath (p2 , r'C:\dir\num\two' , sep = ';' , delete_existing = False )
560
+ p2 = PrependPath (p2 , r'C:\dir\num\three' , sep = ';' , delete_existing = False )
561
+ self .assertEqual (p2 , r'C:\dir\num\three;C:\dir\num\one;C:\dir\num\two' )
562
+
563
+ # only last one is kept if there are dupes in new
564
+ with self .subTest ():
565
+ p3 : list | str = r'C:\dir\num\one'
566
+ p3 = PrependPath (p3 , r'C:\dir\num\two;C:\dir\num\three;C:\dir\num\two' , sep = ';' )
567
+ self .assertEqual (p3 , r'C:\dir\num\two;C:\dir\num\three;C:\dir\num\one' )
568
+
569
+ # try prepending a Dir Node
570
+ with self .subTest ():
571
+ p4 : list | str = r'C:\dir\num\one'
572
+ test = TestCmd .TestCmd (workdir = '' )
573
+ test .subdir ('sub' )
574
+ subdir = test .workpath ('sub' )
575
+ p4 = PrependPath (p4 , subdir , sep = ';' )
576
+ self .assertEqual (p4 , rf'{ subdir } ;C:\dir\num\one' )
577
+
578
+ # try with initial list, adding string (result stays a list)
579
+ with self .subTest ():
580
+ p5 : list = [r'C:\dir\num\one' , r'C:\dir\num\two' ]
581
+ p5 = PrependPath (p5 , r'C:\dir\num\two' , sep = ';' )
582
+ self .assertEqual (p5 , [r'C:\dir\num\two' , r'C:\dir\num\one' ])
583
+ p5 = PrependPath (p5 , r'C:\dir\num\three' , sep = ';' )
584
+ self .assertEqual (p5 , [r'C:\dir\num\three' , r'C:\dir\num\two' , r'C:\dir\num\one' ])
585
+
586
+ # try with initial string, adding list (result stays a string)
587
+ with self .subTest ():
588
+ p6 : list | str = r'C:\dir\num\one;C:\dir\num\two'
589
+ p6 = PrependPath (p6 , [r'C:\dir\num\two' , r'C:\dir\num\three' ], sep = ';' )
590
+ self .assertEqual (p6 , r'C:\dir\num\two;C:\dir\num\three;C:\dir\num\one' )
591
+
563
592
564
593
def test_AppendPath (self ) -> None :
565
594
"""Test appending to a path."""
566
- p1 : list | str = r'C:\dir\num\one;C:\dir\num\two'
567
- p2 : list | str = r'C:\mydir\num\one;C:\mydir\num\two'
568
- # have to include the pathsep here so that the test will work on UNIX too.
569
- p1 = AppendPath (p1 , r'C:\dir\num\two' , sep = ';' )
570
- p1 = AppendPath (p1 , r'C:\dir\num\three' , sep = ';' )
571
- assert p1 == r'C:\dir\num\one;C:\dir\num\two;C:\dir\num\three' , p1
572
-
573
- p2 = AppendPath (p2 , r'C:\mydir\num\three' , sep = ';' )
574
- p2 = AppendPath (p2 , r'C:\mydir\num\one' , sep = ';' )
575
- assert p2 == r'C:\mydir\num\two;C:\mydir\num\three;C:\mydir\num\one' , p2
576
-
577
- # check (only) last one is kept if there are dupes in new
578
- p3 : list | str = r'C:\dir\num\one'
579
- p3 = AppendPath (p3 , r'C:\dir\num\two;C:\dir\num\three;C:\dir\num\two' , sep = ';' )
580
- assert p3 == r'C:\dir\num\one;C:\dir\num\three;C:\dir\num\two' , p3
581
-
582
- def test_PrependPathPreserveOld (self ) -> None :
583
- """Test prepending to a path while preserving old paths"""
584
- p1 : list | str = r'C:\dir\num\one;C:\dir\num\two'
585
- # have to include the pathsep here so that the test will work on UNIX too.
586
- p1 = PrependPath (p1 , r'C:\dir\num\two' , sep = ';' , delete_existing = False )
587
- p1 = PrependPath (p1 , r'C:\dir\num\three' , sep = ';' )
588
- assert p1 == r'C:\dir\num\three;C:\dir\num\one;C:\dir\num\two' , p1
589
-
590
- def test_AppendPathPreserveOld (self ) -> None :
591
- """Test appending to a path while preserving old paths"""
592
- p1 : list | str = r'C:\dir\num\one;C:\dir\num\two'
593
- # have to include the pathsep here so that the test will work on UNIX too.
594
- p1 = AppendPath (p1 , r'C:\dir\num\one' , sep = ';' , delete_existing = False )
595
- p1 = AppendPath (p1 , r'C:\dir\num\three' , sep = ';' )
596
- assert p1 == r'C:\dir\num\one;C:\dir\num\two;C:\dir\num\three' , p1
595
+ # have to specify the pathsep when adding so it's cross-platform
596
+ # new duplicates existing - "moves to end"
597
+ with self .subTest ():
598
+ p1 : list | str = r'C:\dir\num\one;C:\dir\num\two'
599
+ p1 = AppendPath (p1 , r'C:\dir\num\two' , sep = ';' )
600
+ p1 = AppendPath (p1 , r'C:\dir\num\three' , sep = ';' )
601
+ self .assertEqual (p1 , r'C:\dir\num\one;C:\dir\num\two;C:\dir\num\three' )
602
+
603
+ # ... except with delete_existing false
604
+ with self .subTest ():
605
+ p2 : list | str = r'C:\dir\num\one;C:\dir\num\two'
606
+ p2 = AppendPath (p1 , r'C:\dir\num\one' , sep = ';' , delete_existing = False )
607
+ p2 = AppendPath (p1 , r'C:\dir\num\three' , sep = ';' )
608
+ self .assertEqual (p2 , r'C:\dir\num\one;C:\dir\num\two;C:\dir\num\three' )
609
+
610
+ # only last one is kept if there are dupes in new
611
+ with self .subTest ():
612
+ p3 : list | str = r'C:\dir\num\one'
613
+ p3 = AppendPath (p3 , r'C:\dir\num\two;C:\dir\num\three;C:\dir\num\two' , sep = ';' )
614
+ self .assertEqual (p3 , r'C:\dir\num\one;C:\dir\num\three;C:\dir\num\two' )
615
+
616
+ # try appending a Dir Node
617
+ with self .subTest ():
618
+ p4 : list | str = r'C:\dir\num\one'
619
+ test = TestCmd .TestCmd (workdir = '' )
620
+ test .subdir ('sub' )
621
+ subdir = test .workpath ('sub' )
622
+ p4 = AppendPath (p4 , subdir , sep = ';' )
623
+ self .assertEqual (p4 , rf'C:\dir\num\one;{ subdir } ' )
624
+
625
+ # try with initial list, adding string (result stays a list)
626
+ with self .subTest ():
627
+ p5 : list = [r'C:\dir\num\one' , r'C:\dir\num\two' ]
628
+ p5 = AppendPath (p5 , r'C:\dir\num\two' , sep = ';' )
629
+ p5 = AppendPath (p5 , r'C:\dir\num\three' , sep = ';' )
630
+ self .assertEqual (p5 , [r'C:\dir\num\one' , r'C:\dir\num\two' , r'C:\dir\num\three' ])
631
+
632
+ # try with initia string, adding list (result stays a string)
633
+ with self .subTest ():
634
+ p6 : list | str = r'C:\dir\num\one;C:\dir\num\two'
635
+ p6 = AppendPath (p6 , [r'C:\dir\num\two' , r'C:\dir\num\three' ], sep = ';' )
636
+ self .assertEqual (p6 , r'C:\dir\num\one;C:\dir\num\two;C:\dir\num\three' )
597
637
598
638
def test_addPathIfNotExists (self ) -> None :
599
639
"""Test the AddPathIfNotExists() function"""
0 commit comments