<s> from __future__ import unicode_literals <EOL> import os <EOL> import shutil <EOL> from django . core . files . base import ContentFile <EOL> from django . core . files . storage import FileSystemStorage <EOL> from django . test import TestCase <EOL> from pipeline import glob <EOL> def local_path ( path ) : <EOL> return os . path . join ( os . path . dirname ( __file__ ) , path ) <EOL> class GlobTest ( TestCase ) : <EOL> def normpath ( self , * parts ) : <EOL> return os . path . normpath ( os . path . join ( * parts ) ) <EOL> def mktemp ( self , * parts ) : <EOL> filename = self . normpath ( * parts ) <EOL> base , file = os . path . split ( filename ) <EOL> base = os . path . join ( self . storage . location , base ) <EOL> if not os . path . exists ( base ) : <EOL> os . makedirs ( base ) <EOL> self . storage . save ( filename , ContentFile ( "<STR_LIT>" ) ) <EOL> def assertSequenceEqual ( self , l1 , l2 ) : <EOL> self . assertEqual ( set ( l1 ) , set ( l2 ) ) <EOL> def setUp ( self ) : <EOL> self . storage = FileSystemStorage ( local_path ( '<STR_LIT>' ) ) <EOL> self . old_storage = glob . staticfiles_storage <EOL> glob . staticfiles_storage = self . storage <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> 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> return glob . glob ( pattern ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . storage . location ) <EOL> glob . staticfiles_storage = self . old_storage <EOL> def test_glob_literal ( self ) : <EOL> self . assertSequenceEqual ( self . glob ( '<STR_LIT:a>' ) , [ self . normpath ( '<STR_LIT:a>' ) ] ) <EOL> self . assertSequenceEqual ( self . glob ( '<STR_LIT:a>' , '<STR_LIT:D>' ) , [ self . normpath ( '<STR_LIT:a>' , '<STR_LIT:D>' ) ] ) <EOL> self . assertSequenceEqual ( self . glob ( '<STR_LIT>' ) , [ self . normpath ( '<STR_LIT>' ) ] ) <EOL> def test_glob_one_directory ( self ) : <EOL> self . assertSequenceEqual ( <EOL> self . glob ( '<STR_LIT>' ) , map ( self . normpath , [ '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> self . assertSequenceEqual ( <EOL> self . glob ( '<STR_LIT>' ) , map ( self . normpath , [ '<STR_LIT:a>' , '<STR_LIT>' ] ) ) <EOL> self . assertSequenceEqual ( <EOL> self . glob ( '<STR_LIT>' ) , map ( self . normpath , [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> self . assertSequenceEqual ( <EOL> self . glob ( '<STR_LIT>' ) , map ( self . normpath , [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> self . assertSequenceEqual ( self . glob ( '<STR_LIT>' ) , [ ] ) <EOL> def test_glob_nested_directory ( self ) : <EOL> if os . path . normcase ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> self . assertSequenceEqual ( <EOL> self . glob ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) , [ self . normpath ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> else : <EOL> self . assertSequenceEqual ( self . glob ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) , [ <EOL> self . normpath ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . normpath ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ] ) <EOL> self . assertSequenceEqual ( <EOL> self . glob ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) , [ self . normpath ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> def test_glob_directory_names ( self ) : <EOL> self . assertSequenceEqual ( <EOL> self . glob ( '<STR_LIT:*>' , '<STR_LIT:D>' ) , [ self . normpath ( '<STR_LIT:a>' , '<STR_LIT:D>' ) ] ) <EOL> self . assertSequenceEqual ( self . glob ( '<STR_LIT:*>' , '<STR_LIT>' ) , [ ] ) <EOL> self . assertSequenceEqual ( <EOL> self . glob ( '<STR_LIT:a>' , '<STR_LIT:*>' , '<STR_LIT:*>' , '<STR_LIT>' ) , <EOL> [ self . normpath ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> self . assertSequenceEqual ( <EOL> self . glob ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> map ( self . normpath , [ 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> paths = glob . glob ( '<STR_LIT:*>' + os . sep ) <EOL> self . assertEqual ( len ( paths ) , <NUM_LIT:4> ) <EOL> self . assertTrue ( all ( [ os . sep in path for path in paths ] ) ) </s>
