Ticket #3481: trial-marker.diff

File trial-marker.diff, 2.2 KB (added by jonathanj, 10 months ago)
  • twisted/trial/test/test_runner.py

     
    477477        self.assertEqual(['runcall'], debugger._calls) 
    478478 
    479479 
     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        my_runner = self.getRunner() 
     491        loader = runner.TestLoader() 
     492        suite = loader.loadByName('twisted.trial.test.sample', True) 
     493        self.assertRaises(runner.NoTrialMarker, my_runner.run, suite) 
     494        self.assertTrue(os.path.exists(tempPath)) 
    480495 
     496 
     497 
    481498class TestTrialSuite(unittest.TestCase): 
    482499 
    483500    def test_imports(self): 
  • twisted/trial/runner.py

     
    4040 
    4141 
    4242 
     43class NoTrialMarker(Exception): 
     44    """ 
     45    No trial marker file could be found. 
     46    """ 
     47 
     48 
     49 
    4350def isPackage(module): 
    4451    """Given an object return True if the object looks like a package""" 
    4552    if not isinstance(module, types.ModuleType): 
     
    697704 
    698705 
    699706    def _removeSafely(self, path): 
     707        """ 
     708        Safely remove a path, recursively. 
     709 
     710        If C{path} does not contain a node named C{_trial_marker}, a 
     711        C{NoTrialmarker} exception is raised and the path is not removed. 
     712        """ 
     713        if not os.path.exists(os.path.join(path, '_trial_marker')): 
     714            raise NoTrialMarker( 
     715                '%r is not a trial temporary path, refusing to remove it' 
     716                % (path,)) 
     717 
    700718        try: 
    701719            shutil.rmtree(path) 
    702720        except OSError, e: 
     
    739757 
    740758        os.mkdir(testdir) 
    741759        os.chdir(testdir) 
     760        file('_trial_marker', 'w').close() 
    742761        return currentDir 
    743762 
    744763