Changeset 27098
- Timestamp:
- 07/07/2009 07:20:40 PM (14 months ago)
- Location:
- trunk/twisted/trial
- Files:
-
- 2 modified
-
runner.py (modified) (7 diffs)
-
test/test_runner.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/twisted/trial/runner.py
r26734 r27098 1 1 # -*- test-case-name: twisted.trial.test.test_runner -*- 2 # Copyright (c) 2001-200 8Twisted Matrix Laboratories.2 # Copyright (c) 2001-2009 Twisted Matrix Laboratories. 3 3 # See LICENSE for details. 4 4 … … 10 10 11 11 12 import pdb , shutil12 import pdb 13 13 import os, types, warnings, sys, inspect, imp 14 14 import random, doctest, time 15 15 16 from twisted.python import reflect, log, failure, modules 16 from twisted.python import reflect, log, failure, modules, filepath 17 17 from twisted.python.util import dsu 18 18 from twisted.python.compat import set … … 37 37 A working directory was specified to the runner, but another test run is 38 38 currently using that directory. 39 """ 40 41 42 43 class _NoTrialMarker(Exception): 44 """ 45 No trial marker file could be found. 46 47 Raised when trial attempts to remove a trial temporary working directory 48 that does not contain a marker file. 39 49 """ 40 50 … … 66 76 """ 67 77 return os.path.abspath(filename1) == os.path.abspath(filename2) 78 68 79 69 80 def filenameToModule(fn): … … 698 709 699 710 def _removeSafely(self, path): 711 """ 712 Safely remove a path, recursively. 713 714 If C{path} does not contain a node named C{_trial_marker}, a 715 L{_NoTrialmarker} exception is raised and the path is not removed. 716 """ 717 if not path.child('_trial_marker').exists(): 718 raise _NoTrialMarker( 719 '%r is not a trial temporary path, refusing to remove it' 720 % (path,)) 721 700 722 try: 701 shutil.rmtree(path)723 path.remove() 702 724 except OSError, e: 703 725 print ("could not remove %r, caught OSError [Errno %s]: %s" 704 % (path, e.errno, e.strerror))726 % (path, e.errno, e.strerror)) 705 727 try: 706 os.rename(path,707 os.path.abspath("_trial_temp_old%s"708 % random.randint(0, 99999999)))728 newPath = FilePath('_trial_temp_old%s' 729 % random.randint(0, 99999999)) 730 path.moveTo(newPath) 709 731 except OSError, e: 710 732 print ("could not rename path, caught OSError [Errno %s]: %s" … … 716 738 self._tearDownLogFile() 717 739 currentDir = os.getcwd() 718 base = os.path.normpath(os.path.abspath(self.workingDirectory))740 base = filepath.FilePath(self.workingDirectory) 719 741 counter = 0 720 742 while True: 721 743 if counter: 722 testdir = '%s-%d' % (base, counter)744 testdir = base.sibling('%s-%d' % (base.basename(), counter)) 723 745 else: 724 746 testdir = base 725 747 726 self._testDirLock = FilesystemLock(testdir + '.lock')748 self._testDirLock = FilesystemLock(testdir.path + '.lock') 727 749 if self._testDirLock.lock(): 728 750 # It is not in use 729 if os.path.exists(testdir):751 if testdir.exists(): 730 752 # It exists though - delete it 731 753 self._removeSafely(testdir) … … 738 760 raise _WorkingDirectoryBusy() 739 761 740 os.mkdir(testdir) 741 os.chdir(testdir) 762 testdir.makedirs() 763 os.chdir(testdir.path) 764 file('_trial_marker', 'w').close() 742 765 return currentDir 743 766 -
trunk/twisted/trial/test/test_runner.py
r25279 r27098 1 # Copyright (c) 2005-200 8Twisted Matrix Laboratories.1 # Copyright (c) 2005-2009 Twisted Matrix Laboratories. 2 2 # See LICENSE for details. 3 3 # … … 476 476 self.assertEqual(self.standardReport, result._calls) 477 477 self.assertEqual(['runcall'], debugger._calls) 478 479 480 def test_noMarker(self): 481 """ 482 Specifying a temp directory that does not have a trial marker results 483 in an exception and does not remove the specified directory. 484 """ 485 tempPath = self.mktemp() 486 # Create our working directory outside of trial. 487 os.mkdir(tempPath) 488 self.parseOptions(['--temp-directory', tempPath, 489 'twisted.trial.test.sample']) 490 myRunner = self.getRunner() 491 loader = runner.TestLoader() 492 suite = loader.loadByName('twisted.trial.test.sample', True) 493 self.assertRaises(runner._NoTrialMarker, myRunner.run, suite) 494 self.assertTrue(os.path.exists(tempPath)) 478 495 479 496
