def test_invalidSymlink(self): '''Test that invalid symlinks get cleaned up''' thisTempFolder = tempFolderManager() # invalid link os.symlink('thisFileShouldNotExist', os.path.join(thisTempFolder.getPath(), 'validLink')) thisTempFolder.cleanup()
def test_getPath(self): managedItem = tempFolderManager() self.assertTrue( managedItem.getPath() is not None, 'On a simple tempFolderManager item getPath is returning None') self.assertTrue( managedItem.getPath().startswith( tempFolderManager.getDefaultFolder()), 'The simple tempFolderManager items reply to getPath did not start with the default folder, but rather was: ' + managedItem.getPath())
def test_validSymlink(self): '''Test that valid symlinks get cleared up''' thisTempFolder = tempFolderManager() # create a file to link to open(os.path.join(thisTempFolder.getPath(), 'testFile'), 'w').close() # valid link os.symlink('testFile', os.path.join(thisTempFolder.getPath(), 'validLink')) thisTempFolder.cleanup()
def test_withStatementFunction(self): '''Test the use of items with the "with" statement''' location = None with tempFolderManager() as thisTempFolder: self.assertTrue(isinstance(thisTempFolder, tempFolderManager), 'While using a with statement a tempFolderManager item was not created correctly') location = thisTempFolder.getPath() self.assertTrue(location is not None, 'When using a with statement getPath method returned None') self.assertTrue(os.path.isdir(location), 'When using a with statement getPath method returned a path that was not an existing directory') self.assertTrue(tempFolderManager.getManagedPathForPath(location) is not None, 'When using a with statement getPath returned a path that was not in a managed item') # create some contents to make it interesting generateSomeContent(location) # outside the with statement the item should have auto-cleaned iteself self.assertFalse(os.path.exists(location), 'After exiting a with statement the item was not properly cleaned up') # repeat the same exercise with a preset location location = tempfile.mkdtemp(dir='/tmp') with tempFolderManager(location) as thisTempFolder: self.assertTrue(isinstance(thisTempFolder, tempFolderManager), 'While using a with statement and a preset location a tempFolderManager item was not created correctly') returnedLocation = thisTempFolder.getPath() self.assertTrue(returnedLocation is not None, 'When using a with statement and a preset location getPath method returned None') self.assertTrue(os.path.samefile(returnedLocation, location), 'When using a with statement and a preset location getPath did not return the expected location: "%s" vs. "%s"' % (location, returnedLocation)) self.assertTrue(os.path.isdir(location), 'When using a with statement and a preset location getPath method returned a path that was not an existing directory') self.assertTrue(tempFolderManager.getManagedPathForPath(location) is not None, 'When using a with statement and a preset location getPath returned a path that was not in a managed item') # create some contents to make it interesting generateSomeContent(location) # outside the with statement the item should have auto-cleaned iteself self.assertFalse(os.path.exists(location), 'After exiting a with statement the item was not properly cleaned up')
def test_withStatementFunction(self): '''Test the use of items with the "with" statement''' location = None with tempFolderManager() as thisTempFolder: self.assertTrue( isinstance(thisTempFolder, tempFolderManager), 'While using a with statement a tempFolderManager item was not created correctly' ) location = thisTempFolder.getPath() self.assertTrue( location is not None, 'When using a with statement getPath method returned None') self.assertTrue( os.path.isdir(location), 'When using a with statement getPath method returned a path that was not an existing directory' ) self.assertTrue( tempFolderManager.getManagedPathForPath(location) is not None, 'When using a with statement getPath returned a path that was not in a managed item' ) # create some contents to make it interesting generateSomeContent(location) # outside the with statement the item should have auto-cleaned iteself self.assertFalse( os.path.exists(location), 'After exiting a with statement the item was not properly cleaned up' ) # repeat the same exercise with a preset location location = tempfile.mkdtemp(dir='/tmp') with tempFolderManager(location) as thisTempFolder: self.assertTrue( isinstance(thisTempFolder, tempFolderManager), 'While using a with statement and a preset location a tempFolderManager item was not created correctly' ) returnedLocation = thisTempFolder.getPath() self.assertTrue( returnedLocation is not None, 'When using a with statement and a preset location getPath method returned None' ) self.assertTrue( os.path.samefile(returnedLocation, location), 'When using a with statement and a preset location getPath did not return the expected location: "%s" vs. "%s"' % (location, returnedLocation)) self.assertTrue( os.path.isdir(location), 'When using a with statement and a preset location getPath method returned a path that was not an existing directory' ) self.assertTrue( tempFolderManager.getManagedPathForPath(location) is not None, 'When using a with statement and a preset location getPath returned a path that was not in a managed item' ) # create some contents to make it interesting generateSomeContent(location) # outside the with statement the item should have auto-cleaned iteself self.assertFalse( os.path.exists(location), 'After exiting a with statement the item was not properly cleaned up' )
def test_getPath(self): managedItem = tempFolderManager() self.assertTrue(managedItem.getPath() is not None, 'On a simple tempFolderManager item getPath is returning None') self.assertTrue(managedItem.getPath().startswith(tempFolderManager.getDefaultFolder()), 'The simple tempFolderManager items reply to getPath did not start with the default folder, but rather was: ' + managedItem.getPath())