<s> """<STR_LIT>""" <EOL> import os <EOL> import shutil <EOL> import tempfile <EOL> import unittest <EOL> import mock <EOL> from perfkitbenchmarker import data <EOL> class FileResourceLoaderTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . temp_dir = tempfile . mkdtemp ( prefix = '<STR_LIT>' ) <EOL> self . instance = data . FileResourceLoader ( self . temp_dir ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . temp_dir ) <EOL> def _Create ( self , file_name , content = '<STR_LIT>' ) : <EOL> file_path = os . path . join ( self . temp_dir , file_name ) <EOL> with open ( file_path , '<STR_LIT:w>' ) as fp : <EOL> fp . write ( content ) <EOL> return file_path <EOL> def testResourcePath_NonExistantResource ( self ) : <EOL> self . assertListEqual ( [ ] , os . listdir ( self . temp_dir ) ) <EOL> self . assertRaises ( data . ResourceNotFound , <EOL> self . instance . ResourcePath , <EOL> '<STR_LIT>' ) <EOL> def testResourcePath_ExtantResource ( self ) : <EOL> file_name = '<STR_LIT>' <EOL> file_path = self . _Create ( file_name ) <EOL> self . assertEqual ( file_path , self . instance . ResourcePath ( file_name ) ) <EOL> def testResourceExists_NonExistantResource ( self ) : <EOL> self . assertFalse ( self . instance . ResourceExists ( '<STR_LIT>' ) ) <EOL> def testResourceExists_ExtantResource ( self ) : <EOL> file_name = '<STR_LIT>' <EOL> self . _Create ( file_name ) <EOL> self . assertTrue ( self . instance . ResourceExists ( file_name ) ) <EOL> class PackageResourceLoaderTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . instance = data . PackageResourceLoader ( data . __name__ ) <EOL> def testResourcePath_NonExistantResource ( self ) : <EOL> self . assertRaises ( data . ResourceNotFound , <EOL> self . instance . ResourcePath , <EOL> '<STR_LIT>' ) <EOL> def testResourcePath_ExtantResource ( self ) : <EOL> file_name = '<STR_LIT>' <EOL> path = self . instance . ResourcePath ( file_name ) <EOL> self . assertEqual ( file_name , os . path . basename ( path ) ) <EOL> self . assertTrue ( os . path . exists ( path ) ) <EOL> def testResourceExists_NonExistantResource ( self ) : <EOL> self . assertFalse ( self . instance . ResourceExists ( '<STR_LIT>' ) ) <EOL> def testResourceExists_ExtantResource ( self ) : <EOL> file_name = '<STR_LIT>' <EOL> self . assertTrue ( self . instance . ResourceExists ( file_name ) ) <EOL> class ResourcePathTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> mock_found_loader = mock . MagicMock ( spec = data . ResourceLoader ) <EOL> mock_found_loader . ResourceExists . return_value = True <EOL> mock_found_loader . ResourcePath . return_value = '<STR_LIT>' <EOL> mock_not_found_loader = mock . MagicMock ( spec = data . ResourceLoader ) <EOL> mock_not_found_loader . ResourceExists . return_value = False <EOL> p = mock . patch ( data . __name__ + '<STR_LIT>' , <EOL> return_value = [ mock_found_loader ] ) <EOL> self . mock_get_resource_loaders = p . start ( ) <EOL> self . addCleanup ( p . stop ) <EOL> p = mock . patch ( data . __name__ + '<STR_LIT>' , <EOL> [ mock_not_found_loader ] ) <EOL> p . start ( ) <EOL> self . addCleanup ( p . stop ) <EOL> def testSearchUserPaths ( self ) : <EOL> r = data . ResourcePath ( '<STR_LIT>' , True ) <EOL> self . assertEqual ( '<STR_LIT>' , r ) <EOL> def testDoNotSearchUserPaths ( self ) : <EOL> with self . assertRaises ( data . ResourceNotFound ) : <EOL> data . ResourcePath ( '<STR_LIT>' , False ) </s>
