<s> import unittest <EOL> from test . test_support import run_unittest , TESTFN <EOL> import glob <EOL> import os <EOL> import shutil <EOL> class GlobTests ( unittest . TestCase ) : <EOL> def norm ( self , * parts ) : <EOL> return os . path . normpath ( os . path . join ( self . tempdir , * parts ) ) <EOL> def mktemp ( self , * parts ) : <EOL> filename = self . norm ( * parts ) <EOL> base , file = os . path . split ( filename ) <EOL> if not os . path . exists ( base ) : <EOL> os . makedirs ( base ) <EOL> f = open ( filename , '<STR_LIT:w>' ) <EOL> f . close ( ) <EOL> def setUp ( self ) : <EOL> self . tempdir = TESTFN + "<STR_LIT>" <EOL> self . mktemp ( '<STR_LIT:a>' , '<STR_LIT:D>' ) <EOL> self . mktemp ( '<STR_LIT>' , '<STR_LIT:F>' ) <EOL> self . mktemp ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . mktemp ( '<STR_LIT>' ) <EOL> self . mktemp ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . mktemp ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> os . symlink ( self . norm ( '<STR_LIT>' ) , self . norm ( '<STR_LIT>' ) ) <EOL> os . symlink ( self . norm ( '<STR_LIT>' ) , self . norm ( '<STR_LIT>' ) ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . tempdir ) <EOL> def glob ( self , * parts ) : <EOL> if len ( parts ) == <NUM_LIT:1> : <EOL> pattern = parts [ <NUM_LIT:0> ] <EOL> else : <EOL> pattern = os . path . join ( * parts ) <EOL> p = os . path . join ( self . tempdir , pattern ) <EOL> res = glob . glob ( p ) <EOL> self . assertEqual ( list ( glob . iglob ( p ) ) , res ) <EOL> return res <EOL> def assertSequencesEqual_noorder ( self , l1 , l2 ) : <EOL> self . assertEqual ( set ( l1 ) , set ( l2 ) ) <EOL> def test_glob_literal ( self ) : <EOL> eq = self . assertSequencesEqual_noorder <EOL> eq ( self . glob ( '<STR_LIT:a>' ) , [ self . norm ( '<STR_LIT:a>' ) ] ) <EOL> eq ( self . glob ( '<STR_LIT:a>' , '<STR_LIT:D>' ) , [ self . norm ( '<STR_LIT:a>' , '<STR_LIT:D>' ) ] ) <EOL> eq ( self . glob ( '<STR_LIT>' ) , [ self . norm ( '<STR_LIT>' ) ] ) <EOL> eq ( self . glob ( '<STR_LIT>' ) , [ ] ) <EOL> def test_glob_one_directory ( self ) : <EOL> eq = self . assertSequencesEqual_noorder <EOL> eq ( self . glob ( '<STR_LIT>' ) , map ( self . norm , [ '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> eq ( self . glob ( '<STR_LIT>' ) , map ( self . norm , [ '<STR_LIT:a>' , '<STR_LIT>' ] ) ) <EOL> eq ( self . glob ( '<STR_LIT>' ) , map ( self . norm , [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> eq ( self . glob ( '<STR_LIT>' ) , map ( self . norm , [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> eq ( self . glob ( '<STR_LIT>' ) , [ ] ) <EOL> def test_glob_nested_directory ( self ) : <EOL> eq = self . assertSequencesEqual_noorder <EOL> if os . path . normcase ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> eq ( self . glob ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) , [ self . norm ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> else : <EOL> eq ( self . glob ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) , [ self . norm ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . norm ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> eq ( self . glob ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) , [ self . norm ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> def test_glob_directory_names ( self ) : <EOL> eq = self . assertSequencesEqual_noorder <EOL> eq ( self . glob ( '<STR_LIT:*>' , '<STR_LIT:D>' ) , [ self . norm ( '<STR_LIT:a>' , '<STR_LIT:D>' ) ] ) <EOL> eq ( self . glob ( '<STR_LIT:*>' , '<STR_LIT>' ) , [ ] ) <EOL> eq ( self . glob ( '<STR_LIT:a>' , '<STR_LIT:*>' , '<STR_LIT:*>' , '<STR_LIT>' ) , <EOL> [ self . norm ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> eq ( self . glob ( '<STR_LIT>' , '<STR_LIT>' ) , map ( self . norm , [ os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> os . path . join ( '<STR_LIT>' , '<STR_LIT:F>' ) ] ) ) <EOL> def test_glob_directory_with_trailing_slash ( self ) : <EOL> res = glob . glob ( self . tempdir + '<STR_LIT:*>' + os . sep ) <EOL> self . assertEqual ( len ( res ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( res [ <NUM_LIT:0> ] in [ self . tempdir , self . tempdir + os . sep ] ) <EOL> def test_glob_broken_symlinks ( self ) : <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> eq = self . assertSequencesEqual_noorder <EOL> eq ( self . glob ( '<STR_LIT>' ) , [ self . norm ( '<STR_LIT>' ) , self . norm ( '<STR_LIT>' ) ] ) <EOL> eq ( self . glob ( '<STR_LIT>' ) , [ self . norm ( '<STR_LIT>' ) ] ) <EOL> eq ( self . glob ( '<STR_LIT>' ) , [ self . norm ( '<STR_LIT>' ) ] ) <EOL> def test_main ( ) : <EOL> run_unittest ( GlobTests ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
