<s> """<STR_LIT>""" <EOL> import os <EOL> import shutil <EOL> import os . path <EOL> import sys <EOL> import unittest <EOL> import tempfile <EOL> from fnmatch import fnmatch <EOL> from openmdao . util . fileutil import find_in_path , build_directory , find_files , onerror <EOL> structure = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } <EOL> } <EOL> class FileUtilTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . startdir = os . getcwd ( ) <EOL> self . tempdir = tempfile . mkdtemp ( ) <EOL> os . chdir ( self . tempdir ) <EOL> build_directory ( structure ) <EOL> def tearDown ( self ) : <EOL> os . chdir ( self . startdir ) <EOL> shutil . rmtree ( self . tempdir , onerror = onerror ) <EOL> def test_find_in_path ( self ) : <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> path = r'<STR_LIT>' <EOL> else : <EOL> path = '<STR_LIT>' <EOL> fname = find_in_path ( '<STR_LIT:bar>' , path ) <EOL> self . assertEqual ( fname , None ) <EOL> fname = find_in_path ( '<STR_LIT>' , path , exts = ( '<STR_LIT>' , ) ) <EOL> self . assertTrue ( fname is not None ) <EOL> self . assertEqual ( os . path . basename ( fname ) , '<STR_LIT>' ) <EOL> fname = find_in_path ( '<STR_LIT>' , path ) <EOL> self . assertTrue ( fname is not None ) <EOL> self . assertEqual ( os . path . basename ( fname ) , '<STR_LIT>' ) <EOL> fname = find_in_path ( '<STR_LIT>' , path ) <EOL> self . assertEqual ( fname , None ) <EOL> def test_find_files ( self ) : <EOL> flist = find_files ( self . tempdir ) <EOL> self . assertEqual ( set ( [ os . path . basename ( f ) for f in flist ] ) , <EOL> set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> flist = find_files ( self . tempdir , '<STR_LIT>' ) <EOL> self . assertEqual ( set ( [ os . path . basename ( f ) for f in flist ] ) , <EOL> set ( [ '<STR_LIT>' ] ) ) <EOL> matcher = lambda name : fnmatch ( name , '<STR_LIT>' ) or name . startswith ( '<STR_LIT:_>' ) <EOL> flist = find_files ( self . tempdir , matcher ) <EOL> self . assertEqual ( set ( [ os . path . basename ( f ) for f in flist ] ) , <EOL> set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] ) ) <EOL> flist = find_files ( self . tempdir , exclude = '<STR_LIT>' ) <EOL> self . assertEqual ( set ( [ os . path . basename ( f ) for f in flist ] ) , <EOL> set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> flist = find_files ( self . tempdir , exclude = matcher ) <EOL> self . assertEqual ( set ( [ os . path . basename ( f ) for f in flist ] ) , <EOL> set ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> flist = find_files ( self . tempdir , match = '<STR_LIT>' , exclude = matcher ) <EOL> self . assertEqual ( set ( [ os . path . basename ( f ) for f in flist ] ) , <EOL> set ( [ ] ) ) <EOL> flist = find_files ( self . tempdir , direxclude = '<STR_LIT>' ) <EOL> self . assertEqual ( set ( [ os . path . basename ( f ) for f in flist ] ) , <EOL> set ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
