Beispiel #1
0
    def test_multipleDefaultFolders(self):
        '''SetupMultiple default folders, and see that they are cleaned up with cleanupForExit'''

        # create the first target
        firstTarget = tempfile.mkdtemp(dir='/tmp')
        firstResult = tempFolderManager.setDefaultFolder(firstTarget)
        self.assertTrue(
            os.path.samefile(firstTarget, firstResult),
            'When setDefaultFolder was given a target location of "%s" it returned: %s'
            % (firstTarget, firstResult))
        generateSomeContent(firstTarget)

        # create the second target
        secondTarget = tempfile.mkdtemp(dir='/tmp')
        self.assertNotEqual(
            firstTarget, secondTarget,
            'Error in tempfile module: two calls to mkdtemp returned the same result'
        )
        secondResult = tempFolderManager.setDefaultFolder(secondTarget)
        self.assertTrue(
            os.path.samefile(secondTarget, secondResult),
            'When setDefaultFolder was given a target location of "%s" it returned: %s'
            % (firstTarget, firstResult))
        generateSomeContent(secondTarget)

        # clean up everything
        tempFolderManager.cleanupForExit()

        # verify that the targets went away
        self.assertFalse(
            os.path.exists(firstTarget) or os.path.exists(secondTarget),
            'Both folders were not deleted when cleanupForExit was called: %s %s'
            % (firstTarget, secondTarget))
Beispiel #2
0
    def test_basicClassSetup(self):
        '''Setup the class, and make sure it is running'''

        mainTempFolder = tempFolderManager.setDefaultFolder(None)

        # output tests
        self.assertTrue(
            mainTempFolder is not None,
            'Calling setDefaultFolder with no input returned None')
        self.assertTrue(
            os.path.isdir(mainTempFolder),
            'Calling setDefaultFolder with no input did not return a valid folder'
        )

        # defaultFolder value tests
        self.assertTrue(
            tempFolderManager.defaultFolder is not None,
            'When calling setDefaultFolder with no input the default folder path in tempFolderManager was not set'
        )
        self.assertEqual(
            mainTempFolder, tempFolderManager.defaultFolder,
            'When calling setDefaultFolder with no input the default folder path that setDefaultFolder returned (%s) was not set internally in tempFolderManager (%s)'
            % (mainTempFolder, tempFolderManager.defaultFolder))
        self.assertTrue(
            tempFolderManager.defaultFolder.startswith('/private/tmp'),
            'The tempFolderManager class did not auto-generate a folder in the expected place (/private/tmp) but rather: '
            + tempFolderManager.defaultFolder)

        # check that setDefaultFolder and getDefaultFolder return the same things
        getValue = tempFolderManager.getDefaultFolder()
        setValue = tempFolderManager.setDefaultFolder()
        self.assertEqual(
            getValue, setValue,
            'setDefaultFolder and getDefaultFolder did not return the same vaules: "%s" vs. "%s"'
            % (getValue, setValue))
	def test_targetdDefaultFolder(self):
		'''Test that default folders can be created at specified locations'''
		
		target = tempfile.mkdtemp(dir='/tmp')
		result = tempFolderManager.setDefaultFolder(target)
		self.assertTrue(os.path.samefile(target, result), 'When setDefaultFolder was given a target location of "%s" it returned: %s' % (target, result))
		self.assertTrue(os.path.samefile(target, tempFolderManager.defaultFolder), 'When setDefaultFolder was given a target location of "%s" it set the internal default folder to: %s' % (target, tempFolderManager.defaultFolder))
		self.assertEqual(tempFolderManager.getDefaultFolder(), result, 'getDefaultFolder did not return the same location as setDefaultFolder did: "%s" vs "%s"' % (tempFolderManager.getDefaultFolder(), result))
	def test_basicClassSetup(self):
		'''Setup the class, and make sure it is running'''
		
		mainTempFolder = tempFolderManager.setDefaultFolder(None)
		
		# output tests
		self.assertTrue(mainTempFolder is not None, 'Calling setDefaultFolder with no input returned None')
		self.assertTrue(os.path.isdir(mainTempFolder), 'Calling setDefaultFolder with no input did not return a valid folder')
		
		# defaultFolder value tests
		self.assertTrue(tempFolderManager.defaultFolder is not None, 'When calling setDefaultFolder with no input the default folder path in tempFolderManager was not set')
		self.assertEqual(mainTempFolder, tempFolderManager.defaultFolder, 'When calling setDefaultFolder with no input the default folder path that setDefaultFolder returned (%s) was not set internally in tempFolderManager (%s)' % (mainTempFolder, tempFolderManager.defaultFolder))
		self.assertTrue(tempFolderManager.defaultFolder.startswith('/private/tmp'), 'The tempFolderManager class did not auto-generate a folder in the expected place (/private/tmp) but rather: ' + tempFolderManager.defaultFolder)
		
		# check that setDefaultFolder and getDefaultFolder return the same things
		getValue = tempFolderManager.getDefaultFolder()
		setValue = tempFolderManager.setDefaultFolder()
		self.assertEqual(getValue, setValue, 'setDefaultFolder and getDefaultFolder did not return the same vaules: "%s" vs. "%s"' % (getValue, setValue))
	def test_multipleDefaultFolders(self):
		'''SetupMultiple default folders, and see that they are cleaned up with cleanupForExit'''
		
		# create the first target
		firstTarget = tempfile.mkdtemp(dir='/tmp')
		firstResult = tempFolderManager.setDefaultFolder(firstTarget)
		self.assertTrue(os.path.samefile(firstTarget, firstResult), 'When setDefaultFolder was given a target location of "%s" it returned: %s' % (firstTarget, firstResult))
		generateSomeContent(firstTarget)
		
		# create the second target
		secondTarget = tempfile.mkdtemp(dir='/tmp')
		self.assertNotEqual(firstTarget, secondTarget, 'Error in tempfile module: two calls to mkdtemp returned the same result')
		secondResult = tempFolderManager.setDefaultFolder(secondTarget)
		self.assertTrue(os.path.samefile(secondTarget, secondResult), 'When setDefaultFolder was given a target location of "%s" it returned: %s' % (firstTarget, firstResult))
		generateSomeContent(secondTarget)
		
		# clean up everything
		tempFolderManager.cleanupForExit()
		
		# verify that the targets went away
		self.assertFalse(os.path.exists(firstTarget) or os.path.exists(secondTarget), 'Both folders were not deleted when cleanupForExit was called: %s %s' % (firstTarget, secondTarget))
Beispiel #6
0
    def test_targetdDefaultFolder(self):
        '''Test that default folders can be created at specified locations'''

        target = tempfile.mkdtemp(dir='/tmp')
        result = tempFolderManager.setDefaultFolder(target)
        self.assertTrue(
            os.path.samefile(target, result),
            'When setDefaultFolder was given a target location of "%s" it returned: %s'
            % (target, result))
        self.assertTrue(
            os.path.samefile(target, tempFolderManager.defaultFolder),
            'When setDefaultFolder was given a target location of "%s" it set the internal default folder to: %s'
            % (target, tempFolderManager.defaultFolder))
        self.assertEqual(
            tempFolderManager.getDefaultFolder(), result,
            'getDefaultFolder did not return the same location as setDefaultFolder did: "%s" vs "%s"'
            % (tempFolderManager.getDefaultFolder(), result))