@@ -522,7 +522,45 @@ def test_mixed_namespace(self):
522522 del sys .modules ['foo.bar' ]
523523 del sys .modules ['foo.baz' ]
524524
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+ del sys .path [0 ]
539+
540+
541+ def test_extend_path_pkg_files (self ):
542+ pkgname = 'foo'
543+ dirname_0 = self .create_init (pkgname )
544+
545+ with open (os .path .join (dirname_0 , 'bar.pkg' ), 'w' ) as pkg_file :
546+ pkg_file .write ('\n ' .join ([
547+ 'baz' ,
548+ '/foo/bar/baz' ,
549+ '' ,
550+ '#comment'
551+ ]))
552+
553+ # A *.pkg file is trusted at face value. Apart from checking for duplicates, all entries found in a *.pkg
554+ # file are added as-is to the resulting paths, regardless of whether they exist on the filesystem.
555+ extended_paths = pkgutil .extend_path (sys .path , 'bar' )
556+
557+ self .assertEqual (extended_paths [:- 2 ], sys .path )
558+ self .assertEqual (extended_paths [- 2 ], 'baz' )
559+ self .assertEqual (extended_paths [- 1 ], '/foo/bar/baz' )
560+
561+ # Cleanup
562+ shutil .rmtree (dirname_0 )
563+ del sys .path [0 ]
526564
527565
528566class NestedNamespacePackageTest (unittest .TestCase ):
0 commit comments