def test_plainFiles(self):
		'''Test that a random file will be deleted'''
		
		(fileHandle, filePath) = tempfile.mkstemp()
		os.close(fileHandle) # we don't need to write anything to this
		filePath = pathHelpers.normalizePath(filePath, followSymlink=True)
		
		# add it, and confirm that this is managed
		tempFolderManager.addManagedItem(filePath)
		self.assertTrue(filePath in tempFolderManager.managedItems, 'Adding a file using addManagedItem did not result in it being put in managedItems')
		self.assertTrue(tempFolderManager.getManagedPathForPath(filePath) is not None, 'Adding a file using addManagedItem did not make it managed (according to getManagedPathForPath)')
		
		# wipe this out using cleanupItem
		tempFolderManager.cleanupItem(filePath)
		self.assertFalse(os.path.exists(filePath), 'Removing a file added with addManagedItem with cleanupItem did not get rid of the file')
		
		# repeat the exercise for cleanupForExit
		(fileHandle, filePath) = tempfile.mkstemp()
		os.close(fileHandle) # we don't need to write anything to this
		filePath = pathHelpers.normalizePath(filePath, followSymlink=True)
		
		# add it, and confirm that this is managed
		tempFolderManager.addManagedItem(filePath)
		self.assertTrue(filePath in tempFolderManager.managedItems, 'Adding a file using addManagedItem did not result in it being put in managedItems')
		self.assertTrue(tempFolderManager.getManagedPathForPath(filePath) is not None, 'Adding a file using addManagedItem did not make it managed (according to getManagedPathForPath)')
		
		# wipe this out using cleanupItem
		tempFolderManager.cleanupForExit()
		self.assertFalse(os.path.exists(filePath), 'Removing a file added with addManagedItem with cleanupForExit did not get rid of the file')
示例#2
0
	def test_singleSourceSetup(self):
		'''Test setting up a single source folder'''
		
		# setup the cache folder so that we can do tests
		cacheFolderPath = tempFolderManager.getNewTempFolder()
		cacheController.setCacheFolder(cacheFolderPath)
		
		sourceFolderPath = tempFolderManager.getNewTempFolder()
		
		# sanity check that it was not already somehow the source folders already
		self.assertFalse(sourceFolderPath in cacheController.sourceFolders, 'The new sourceFolder was found in the sourceFodlers variable too soon')
		self.assertNotEqual(sourceFolderPath, cacheController.writeableCacheFolder, 'The new sourceFolder should not be the selected cache folder')
		
		# check that adding the source folder results in it being actually added
		cacheController.addSourceFolders(sourceFolderPath)
		self.assertTrue(sourceFolderPath in cacheController.sourceFolders, 'After being added with addSourceFolders the test source path was not in the sourceFolders vaiable')
		self.assertTrue(sourceFolderPath in cacheController.getSourceFolders(), 'After being added with addSourceFolders the test source path was not in the getSourceFolders output')
		
		# check that this has not affected the cache folder setting
		self.assertEqual(cacheFolderPath, cacheController.getCacheFolder(), 'After adding a source folder the cache folder should not change')
		
		# remove the source folder, and check to make sure it is removed
		cacheController.removeSourceFolders(sourceFolderPath)
		self.assertFalse(sourceFolderPath in cacheController.sourceFolders, 'After calling removeSourceFolder the source folder was still in the sourceFolders list')
		
		# cleanup
		cacheController.removeCacheFolder()
		cacheController.removeSourceFolders(cacheFolderPath)
		tempFolderManager.cleanupItem(cacheFolderPath)
		tempFolderManager.cleanupItem(sourceFolderPath)
示例#3
0
    def tearDown(self):
        # clean up
        outputFilePath = self.outputFile.name
        self.outputFile.close()
        self.outputFile = None

        tempFolderManager.cleanupItem(outputFilePath)

        self.outputHandler = None
示例#4
0
	def tearDown(self):
		# clean up
		outputFilePath = self.outputFile.name
		self.outputFile.close()
		self.outputFile = None
		
		tempFolderManager.cleanupItem(outputFilePath)
		
		self.outputHandler = None
示例#5
0
	def test_multipleSourceSetup(self):
		'''Test setting up multiple source folders'''
		
		# setup the cache folder so that we can do tests
		cacheFolderPath = tempFolderManager.getNewTempFolder()
		cacheController.setCacheFolder(cacheFolderPath)
		
		firstSourceFolderPath	= tempFolderManager.getNewTempFolder()
		secondSourceFolderPath	= tempFolderManager.getNewTempFolder()
		thirdSourceFolderPath	= tempFolderManager.getNewTempFolder()
		
		# add the first two items and confirm they are there
		cacheController.addSourceFolders([firstSourceFolderPath, secondSourceFolderPath])
		
		self.assertTrue(firstSourceFolderPath in cacheController.sourceFolders, 'After being added with addSourceFolders the first test source path was not in the sourceFolders vaiable')
		self.assertTrue(firstSourceFolderPath in cacheController.getSourceFolders(), 'After being added with addSourceFolders the first test source path was not in the getSourceFolders output')
		
		self.assertTrue(secondSourceFolderPath in cacheController.sourceFolders, 'After being added with addSourceFolders the second test source path was not in the sourceFolders vaiable')
		self.assertTrue(secondSourceFolderPath in cacheController.getSourceFolders(), 'After being added with addSourceFolders the second test source path was not in the getSourceFolders output')
		
		# add the third item, verifying that all three are there
		cacheController.addSourceFolders(thirdSourceFolderPath)
		
		self.assertTrue(firstSourceFolderPath in cacheController.sourceFolders, 'After adding the third source item with addSourceFolders the first test source path was not in the sourceFolders vaiable')
		self.assertTrue(firstSourceFolderPath in cacheController.getSourceFolders(), 'After adding the third source item with addSourceFolders the first test source path was not in the getSourceFolders output')
		
		self.assertTrue(secondSourceFolderPath in cacheController.sourceFolders, 'After adding the third source item with addSourceFolders the second test source path was not in the sourceFolders vaiable')
		self.assertTrue(secondSourceFolderPath in cacheController.getSourceFolders(), 'After adding the third source item with addSourceFolders the second test source path was not in the getSourceFolders output')
		
		self.assertTrue(thirdSourceFolderPath in cacheController.sourceFolders, 'After adding the third source item with addSourceFolders the third test source path was not in the sourceFolders vaiable')
		self.assertTrue(thirdSourceFolderPath in cacheController.getSourceFolders(), 'After adding the third source item with addSourceFolders the third test source path was not in the getSourceFolders output')
		
		# remove the second item, and verify that it is removed, and the other two still there
		cacheController.removeSourceFolders(secondSourceFolderPath)
		
		self.assertFalse(secondSourceFolderPath in cacheController.sourceFolders, 'After removing the second source item with removeSourceFolders the second test source path was still in the sourceFolders vaiable')
		self.assertFalse(secondSourceFolderPath in cacheController.getSourceFolders(), 'After removing the second source item with removeSourceFolders the second test source path was still in the getSourceFolders output')
				
		self.assertTrue(firstSourceFolderPath in cacheController.sourceFolders, 'After removing the second source item with removeSourceFolders the first test source path was not in the sourceFolders vaiable')
		self.assertTrue(firstSourceFolderPath in cacheController.getSourceFolders(), 'After removing the second source item with removeSourceFolders the first test source path was not in the getSourceFolders output')
		
		self.assertTrue(thirdSourceFolderPath in cacheController.sourceFolders, 'After removing the second source item with removeSourceFolders the third test source path was not in the sourceFolders vaiable')
		self.assertTrue(thirdSourceFolderPath in cacheController.getSourceFolders(), 'After removing the second source item with removeSourceFolders the third test source path was not in the getSourceFolders output')
		
		# remove the two remaining items and verify that they are gone
		cacheController.removeSourceFolders([firstSourceFolderPath, thirdSourceFolderPath])
		
		self.assertFalse(firstSourceFolderPath in cacheController.sourceFolders, 'After removing the first and third source item with removeSourceFolders the first test source path was still in the sourceFolders vaiable')
		self.assertFalse(secondSourceFolderPath in cacheController.sourceFolders, 'After removing the first and third source item with removeSourceFolders the second test source path was still in the sourceFolders vaiable')
		self.assertFalse(thirdSourceFolderPath in cacheController.sourceFolders, 'After removing the first and third source item with removeSourceFolders the third test source path was still in the sourceFolders vaiable')
		
		# cleanup
		cacheController.removeCacheFolder()
		cacheController.removeSourceFolders(cacheFolderPath)
		tempFolderManager.cleanupItem(cacheFolderPath)
		
		tempFolderManager.cleanupItem(firstSourceFolderPath)
		tempFolderManager.cleanupItem(secondSourceFolderPath)
		tempFolderManager.cleanupItem(thirdSourceFolderPath)
	def test_noPermissions(self):
		'''Items should be cleaned up, even if their permissions don't allow it'''
		
		# create and test an unwriteable folder
		unwriteableFolder = tempFolderManager.getNewTempFolder()
		os.chmod(unwriteableFolder, 0)
		tempFolderManager.cleanupItem(unwriteableFolder)
		self.assertFalse(os.path.exists(unwriteableFolder), 'After cleanupForExit the unwriteable folder should have been cleaned away')
		
		# create and test an unwriteable file
		testFolder = tempFolderManager.getNewTempFolder()
		open(os.path.join(testFolder, 'unwriteableFile'), 'w').close()
		os.chmod(os.path.join(testFolder, 'unwriteableFile'), 0)
		tempFolderManager.cleanupItem(testFolder)
		self.assertFalse(os.path.exists(os.path.join(testFolder, 'unwriteableFile')), 'After cleanupForExit the unwriteable file should have been cleaned away')
示例#7
0
    def test_plainFiles(self):
        '''Test that a random file will be deleted'''

        (fileHandle, filePath) = tempfile.mkstemp()
        os.close(fileHandle)  # we don't need to write anything to this
        filePath = pathHelpers.normalizePath(filePath, followSymlink=True)

        # add it, and confirm that this is managed
        tempFolderManager.addManagedItem(filePath)
        self.assertTrue(
            filePath in tempFolderManager.managedItems,
            'Adding a file using addManagedItem did not result in it being put in managedItems'
        )
        self.assertTrue(
            tempFolderManager.getManagedPathForPath(filePath) is not None,
            'Adding a file using addManagedItem did not make it managed (according to getManagedPathForPath)'
        )

        # wipe this out using cleanupItem
        tempFolderManager.cleanupItem(filePath)
        self.assertFalse(
            os.path.exists(filePath),
            'Removing a file added with addManagedItem with cleanupItem did not get rid of the file'
        )

        # repeat the exercise for cleanupForExit
        (fileHandle, filePath) = tempfile.mkstemp()
        os.close(fileHandle)  # we don't need to write anything to this
        filePath = pathHelpers.normalizePath(filePath, followSymlink=True)

        # add it, and confirm that this is managed
        tempFolderManager.addManagedItem(filePath)
        self.assertTrue(
            filePath in tempFolderManager.managedItems,
            'Adding a file using addManagedItem did not result in it being put in managedItems'
        )
        self.assertTrue(
            tempFolderManager.getManagedPathForPath(filePath) is not None,
            'Adding a file using addManagedItem did not make it managed (according to getManagedPathForPath)'
        )

        # wipe this out using cleanupItem
        tempFolderManager.cleanupForExit()
        self.assertFalse(
            os.path.exists(filePath),
            'Removing a file added with addManagedItem with cleanupForExit did not get rid of the file'
        )
示例#8
0
    def test_singleSourceSetup(self):
        '''Test setting up a single source folder'''

        # setup the cache folder so that we can do tests
        cacheFolderPath = tempFolderManager.getNewTempFolder()
        cacheController.setCacheFolder(cacheFolderPath)

        sourceFolderPath = tempFolderManager.getNewTempFolder()

        # sanity check that it was not already somehow the source folders already
        self.assertFalse(
            sourceFolderPath in cacheController.sourceFolders,
            'The new sourceFolder was found in the sourceFodlers variable too soon'
        )
        self.assertNotEqual(
            sourceFolderPath, cacheController.writeableCacheFolder,
            'The new sourceFolder should not be the selected cache folder')

        # check that adding the source folder results in it being actually added
        cacheController.addSourceFolders(sourceFolderPath)
        self.assertTrue(
            sourceFolderPath in cacheController.sourceFolders,
            'After being added with addSourceFolders the test source path was not in the sourceFolders vaiable'
        )
        self.assertTrue(
            sourceFolderPath in cacheController.getSourceFolders(),
            'After being added with addSourceFolders the test source path was not in the getSourceFolders output'
        )

        # check that this has not affected the cache folder setting
        self.assertEqual(
            cacheFolderPath, cacheController.getCacheFolder(),
            'After adding a source folder the cache folder should not change')

        # remove the source folder, and check to make sure it is removed
        cacheController.removeSourceFolders(sourceFolderPath)
        self.assertFalse(
            sourceFolderPath in cacheController.sourceFolders,
            'After calling removeSourceFolder the source folder was still in the sourceFolders list'
        )

        # cleanup
        cacheController.removeCacheFolder()
        cacheController.removeSourceFolders(cacheFolderPath)
        tempFolderManager.cleanupItem(cacheFolderPath)
        tempFolderManager.cleanupItem(sourceFolderPath)
示例#9
0
    def test_noPermissions(self):
        '''Items should be cleaned up, even if their permissions don't allow it'''

        # create and test an unwriteable folder
        unwriteableFolder = tempFolderManager.getNewTempFolder()
        os.chmod(unwriteableFolder, 0)
        tempFolderManager.cleanupItem(unwriteableFolder)
        self.assertFalse(
            os.path.exists(unwriteableFolder),
            'After cleanupForExit the unwriteable folder should have been cleaned away'
        )

        # create and test an unwriteable file
        testFolder = tempFolderManager.getNewTempFolder()
        open(os.path.join(testFolder, 'unwriteableFile'), 'w').close()
        os.chmod(os.path.join(testFolder, 'unwriteableFile'), 0)
        tempFolderManager.cleanupItem(testFolder)
        self.assertFalse(
            os.path.exists(os.path.join(testFolder, 'unwriteableFile')),
            'After cleanupForExit the unwriteable file should have been cleaned away'
        )
示例#10
0
    def tearDown(self):
        '''Clean up the items we created for tests'''

        # cache folder
        if cacheController.writeableCacheFolder == self.cacheFolderPath:
            cacheController.removeCacheFolder()
        tempFolderManager.cleanupItem(self.cacheFolderPath)

        # source folders
        if self.firstSourceFolderPath in cacheController.sourceFolders:
            cacheController.removeSourceFolders(self.firstSourceFolderPath)
        tempFolderManager.cleanupItem(self.firstSourceFolderPath)
        if self.secondSourceFolderPath in cacheController.sourceFolders:
            cacheController.removeSourceFolders(self.secondSourceFolderPath)
        tempFolderManager.cleanupItem(self.secondSourceFolderPath)

        # verified files
        cacheController.verifiedFiles = {}

        self.cacheFolderPath = None
        self.firstSourceFolderPath = None
        self.secondSourceFolderPath = None

        self.testMaterials = None

        tempFolderManager.cleanupForExit()
示例#11
0
	def tearDown(self):
		'''Clean up the items we created for tests'''
		
		# cache folder
		if cacheController.writeableCacheFolder == self.cacheFolderPath:
			cacheController.removeCacheFolder()
		tempFolderManager.cleanupItem(self.cacheFolderPath)
		
		# source folders
		if self.firstSourceFolderPath in cacheController.sourceFolders:
			cacheController.removeSourceFolders(self.firstSourceFolderPath)
		tempFolderManager.cleanupItem(self.firstSourceFolderPath)
		if self.secondSourceFolderPath in cacheController.sourceFolders:
			cacheController.removeSourceFolders(self.secondSourceFolderPath)
		tempFolderManager.cleanupItem(self.secondSourceFolderPath)
		
		# verified files
		cacheController.verifiedFiles = {}
		
		self.cacheFolderPath = None
		self.firstSourceFolderPath = None
		self.secondSourceFolderPath = None
		
		self.testMaterials = None
		
		tempFolderManager.cleanupForExit()
示例#12
0
    def test_multipleSourceSetup(self):
        '''Test setting up multiple source folders'''

        # setup the cache folder so that we can do tests
        cacheFolderPath = tempFolderManager.getNewTempFolder()
        cacheController.setCacheFolder(cacheFolderPath)

        firstSourceFolderPath = tempFolderManager.getNewTempFolder()
        secondSourceFolderPath = tempFolderManager.getNewTempFolder()
        thirdSourceFolderPath = tempFolderManager.getNewTempFolder()

        # add the first two items and confirm they are there
        cacheController.addSourceFolders(
            [firstSourceFolderPath, secondSourceFolderPath])

        self.assertTrue(
            firstSourceFolderPath in cacheController.sourceFolders,
            'After being added with addSourceFolders the first test source path was not in the sourceFolders vaiable'
        )
        self.assertTrue(
            firstSourceFolderPath in cacheController.getSourceFolders(),
            'After being added with addSourceFolders the first test source path was not in the getSourceFolders output'
        )

        self.assertTrue(
            secondSourceFolderPath in cacheController.sourceFolders,
            'After being added with addSourceFolders the second test source path was not in the sourceFolders vaiable'
        )
        self.assertTrue(
            secondSourceFolderPath in cacheController.getSourceFolders(),
            'After being added with addSourceFolders the second test source path was not in the getSourceFolders output'
        )

        # add the third item, verifying that all three are there
        cacheController.addSourceFolders(thirdSourceFolderPath)

        self.assertTrue(
            firstSourceFolderPath in cacheController.sourceFolders,
            'After adding the third source item with addSourceFolders the first test source path was not in the sourceFolders vaiable'
        )
        self.assertTrue(
            firstSourceFolderPath in cacheController.getSourceFolders(),
            'After adding the third source item with addSourceFolders the first test source path was not in the getSourceFolders output'
        )

        self.assertTrue(
            secondSourceFolderPath in cacheController.sourceFolders,
            'After adding the third source item with addSourceFolders the second test source path was not in the sourceFolders vaiable'
        )
        self.assertTrue(
            secondSourceFolderPath in cacheController.getSourceFolders(),
            'After adding the third source item with addSourceFolders the second test source path was not in the getSourceFolders output'
        )

        self.assertTrue(
            thirdSourceFolderPath in cacheController.sourceFolders,
            'After adding the third source item with addSourceFolders the third test source path was not in the sourceFolders vaiable'
        )
        self.assertTrue(
            thirdSourceFolderPath in cacheController.getSourceFolders(),
            'After adding the third source item with addSourceFolders the third test source path was not in the getSourceFolders output'
        )

        # remove the second item, and verify that it is removed, and the other two still there
        cacheController.removeSourceFolders(secondSourceFolderPath)

        self.assertFalse(
            secondSourceFolderPath in cacheController.sourceFolders,
            'After removing the second source item with removeSourceFolders the second test source path was still in the sourceFolders vaiable'
        )
        self.assertFalse(
            secondSourceFolderPath in cacheController.getSourceFolders(),
            'After removing the second source item with removeSourceFolders the second test source path was still in the getSourceFolders output'
        )

        self.assertTrue(
            firstSourceFolderPath in cacheController.sourceFolders,
            'After removing the second source item with removeSourceFolders the first test source path was not in the sourceFolders vaiable'
        )
        self.assertTrue(
            firstSourceFolderPath in cacheController.getSourceFolders(),
            'After removing the second source item with removeSourceFolders the first test source path was not in the getSourceFolders output'
        )

        self.assertTrue(
            thirdSourceFolderPath in cacheController.sourceFolders,
            'After removing the second source item with removeSourceFolders the third test source path was not in the sourceFolders vaiable'
        )
        self.assertTrue(
            thirdSourceFolderPath in cacheController.getSourceFolders(),
            'After removing the second source item with removeSourceFolders the third test source path was not in the getSourceFolders output'
        )

        # remove the two remaining items and verify that they are gone
        cacheController.removeSourceFolders(
            [firstSourceFolderPath, thirdSourceFolderPath])

        self.assertFalse(
            firstSourceFolderPath in cacheController.sourceFolders,
            'After removing the first and third source item with removeSourceFolders the first test source path was still in the sourceFolders vaiable'
        )
        self.assertFalse(
            secondSourceFolderPath in cacheController.sourceFolders,
            'After removing the first and third source item with removeSourceFolders the second test source path was still in the sourceFolders vaiable'
        )
        self.assertFalse(
            thirdSourceFolderPath in cacheController.sourceFolders,
            'After removing the first and third source item with removeSourceFolders the third test source path was still in the sourceFolders vaiable'
        )

        # cleanup
        cacheController.removeCacheFolder()
        cacheController.removeSourceFolders(cacheFolderPath)
        tempFolderManager.cleanupItem(cacheFolderPath)

        tempFolderManager.cleanupItem(firstSourceFolderPath)
        tempFolderManager.cleanupItem(secondSourceFolderPath)
        tempFolderManager.cleanupItem(thirdSourceFolderPath)