<s> from __future__ import absolute_import , division <EOL> import gc <EOL> import re <EOL> import sys <EOL> import textwrap <EOL> import types <EOL> from twisted . trial import unittest <EOL> from twisted . trial . runner import TrialRunner , TestSuite , DestructiveTestSuite <EOL> from twisted . trial . runner import TestLoader <EOL> from twisted . scripts import trial <EOL> from twisted . python import util <EOL> from twisted . python . usage import UsageError <EOL> from twisted . python . filepath import FilePath <EOL> from twisted . python . compat import NativeStringIO , _PY3 <EOL> from twisted . trial . test . test_loader import testNames <EOL> if not _PY3 : <EOL> from twisted . trial . _dist . disttrial import DistTrialRunner <EOL> pyunit = __import__ ( '<STR_LIT>' ) <EOL> def sibpath ( filename ) : <EOL> """<STR_LIT>""" <EOL> return util . sibpath ( __file__ , filename ) <EOL> class ForceGarbageCollectionTests ( unittest . SynchronousTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . config = trial . Options ( ) <EOL> self . log = [ ] <EOL> self . patch ( gc , '<STR_LIT>' , self . collect ) <EOL> test = pyunit . FunctionTestCase ( self . simpleTest ) <EOL> self . test = TestSuite ( [ test , test ] ) <EOL> def simpleTest ( self ) : <EOL> """<STR_LIT>""" <EOL> self . log . append ( '<STR_LIT:test>' ) <EOL> def collect ( self ) : <EOL> """<STR_LIT>""" <EOL> self . log . append ( '<STR_LIT>' ) <EOL> def makeRunner ( self ) : <EOL> """<STR_LIT>""" <EOL> runner = trial . _makeRunner ( self . config ) <EOL> runner . stream = NativeStringIO ( ) <EOL> return runner <EOL> def test_forceGc ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config [ '<STR_LIT>' ] = True <EOL> self . config . postOptions ( ) <EOL> runner = self . makeRunner ( ) <EOL> runner . run ( self . test ) <EOL> self . assertEqual ( self . log , [ '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT>' ] ) <EOL> def test_unforceGc ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . postOptions ( ) <EOL> runner = self . makeRunner ( ) <EOL> runner . run ( self . test ) <EOL> self . assertEqual ( self . log , [ '<STR_LIT:test>' , '<STR_LIT:test>' ] ) <EOL> class SuiteUsedTests ( unittest . SynchronousTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config = trial . Options ( ) <EOL> def test_defaultSuite ( self ) : <EOL> """<STR_LIT>""" <EOL> loader = trial . _getLoader ( self . config ) <EOL> self . assertEqual ( loader . suiteFactory , DestructiveTestSuite ) <EOL> def test_untilFailureSuite ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config [ '<STR_LIT>' ] = True <EOL> loader = trial . _getLoader ( self . config ) <EOL> self . assertEqual ( loader . suiteFactory , TestSuite ) <EOL> class TestModuleTests ( unittest . SynchronousTestCase ) : <EOL> def setUp ( self ) : <EOL> self . config = trial . Options ( ) <EOL> def tearDown ( self ) : <EOL> self . config = None <EOL> def test_testNames ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( testNames ( self ) , [ self . id ( ) ] ) <EOL> def assertSuitesEqual ( self , test1 , names ) : <EOL> loader = TestLoader ( ) <EOL> names1 = testNames ( test1 ) <EOL> names2 = testNames ( TestSuite ( map ( loader . loadByName , names ) ) ) <EOL> names1 . sort ( ) <EOL> names2 . sort ( ) <EOL> self . assertEqual ( names1 , names2 ) <EOL> def test_baseState ( self ) : <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . config [ '<STR_LIT>' ] ) ) <EOL> def test_testmoduleOnModule ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . opt_testmodule ( sibpath ( '<STR_LIT>' ) ) <EOL> self . assertSuitesEqual ( trial . _getSuite ( self . config ) , <EOL> [ '<STR_LIT>' ] ) <EOL> def test_testmoduleTwice ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . opt_testmodule ( sibpath ( '<STR_LIT>' ) ) <EOL> self . config . opt_testmodule ( sibpath ( '<STR_LIT>' ) ) <EOL> self . assertSuitesEqual ( trial . _getSuite ( self . config ) , <EOL> [ '<STR_LIT>' ] ) <EOL> def test_testmoduleOnSourceAndTarget ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . opt_testmodule ( sibpath ( '<STR_LIT>' ) ) <EOL> self . config . opt_testmodule ( sibpath ( '<STR_LIT>' ) ) <EOL> self . assertSuitesEqual ( trial . _getSuite ( self . config ) , <EOL> [ '<STR_LIT>' ] ) <EOL> def test_testmoduleOnSelfModule ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . opt_testmodule ( sibpath ( '<STR_LIT>' ) ) <EOL> self . assertSuitesEqual ( trial . _getSuite ( self . config ) , <EOL> [ '<STR_LIT>' ] ) <EOL> def test_testmoduleOnScript ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . opt_testmodule ( sibpath ( '<STR_LIT>' ) ) <EOL> self . assertSuitesEqual ( trial . _getSuite ( self . config ) , <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def test_testmoduleOnNonexistentFile ( self ) : <EOL> """<STR_LIT>""" <EOL> buffy = NativeStringIO ( ) <EOL> stderr , sys . stderr = sys . stderr , buffy <EOL> filename = '<STR_LIT>' <EOL> try : <EOL> self . config . opt_testmodule ( filename ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . config [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( "<STR_LIT>" % ( filename , ) , <EOL> buffy . getvalue ( ) ) <EOL> finally : <EOL> sys . stderr = stderr <EOL> def test_testmoduleOnEmptyVars ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . opt_testmodule ( sibpath ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . config [ '<STR_LIT>' ] ) ) <EOL> def test_testmoduleOnModuleName ( self ) : <EOL> """<STR_LIT>""" <EOL> buffy = NativeStringIO ( ) <EOL> stderr , sys . stderr = sys . stderr , buffy <EOL> moduleName = '<STR_LIT>' <EOL> try : <EOL> self . config . opt_testmodule ( moduleName ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . config [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( "<STR_LIT>" % ( moduleName , ) , <EOL> buffy . getvalue ( ) ) <EOL> finally : <EOL> sys . stderr = stderr <EOL> def test_parseLocalVariable ( self ) : <EOL> declaration = '<STR_LIT>' <EOL> localVars = trial . _parseLocalVariables ( declaration ) <EOL> self . assertEqual ( { '<STR_LIT>' : <EOL> '<STR_LIT>' } , <EOL> localVars ) <EOL> def test_trailingSemicolon ( self ) : <EOL> declaration = '<STR_LIT>' <EOL> localVars = trial . _parseLocalVariables ( declaration ) <EOL> self . assertEqual ( { '<STR_LIT>' : <EOL> '<STR_LIT>' } , <EOL> localVars ) <EOL> def test_parseLocalVariables ( self ) : <EOL> declaration = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> localVars = trial . _parseLocalVariables ( declaration ) <EOL> self . assertEqual ( { '<STR_LIT>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:foo>' : '<STR_LIT:bar>' } , <EOL> localVars ) <EOL> def test_surroundingGuff ( self ) : <EOL> declaration = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> localVars = trial . _parseLocalVariables ( declaration ) <EOL> self . assertEqual ( { '<STR_LIT>' : <EOL> '<STR_LIT>' } , <EOL> localVars ) <EOL> def test_invalidLine ( self ) : <EOL> self . failUnlessRaises ( ValueError , trial . _parseLocalVariables , <EOL> '<STR_LIT:foo>' ) <EOL> def test_invalidDeclaration ( self ) : <EOL> self . failUnlessRaises ( ValueError , trial . _parseLocalVariables , <EOL> '<STR_LIT>' ) <EOL> self . failUnlessRaises ( ValueError , trial . _parseLocalVariables , <EOL> '<STR_LIT>' ) <EOL> self . failUnlessRaises ( ValueError , trial . _parseLocalVariables , <EOL> '<STR_LIT>' ) <EOL> def test_variablesFromFile ( self ) : <EOL> localVars = trial . loadLocalVariables ( sibpath ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( { '<STR_LIT>' : <EOL> '<STR_LIT>' } , <EOL> localVars ) <EOL> def test_noVariablesInFile ( self ) : <EOL> localVars = trial . loadLocalVariables ( sibpath ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( { } , localVars ) <EOL> def test_variablesFromScript ( self ) : <EOL> localVars = trial . loadLocalVariables ( sibpath ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> { '<STR_LIT>' : ( '<STR_LIT>' <EOL> '<STR_LIT>' ) } , <EOL> localVars ) <EOL> def test_getTestModules ( self ) : <EOL> modules = trial . getTestModules ( sibpath ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( modules , [ '<STR_LIT>' ] ) <EOL> def test_getTestModules_noVars ( self ) : <EOL> modules = trial . getTestModules ( sibpath ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( len ( modules ) , <NUM_LIT:0> ) <EOL> def test_getTestModules_multiple ( self ) : <EOL> modules = trial . getTestModules ( sibpath ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( set ( modules ) , <EOL> set ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) ) <EOL> def test_looksLikeTestModule ( self ) : <EOL> for filename in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . assertTrue ( trial . isTestFile ( filename ) , <EOL> "<STR_LIT>" % ( filename , ) ) <EOL> for filename in [ '<STR_LIT>' , <EOL> sibpath ( '<STR_LIT>' ) , sibpath ( '<STR_LIT>' ) ] : <EOL> self . assertFalse ( trial . isTestFile ( filename ) , <EOL> "<STR_LIT>" % ( filename , ) ) <EOL> class WithoutModuleTests ( unittest . SynchronousTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config = trial . Options ( ) <EOL> self . savedModules = dict ( sys . modules ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> for module in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if module in self . savedModules : <EOL> sys . modules [ module ] = self . savedModules [ module ] <EOL> else : <EOL> sys . modules . pop ( module , None ) <EOL> def _checkSMTP ( self ) : <EOL> """<STR_LIT>""" <EOL> import smtplib <EOL> return smtplib <EOL> def _checkIMAP ( self ) : <EOL> """<STR_LIT>""" <EOL> import imaplib <EOL> return imaplib <EOL> def test_disableOneModule ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . parseOptions ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertRaises ( ImportError , self . _checkSMTP ) <EOL> del sys . modules [ "<STR_LIT>" ] <EOL> self . assertIsInstance ( self . _checkSMTP ( ) , types . ModuleType ) <EOL> def test_disableMultipleModules ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . parseOptions ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertRaises ( ImportError , self . _checkSMTP ) <EOL> self . assertRaises ( ImportError , self . _checkIMAP ) <EOL> del sys . modules [ "<STR_LIT>" ] <EOL> del sys . modules [ "<STR_LIT>" ] <EOL> self . assertIsInstance ( self . _checkSMTP ( ) , types . ModuleType ) <EOL> self . assertIsInstance ( self . _checkIMAP ( ) , types . ModuleType ) <EOL> def test_disableAlreadyImportedModule ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertIsInstance ( self . _checkSMTP ( ) , types . ModuleType ) <EOL> self . assertWarns ( RuntimeWarning , <EOL> "<STR_LIT>" , <EOL> trial . __file__ , <EOL> self . config . parseOptions , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertRaises ( ImportError , self . _checkSMTP ) <EOL> class CoverageTests ( unittest . SynchronousTestCase ) : <EOL> """<STR_LIT>""" <EOL> if getattr ( sys , '<STR_LIT>' , None ) is None : <EOL> skip = ( <EOL> "<STR_LIT>" ) <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . addCleanup ( sys . settrace , sys . gettrace ( ) ) <EOL> def test_tracerInstalled ( self ) : <EOL> """<STR_LIT>""" <EOL> options = trial . Options ( ) <EOL> options . parseOptions ( [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( sys . gettrace ( ) , options . tracer . globaltrace ) <EOL> def test_coverdirDefault ( self ) : <EOL> """<STR_LIT>""" <EOL> options = trial . Options ( ) <EOL> self . assertEqual ( <EOL> options . coverdir ( ) , <EOL> FilePath ( "<STR_LIT:.>" ) . descendant ( [ options [ "<STR_LIT>" ] , "<STR_LIT>" ] ) ) <EOL> def test_coverdirOverridden ( self ) : <EOL> """<STR_LIT>""" <EOL> path = self . mktemp ( ) <EOL> options = trial . Options ( ) <EOL> options . parseOptions ( [ "<STR_LIT>" , path ] ) <EOL> self . assertEqual ( <EOL> options . coverdir ( ) , FilePath ( path ) . child ( "<STR_LIT>" ) ) <EOL> class OptionsTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . options = trial . Options ( ) <EOL> def test_getWorkerArguments ( self ) : <EOL> """<STR_LIT>""" <EOL> self . addCleanup ( sys . setrecursionlimit , sys . getrecursionlimit ( ) ) <EOL> if gc . isenabled ( ) : <EOL> self . addCleanup ( gc . enable ) <EOL> self . options . parseOptions ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT:4>" , "<STR_LIT>" ] ) <EOL> args = self . options . _getWorkerArguments ( ) <EOL> self . assertIn ( "<STR_LIT>" , args ) <EOL> args . remove ( "<STR_LIT>" ) <EOL> self . assertEqual ( [ "<STR_LIT>" , "<STR_LIT>" ] , args ) <EOL> def test_jobsConflictWithDebug ( self ) : <EOL> """<STR_LIT>""" <EOL> error = self . assertRaises ( <EOL> UsageError , self . options . parseOptions , [ "<STR_LIT>" , "<STR_LIT:4>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( "<STR_LIT>" , <EOL> str ( error ) ) <EOL> def test_jobsConflictWithProfile ( self ) : <EOL> """<STR_LIT>""" <EOL> error = self . assertRaises ( <EOL> UsageError , self . options . parseOptions , <EOL> [ "<STR_LIT>" , "<STR_LIT:4>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( "<STR_LIT>" , <EOL> str ( error ) ) <EOL> def test_jobsConflictWithDebugStackTraces ( self ) : <EOL> """<STR_LIT>""" <EOL> error = self . assertRaises ( <EOL> UsageError , self . options . parseOptions , <EOL> [ "<STR_LIT>" , "<STR_LIT:4>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( <EOL> "<STR_LIT>" , <EOL> str ( error ) ) <EOL> def test_jobsConflictWithExitFirst ( self ) : <EOL> """<STR_LIT>""" <EOL> error = self . assertRaises ( <EOL> UsageError , self . options . parseOptions , <EOL> [ "<STR_LIT>" , "<STR_LIT:4>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( <EOL> "<STR_LIT>" , <EOL> str ( error ) ) <EOL> def test_orderConflictWithRandom ( self ) : <EOL> """<STR_LIT>""" <EOL> error = self . assertRaises ( <EOL> UsageError , <EOL> self . options . parseOptions , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( "<STR_LIT>" , <EOL> str ( error ) ) <EOL> class MakeRunnerTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . options = trial . Options ( ) <EOL> def test_jobs ( self ) : <EOL> """<STR_LIT>""" <EOL> self . options . parseOptions ( [ "<STR_LIT>" , "<STR_LIT:4>" , "<STR_LIT>" ] ) <EOL> runner = trial . _makeRunner ( self . options ) <EOL> self . assertIsInstance ( runner , DistTrialRunner ) <EOL> self . assertEqual ( <NUM_LIT:4> , runner . _workerNumber ) <EOL> self . assertEqual ( [ "<STR_LIT>" ] , runner . _workerArguments ) <EOL> if _PY3 : <EOL> test_jobs . skip = "<STR_LIT>" <EOL> def test_dryRunWithJobs ( self ) : <EOL> """<STR_LIT>""" <EOL> self . options . parseOptions ( [ "<STR_LIT>" , "<STR_LIT:4>" , "<STR_LIT>" ] ) <EOL> runner = trial . _makeRunner ( self . options ) <EOL> self . assertIsInstance ( runner , TrialRunner ) <EOL> self . assertEqual ( TrialRunner . DRY_RUN , runner . mode ) <EOL> def test_DebuggerNotFound ( self ) : <EOL> namedAny = trial . reflect . namedAny <EOL> def namedAnyExceptdoNotFind ( fqn ) : <EOL> if fqn == "<STR_LIT>" : <EOL> raise trial . reflect . ModuleNotFound ( fqn ) <EOL> return namedAny ( fqn ) <EOL> self . patch ( trial . reflect , "<STR_LIT>" , namedAnyExceptdoNotFind ) <EOL> options = trial . Options ( ) <EOL> options . parseOptions ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertRaises ( trial . _DebuggerNotFound , trial . _makeRunner , options ) <EOL> def test_exitfirst ( self ) : <EOL> """<STR_LIT>""" <EOL> self . options . parseOptions ( [ "<STR_LIT>" ] ) <EOL> runner = trial . _makeRunner ( self . options ) <EOL> self . assertTrue ( runner . _exitFirst ) <EOL> class RunTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . patch ( trial . Options , "<STR_LIT>" , lambda self : None ) <EOL> def test_debuggerNotFound ( self ) : <EOL> """<STR_LIT>""" <EOL> def _makeRunner ( * args , ** kwargs ) : <EOL> raise trial . _DebuggerNotFound ( '<STR_LIT:foo>' ) <EOL> self . patch ( trial , "<STR_LIT>" , _makeRunner ) <EOL> try : <EOL> trial . run ( ) <EOL> except SystemExit as e : <EOL> self . assertIn ( "<STR_LIT:foo>" , str ( e ) ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> class TestArgumentOrderTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . config = trial . Options ( ) <EOL> self . loader = TestLoader ( ) <EOL> def test_preserveArgumentOrder ( self ) : <EOL> """<STR_LIT>""" <EOL> tests = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> self . config . parseOptions ( tests ) <EOL> suite = trial . _getSuite ( self . config ) <EOL> names = testNames ( suite ) <EOL> expectedSuite = TestSuite ( map ( self . loader . loadByName , tests ) ) <EOL> expectedNames = testNames ( expectedSuite ) <EOL> self . assertEqual ( names , expectedNames ) <EOL> class OrderTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . config = trial . Options ( ) <EOL> def test_alphabetical ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . parseOptions ( [ <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> loader = trial . _getLoader ( self . config ) <EOL> suite = loader . loadByNames ( self . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> testNames ( suite ) , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def test_alphabeticalModule ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . parseOptions ( [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> loader = trial . _getLoader ( self . config ) <EOL> suite = loader . loadByNames ( self . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> testNames ( suite ) , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def test_alphabeticalPackage ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . parseOptions ( [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> loader = trial . _getLoader ( self . config ) <EOL> suite = loader . loadByNames ( self . config [ '<STR_LIT>' ] ) <EOL> names = testNames ( suite ) <EOL> self . assertTrue ( names , msg = "<STR_LIT>" ) <EOL> self . assertEqual ( names , sorted ( names ) ) <EOL> def test_toptobottom ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . parseOptions ( [ <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> loader = trial . _getLoader ( self . config ) <EOL> suite = loader . loadByNames ( self . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> testNames ( suite ) , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def test_toptobottomModule ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . parseOptions ( [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> loader = trial . _getLoader ( self . config ) <EOL> suite = loader . loadByNames ( self . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> testNames ( suite ) , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def test_toptobottomPackage ( self ) : <EOL> """<STR_LIT>""" <EOL> self . config . parseOptions ( [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> loader = trial . _getLoader ( self . config ) <EOL> suite = loader . loadByNames ( self . config [ '<STR_LIT>' ] ) <EOL> names = testNames ( suite ) <EOL> self . assertEqual ( <EOL> names , sorted ( names , key = lambda name : name . split ( "<STR_LIT:.>" ) [ : <NUM_LIT:4> ] ) , <EOL> ) <EOL> def test_toptobottomMissingSource ( self ) : <EOL> """<STR_LIT>""" <EOL> tempdir = self . mktemp ( ) <EOL> package = FilePath ( tempdir ) . child ( '<STR_LIT>' ) <EOL> package . makedirs ( ) <EOL> package . child ( '<STR_LIT>' ) . setContent ( b'<STR_LIT>' ) <EOL> package . child ( '<STR_LIT>' ) . setContent ( textwrap . dedent ( '''<STR_LIT>''' ) . encode ( '<STR_LIT:utf8>' ) ) <EOL> pathEntry = package . parent ( ) . path <EOL> sys . path . insert ( <NUM_LIT:0> , pathEntry ) <EOL> self . addCleanup ( sys . path . remove , pathEntry ) <EOL> from twisted_toptobottom_temp import test_missing <EOL> self . addCleanup ( sys . modules . pop , '<STR_LIT>' ) <EOL> self . addCleanup ( sys . modules . pop , test_missing . __name__ ) <EOL> package . child ( '<STR_LIT>' ) . remove ( ) <EOL> self . config . parseOptions ( [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> loader = trial . _getLoader ( self . config ) <EOL> suite = loader . loadModule ( test_missing ) <EOL> self . assertEqual ( <EOL> testNames ( suite ) , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def test_unknownOrder ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( <EOL> UsageError , self . config . parseOptions , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> class HelpOrderTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_help_ordersPrintsSynopsisAndQuits ( self ) : <EOL> """<STR_LIT>""" <EOL> self . patch ( sys , "<STR_LIT>" , NativeStringIO ( ) ) <EOL> exc = self . assertRaises ( <EOL> SystemExit , trial . Options ( ) . parseOptions , [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( exc . code , <NUM_LIT:0> ) <EOL> output = sys . stdout . getvalue ( ) <EOL> msg = "<STR_LIT>" <EOL> for orderName , ( orderDesc , _ ) in trial . _runOrders . items ( ) : <EOL> match = re . search ( <EOL> "<STR_LIT>" % ( re . escape ( orderName ) , re . escape ( orderDesc ) ) , <EOL> output , <EOL> ) <EOL> self . assertTrue ( match , msg = msg % ( orderName , output ) ) </s>
