@@ -522,7 +522,42 @@ def test_mixed_namespace(self):
522
522
del sys .modules ['foo.bar' ]
523
523
del sys .modules ['foo.baz' ]
524
524
525
- # XXX: test .pkg files
525
+
526
+ def test_extend_path_argument_types (self ):
527
+ pkgname = 'foo'
528
+ dirname_0 = self .create_init (pkgname )
529
+
530
+ # If the input path is not a list it is returned unchanged
531
+ self .assertEqual ('notalist' , pkgutil .extend_path ('notalist' , 'foo' ))
532
+ self .assertEqual (('not' , 'a' , 'list' ), pkgutil .extend_path (('not' , 'a' , 'list' ), 'foo' ))
533
+ self .assertEqual (123 , pkgutil .extend_path (123 , 'foo' ))
534
+ self .assertEqual (None , pkgutil .extend_path (None , 'foo' ))
535
+
536
+ # Cleanup
537
+ shutil .rmtree (dirname_0 )
538
+
539
+
540
+ def test_extend_path_pkg_files (self ):
541
+ pkgname = 'foo'
542
+ dirname_0 = self .create_init (pkgname )
543
+
544
+ with open (os .path .join (dirname_0 , 'bar.pkg' ), 'w' ) as pkg_file :
545
+ pkg_file .write ('\n ' .join ([
546
+ 'baz' ,
547
+ '/foo/bar/baz' ,
548
+ '' ,
549
+ '#comment'
550
+ ]))
551
+
552
+ # A *.pkg file is trusted at face value. Apart from checking for duplicates, all entries found in a *.pkg
553
+ # file are added as-is to the resulting paths, regardless of whether they exist on the filesystem.
554
+ extended_paths = pkgutil .extend_path (sys .path , 'bar' )
555
+
556
+ self .assertEqual (extended_paths [- 2 ], 'baz' )
557
+ self .assertEqual (extended_paths [- 1 ], '/foo/bar/baz' )
558
+
559
+ # Cleanup
560
+ shutil .rmtree (dirname_0 )
526
561
527
562
528
563
class NestedNamespacePackageTest (unittest .TestCase ):
0 commit comments