<s> """<STR_LIT>""" <EOL> import sys <EOL> from test import test_support <EOL> import unittest <EOL> from unittest import TestCase <EOL> import types <EOL> class LoggingResult ( unittest . TestResult ) : <EOL> def __init__ ( self , log ) : <EOL> self . _events = log <EOL> super ( LoggingResult , self ) . __init__ ( ) <EOL> def startTest ( self , test ) : <EOL> self . _events . append ( '<STR_LIT>' ) <EOL> super ( LoggingResult , self ) . startTest ( test ) <EOL> def stopTest ( self , test ) : <EOL> self . _events . append ( '<STR_LIT>' ) <EOL> super ( LoggingResult , self ) . stopTest ( test ) <EOL> def addFailure ( self , * args ) : <EOL> self . _events . append ( '<STR_LIT>' ) <EOL> super ( LoggingResult , self ) . addFailure ( * args ) <EOL> def addError ( self , * args ) : <EOL> self . _events . append ( '<STR_LIT>' ) <EOL> super ( LoggingResult , self ) . addError ( * args ) <EOL> class TestEquality ( object ) : <EOL> def test_eq ( self ) : <EOL> for obj_1 , obj_2 in self . eq_pairs : <EOL> self . assertEqual ( obj_1 , obj_2 ) <EOL> self . assertEqual ( obj_2 , obj_1 ) <EOL> def test_ne ( self ) : <EOL> for obj_1 , obj_2 in self . ne_pairs : <EOL> self . failIfEqual ( obj_1 , obj_2 ) <EOL> self . failIfEqual ( obj_2 , obj_1 ) <EOL> class TestHashing ( object ) : <EOL> def test_hash ( self ) : <EOL> for obj_1 , obj_2 in self . eq_pairs : <EOL> try : <EOL> assert hash ( obj_1 ) == hash ( obj_2 ) <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except AssertionError : <EOL> self . fail ( "<STR_LIT>" % ( obj_1 , obj_2 ) ) <EOL> except Exception , e : <EOL> self . fail ( "<STR_LIT>" % ( obj_1 , obj_2 , e ) ) <EOL> for obj_1 , obj_2 in self . ne_pairs : <EOL> try : <EOL> assert hash ( obj_1 ) != hash ( obj_2 ) <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except AssertionError : <EOL> self . fail ( "<STR_LIT>" % ( obj_1 , obj_2 ) ) <EOL> except Exception , e : <EOL> self . fail ( "<STR_LIT>" % ( obj_1 , obj_2 , e ) ) <EOL> class Test_TestLoader ( TestCase ) : <EOL> def test_loadTestsFromTestCase ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> def foo_bar ( self ) : pass <EOL> tests = unittest . TestSuite ( [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] ) <EOL> loader = unittest . TestLoader ( ) <EOL> self . assertEqual ( loader . loadTestsFromTestCase ( Foo ) , tests ) <EOL> def test_loadTestsFromTestCase__no_matches ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def foo_bar ( self ) : pass <EOL> empty_suite = unittest . TestSuite ( ) <EOL> loader = unittest . TestLoader ( ) <EOL> self . assertEqual ( loader . loadTestsFromTestCase ( Foo ) , empty_suite ) <EOL> def test_loadTestsFromTestCase__TestSuite_subclass ( self ) : <EOL> class NotATestCase ( unittest . TestSuite ) : <EOL> pass <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromTestCase ( NotATestCase ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_loadTestsFromTestCase__default_method_name ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> pass <EOL> loader = unittest . TestLoader ( ) <EOL> self . failIf ( '<STR_LIT>' . startswith ( loader . testMethodPrefix ) ) <EOL> suite = loader . loadTestsFromTestCase ( Foo ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> self . assertEqual ( list ( suite ) , [ Foo ( '<STR_LIT>' ) ] ) <EOL> def test_loadTestsFromModule__TestCase_subclass ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> m . testcase_1 = MyTestCase <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromModule ( m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> expected = [ loader . suiteClass ( [ MyTestCase ( '<STR_LIT:test>' ) ] ) ] <EOL> self . assertEqual ( list ( suite ) , expected ) <EOL> def test_loadTestsFromModule__no_TestCase_instances ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromModule ( m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> self . assertEqual ( list ( suite ) , [ ] ) <EOL> def test_loadTestsFromModule__no_TestCase_tests ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> pass <EOL> m . testcase_1 = MyTestCase <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromModule ( m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> self . assertEqual ( list ( suite ) , [ loader . suiteClass ( ) ] ) <EOL> def test_loadTestsFromModule__not_a_module ( self ) : <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> class NotAModule ( object ) : <EOL> test_2 = MyTestCase <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromModule ( NotAModule ) <EOL> reference = [ unittest . TestSuite ( [ MyTestCase ( '<STR_LIT:test>' ) ] ) ] <EOL> self . assertEqual ( list ( suite ) , reference ) <EOL> def test_loadTestsFromName__empty_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromName ( '<STR_LIT>' ) <EOL> except ValueError , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromName__malformed_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromName ( '<STR_LIT>' ) <EOL> except ValueError : <EOL> pass <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromName__unknown_module_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromName ( '<STR_LIT>' ) <EOL> except ImportError , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromName__unknown_attr_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromName ( '<STR_LIT>' ) <EOL> except AttributeError , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromName__relative_unknown_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromName ( '<STR_LIT>' , unittest ) <EOL> except AttributeError , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromName__relative_empty_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromName ( '<STR_LIT>' , unittest ) <EOL> except AttributeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromName__relative_malformed_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromName ( '<STR_LIT>' , unittest ) <EOL> except ValueError : <EOL> pass <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromName__relative_not_a_module ( self ) : <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> class NotAModule ( object ) : <EOL> test_2 = MyTestCase <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromName ( '<STR_LIT>' , NotAModule ) <EOL> reference = [ MyTestCase ( '<STR_LIT:test>' ) ] <EOL> self . assertEqual ( list ( suite ) , reference ) <EOL> def test_loadTestsFromName__relative_bad_object ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> m . testcase_1 = object ( ) <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromName ( '<STR_LIT>' , m ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromName__relative_TestCase_subclass ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> m . testcase_1 = MyTestCase <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromName ( '<STR_LIT>' , m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> self . assertEqual ( list ( suite ) , [ MyTestCase ( '<STR_LIT:test>' ) ] ) <EOL> def test_loadTestsFromName__relative_TestSuite ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> m . testsuite = unittest . TestSuite ( [ MyTestCase ( '<STR_LIT:test>' ) ] ) <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromName ( '<STR_LIT>' , m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> self . assertEqual ( list ( suite ) , [ MyTestCase ( '<STR_LIT:test>' ) ] ) <EOL> def test_loadTestsFromName__relative_testmethod ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> m . testcase_1 = MyTestCase <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromName ( '<STR_LIT>' , m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> self . assertEqual ( list ( suite ) , [ MyTestCase ( '<STR_LIT:test>' ) ] ) <EOL> def test_loadTestsFromName__relative_invalid_testmethod ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> m . testcase_1 = MyTestCase <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromName ( '<STR_LIT>' , m ) <EOL> except AttributeError , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromName__callable__TestSuite ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> testcase_1 = unittest . FunctionTestCase ( lambda : None ) <EOL> testcase_2 = unittest . FunctionTestCase ( lambda : None ) <EOL> def return_TestSuite ( ) : <EOL> return unittest . TestSuite ( [ testcase_1 , testcase_2 ] ) <EOL> m . return_TestSuite = return_TestSuite <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromName ( '<STR_LIT>' , m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> self . assertEqual ( list ( suite ) , [ testcase_1 , testcase_2 ] ) <EOL> def test_loadTestsFromName__callable__TestCase_instance ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> testcase_1 = unittest . FunctionTestCase ( lambda : None ) <EOL> def return_TestCase ( ) : <EOL> return testcase_1 <EOL> m . return_TestCase = return_TestCase <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromName ( '<STR_LIT>' , m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> self . assertEqual ( list ( suite ) , [ testcase_1 ] ) <EOL> def test_loadTestsFromName__callable__wrong_type ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> def return_wrong ( ) : <EOL> return <NUM_LIT:6> <EOL> m . return_wrong = return_wrong <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> suite = loader . loadTestsFromName ( '<STR_LIT>' , m ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromNames__empty_name_list ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromNames ( [ ] ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> self . assertEqual ( list ( suite ) , [ ] ) <EOL> def test_loadTestsFromNames__relative_empty_name_list ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromNames ( [ ] , unittest ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> self . assertEqual ( list ( suite ) , [ ] ) <EOL> def test_loadTestsFromNames__empty_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromNames ( [ '<STR_LIT>' ] ) <EOL> except ValueError , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromNames__malformed_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromNames ( [ '<STR_LIT>' ] ) <EOL> except ValueError : <EOL> pass <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromNames__unknown_module_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromNames ( [ '<STR_LIT>' ] ) <EOL> except ImportError , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromNames__unknown_attr_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromNames ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> except AttributeError , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromNames__unknown_name_relative_1 ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromNames ( [ '<STR_LIT>' ] , unittest ) <EOL> except AttributeError , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromNames__unknown_name_relative_2 ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromNames ( [ '<STR_LIT>' , '<STR_LIT>' ] , unittest ) <EOL> except AttributeError , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromNames__relative_empty_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromNames ( [ '<STR_LIT>' ] , unittest ) <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromNames__relative_malformed_name ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromNames ( [ '<STR_LIT>' ] , unittest ) <EOL> except AttributeError : <EOL> pass <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromNames__relative_not_a_module ( self ) : <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> class NotAModule ( object ) : <EOL> test_2 = MyTestCase <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromNames ( [ '<STR_LIT>' ] , NotAModule ) <EOL> reference = [ unittest . TestSuite ( [ MyTestCase ( '<STR_LIT:test>' ) ] ) ] <EOL> self . assertEqual ( list ( suite ) , reference ) <EOL> def test_loadTestsFromNames__relative_bad_object ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> m . testcase_1 = object ( ) <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromNames__relative_TestCase_subclass ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> m . testcase_1 = MyTestCase <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> expected = loader . suiteClass ( [ MyTestCase ( '<STR_LIT:test>' ) ] ) <EOL> self . assertEqual ( list ( suite ) , [ expected ] ) <EOL> def test_loadTestsFromNames__relative_TestSuite ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> m . testsuite = unittest . TestSuite ( [ MyTestCase ( '<STR_LIT:test>' ) ] ) <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> self . assertEqual ( list ( suite ) , [ m . testsuite ] ) <EOL> def test_loadTestsFromNames__relative_testmethod ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> m . testcase_1 = MyTestCase <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> ref_suite = unittest . TestSuite ( [ MyTestCase ( '<STR_LIT:test>' ) ] ) <EOL> self . assertEqual ( list ( suite ) , [ ref_suite ] ) <EOL> def test_loadTestsFromNames__relative_invalid_testmethod ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class MyTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> m . testcase_1 = MyTestCase <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) <EOL> except AttributeError , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_loadTestsFromNames__callable__TestSuite ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> testcase_1 = unittest . FunctionTestCase ( lambda : None ) <EOL> testcase_2 = unittest . FunctionTestCase ( lambda : None ) <EOL> def return_TestSuite ( ) : <EOL> return unittest . TestSuite ( [ testcase_1 , testcase_2 ] ) <EOL> m . return_TestSuite = return_TestSuite <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> expected = unittest . TestSuite ( [ testcase_1 , testcase_2 ] ) <EOL> self . assertEqual ( list ( suite ) , [ expected ] ) <EOL> def test_loadTestsFromNames__callable__TestCase_instance ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> testcase_1 = unittest . FunctionTestCase ( lambda : None ) <EOL> def return_TestCase ( ) : <EOL> return testcase_1 <EOL> m . return_TestCase = return_TestCase <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> ref_suite = unittest . TestSuite ( [ testcase_1 ] ) <EOL> self . assertEqual ( list ( suite ) , [ ref_suite ] ) <EOL> def test_loadTestsFromNames__callable__call_staticmethod ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class Test1 ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> testcase_1 = Test1 ( '<STR_LIT:test>' ) <EOL> class Foo ( unittest . TestCase ) : <EOL> @ staticmethod <EOL> def foo ( ) : <EOL> return testcase_1 <EOL> m . Foo = Foo <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) <EOL> self . failUnless ( isinstance ( suite , loader . suiteClass ) ) <EOL> ref_suite = unittest . TestSuite ( [ testcase_1 ] ) <EOL> self . assertEqual ( list ( suite ) , [ ref_suite ] ) <EOL> def test_loadTestsFromNames__callable__wrong_type ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> def return_wrong ( ) : <EOL> return <NUM_LIT:6> <EOL> m . return_wrong = return_wrong <EOL> loader = unittest . TestLoader ( ) <EOL> try : <EOL> suite = loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_getTestCaseNames ( self ) : <EOL> class Test ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> def foobar ( self ) : pass <EOL> loader = unittest . TestLoader ( ) <EOL> self . assertEqual ( loader . getTestCaseNames ( Test ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_getTestCaseNames__no_tests ( self ) : <EOL> class Test ( unittest . TestCase ) : <EOL> def foobar ( self ) : pass <EOL> loader = unittest . TestLoader ( ) <EOL> self . assertEqual ( loader . getTestCaseNames ( Test ) , [ ] ) <EOL> def test_getTestCaseNames__not_a_TestCase ( self ) : <EOL> class BadCase ( int ) : <EOL> def test_foo ( self ) : <EOL> pass <EOL> loader = unittest . TestLoader ( ) <EOL> names = loader . getTestCaseNames ( BadCase ) <EOL> self . assertEqual ( names , [ '<STR_LIT>' ] ) <EOL> def test_getTestCaseNames__inheritance ( self ) : <EOL> class TestP ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> def foobar ( self ) : pass <EOL> class TestC ( TestP ) : <EOL> def test_1 ( self ) : pass <EOL> def test_3 ( self ) : pass <EOL> loader = unittest . TestLoader ( ) <EOL> names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( loader . getTestCaseNames ( TestC ) , names ) <EOL> def test_testMethodPrefix__loadTestsFromTestCase ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> def foo_bar ( self ) : pass <EOL> tests_1 = unittest . TestSuite ( [ Foo ( '<STR_LIT>' ) ] ) <EOL> tests_2 = unittest . TestSuite ( [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] ) <EOL> loader = unittest . TestLoader ( ) <EOL> loader . testMethodPrefix = '<STR_LIT:foo>' <EOL> self . assertEqual ( loader . loadTestsFromTestCase ( Foo ) , tests_1 ) <EOL> loader . testMethodPrefix = '<STR_LIT:test>' <EOL> self . assertEqual ( loader . loadTestsFromTestCase ( Foo ) , tests_2 ) <EOL> def test_testMethodPrefix__loadTestsFromModule ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> def foo_bar ( self ) : pass <EOL> m . Foo = Foo <EOL> tests_1 = [ unittest . TestSuite ( [ Foo ( '<STR_LIT>' ) ] ) ] <EOL> tests_2 = [ unittest . TestSuite ( [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] ) ] <EOL> loader = unittest . TestLoader ( ) <EOL> loader . testMethodPrefix = '<STR_LIT:foo>' <EOL> self . assertEqual ( list ( loader . loadTestsFromModule ( m ) ) , tests_1 ) <EOL> loader . testMethodPrefix = '<STR_LIT:test>' <EOL> self . assertEqual ( list ( loader . loadTestsFromModule ( m ) ) , tests_2 ) <EOL> def test_testMethodPrefix__loadTestsFromName ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> def foo_bar ( self ) : pass <EOL> m . Foo = Foo <EOL> tests_1 = unittest . TestSuite ( [ Foo ( '<STR_LIT>' ) ] ) <EOL> tests_2 = unittest . TestSuite ( [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] ) <EOL> loader = unittest . TestLoader ( ) <EOL> loader . testMethodPrefix = '<STR_LIT:foo>' <EOL> self . assertEqual ( loader . loadTestsFromName ( '<STR_LIT>' , m ) , tests_1 ) <EOL> loader . testMethodPrefix = '<STR_LIT:test>' <EOL> self . assertEqual ( loader . loadTestsFromName ( '<STR_LIT>' , m ) , tests_2 ) <EOL> def test_testMethodPrefix__loadTestsFromNames ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> def foo_bar ( self ) : pass <EOL> m . Foo = Foo <EOL> tests_1 = unittest . TestSuite ( [ unittest . TestSuite ( [ Foo ( '<STR_LIT>' ) ] ) ] ) <EOL> tests_2 = unittest . TestSuite ( [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] ) <EOL> tests_2 = unittest . TestSuite ( [ tests_2 ] ) <EOL> loader = unittest . TestLoader ( ) <EOL> loader . testMethodPrefix = '<STR_LIT:foo>' <EOL> self . assertEqual ( loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) , tests_1 ) <EOL> loader . testMethodPrefix = '<STR_LIT:test>' <EOL> self . assertEqual ( loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) , tests_2 ) <EOL> def test_testMethodPrefix__default_value ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> self . failUnless ( loader . testMethodPrefix == '<STR_LIT:test>' ) <EOL> def test_sortTestMethodsUsing__loadTestsFromTestCase ( self ) : <EOL> def reversed_cmp ( x , y ) : <EOL> return - cmp ( x , y ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> loader = unittest . TestLoader ( ) <EOL> loader . sortTestMethodsUsing = reversed_cmp <EOL> tests = loader . suiteClass ( [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( loader . loadTestsFromTestCase ( Foo ) , tests ) <EOL> def test_sortTestMethodsUsing__loadTestsFromModule ( self ) : <EOL> def reversed_cmp ( x , y ) : <EOL> return - cmp ( x , y ) <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> m . Foo = Foo <EOL> loader = unittest . TestLoader ( ) <EOL> loader . sortTestMethodsUsing = reversed_cmp <EOL> tests = [ loader . suiteClass ( [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] ) ] <EOL> self . assertEqual ( list ( loader . loadTestsFromModule ( m ) ) , tests ) <EOL> def test_sortTestMethodsUsing__loadTestsFromName ( self ) : <EOL> def reversed_cmp ( x , y ) : <EOL> return - cmp ( x , y ) <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> m . Foo = Foo <EOL> loader = unittest . TestLoader ( ) <EOL> loader . sortTestMethodsUsing = reversed_cmp <EOL> tests = loader . suiteClass ( [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( loader . loadTestsFromName ( '<STR_LIT>' , m ) , tests ) <EOL> def test_sortTestMethodsUsing__loadTestsFromNames ( self ) : <EOL> def reversed_cmp ( x , y ) : <EOL> return - cmp ( x , y ) <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> m . Foo = Foo <EOL> loader = unittest . TestLoader ( ) <EOL> loader . sortTestMethodsUsing = reversed_cmp <EOL> tests = [ loader . suiteClass ( [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] ) ] <EOL> self . assertEqual ( list ( loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) ) , tests ) <EOL> def test_sortTestMethodsUsing__getTestCaseNames ( self ) : <EOL> def reversed_cmp ( x , y ) : <EOL> return - cmp ( x , y ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> loader = unittest . TestLoader ( ) <EOL> loader . sortTestMethodsUsing = reversed_cmp <EOL> test_names = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( loader . getTestCaseNames ( Foo ) , test_names ) <EOL> def test_sortTestMethodsUsing__default_value ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> self . failUnless ( loader . sortTestMethodsUsing is cmp ) <EOL> def test_sortTestMethodsUsing__None ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> loader = unittest . TestLoader ( ) <EOL> loader . sortTestMethodsUsing = None <EOL> test_names = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( set ( loader . getTestCaseNames ( Foo ) ) , set ( test_names ) ) <EOL> def test_suiteClass__loadTestsFromTestCase ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> def foo_bar ( self ) : pass <EOL> tests = [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] <EOL> loader = unittest . TestLoader ( ) <EOL> loader . suiteClass = list <EOL> self . assertEqual ( loader . loadTestsFromTestCase ( Foo ) , tests ) <EOL> def test_suiteClass__loadTestsFromModule ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> def foo_bar ( self ) : pass <EOL> m . Foo = Foo <EOL> tests = [ [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] ] <EOL> loader = unittest . TestLoader ( ) <EOL> loader . suiteClass = list <EOL> self . assertEqual ( loader . loadTestsFromModule ( m ) , tests ) <EOL> def test_suiteClass__loadTestsFromName ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> def foo_bar ( self ) : pass <EOL> m . Foo = Foo <EOL> tests = [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] <EOL> loader = unittest . TestLoader ( ) <EOL> loader . suiteClass = list <EOL> self . assertEqual ( loader . loadTestsFromName ( '<STR_LIT>' , m ) , tests ) <EOL> def test_suiteClass__loadTestsFromNames ( self ) : <EOL> m = types . ModuleType ( '<STR_LIT:m>' ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> def foo_bar ( self ) : pass <EOL> m . Foo = Foo <EOL> tests = [ [ Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ] ] <EOL> loader = unittest . TestLoader ( ) <EOL> loader . suiteClass = list <EOL> self . assertEqual ( loader . loadTestsFromNames ( [ '<STR_LIT>' ] , m ) , tests ) <EOL> def test_suiteClass__default_value ( self ) : <EOL> loader = unittest . TestLoader ( ) <EOL> self . failUnless ( loader . suiteClass is unittest . TestSuite ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> def test_3 ( self ) : pass <EOL> def runTest ( self ) : pass <EOL> def _mk_TestSuite ( * names ) : <EOL> return unittest . TestSuite ( Foo ( n ) for n in names ) <EOL> class Test_TestSuite ( TestCase , TestEquality ) : <EOL> eq_pairs = [ ( unittest . TestSuite ( ) , unittest . TestSuite ( ) ) <EOL> , ( unittest . TestSuite ( ) , unittest . TestSuite ( [ ] ) ) <EOL> , ( _mk_TestSuite ( '<STR_LIT>' ) , _mk_TestSuite ( '<STR_LIT>' ) ) ] <EOL> ne_pairs = [ ( unittest . TestSuite ( ) , _mk_TestSuite ( '<STR_LIT>' ) ) <EOL> , ( unittest . TestSuite ( [ ] ) , _mk_TestSuite ( '<STR_LIT>' ) ) <EOL> , ( _mk_TestSuite ( '<STR_LIT>' , '<STR_LIT>' ) , _mk_TestSuite ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> , ( _mk_TestSuite ( '<STR_LIT>' ) , _mk_TestSuite ( '<STR_LIT>' ) ) ] <EOL> def test_init__tests_optional ( self ) : <EOL> suite = unittest . TestSuite ( ) <EOL> self . assertEqual ( suite . countTestCases ( ) , <NUM_LIT:0> ) <EOL> def test_init__empty_tests ( self ) : <EOL> suite = unittest . TestSuite ( [ ] ) <EOL> self . assertEqual ( suite . countTestCases ( ) , <NUM_LIT:0> ) <EOL> def test_init__tests_from_any_iterable ( self ) : <EOL> def tests ( ) : <EOL> yield unittest . FunctionTestCase ( lambda : None ) <EOL> yield unittest . FunctionTestCase ( lambda : None ) <EOL> suite_1 = unittest . TestSuite ( tests ( ) ) <EOL> self . assertEqual ( suite_1 . countTestCases ( ) , <NUM_LIT:2> ) <EOL> suite_2 = unittest . TestSuite ( suite_1 ) <EOL> self . assertEqual ( suite_2 . countTestCases ( ) , <NUM_LIT:2> ) <EOL> suite_3 = unittest . TestSuite ( set ( suite_1 ) ) <EOL> self . assertEqual ( suite_3 . countTestCases ( ) , <NUM_LIT:2> ) <EOL> def test_init__TestSuite_instances_in_tests ( self ) : <EOL> def tests ( ) : <EOL> ftc = unittest . FunctionTestCase ( lambda : None ) <EOL> yield unittest . TestSuite ( [ ftc ] ) <EOL> yield unittest . FunctionTestCase ( lambda : None ) <EOL> suite = unittest . TestSuite ( tests ( ) ) <EOL> self . assertEqual ( suite . countTestCases ( ) , <NUM_LIT:2> ) <EOL> def test_iter ( self ) : <EOL> test1 = unittest . FunctionTestCase ( lambda : None ) <EOL> test2 = unittest . FunctionTestCase ( lambda : None ) <EOL> suite = unittest . TestSuite ( ( test1 , test2 ) ) <EOL> self . assertEqual ( list ( suite ) , [ test1 , test2 ] ) <EOL> def test_countTestCases_zero_simple ( self ) : <EOL> suite = unittest . TestSuite ( ) <EOL> self . assertEqual ( suite . countTestCases ( ) , <NUM_LIT:0> ) <EOL> def test_countTestCases_zero_nested ( self ) : <EOL> class Test1 ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> suite = unittest . TestSuite ( [ unittest . TestSuite ( ) ] ) <EOL> self . assertEqual ( suite . countTestCases ( ) , <NUM_LIT:0> ) <EOL> def test_countTestCases_simple ( self ) : <EOL> test1 = unittest . FunctionTestCase ( lambda : None ) <EOL> test2 = unittest . FunctionTestCase ( lambda : None ) <EOL> suite = unittest . TestSuite ( ( test1 , test2 ) ) <EOL> self . assertEqual ( suite . countTestCases ( ) , <NUM_LIT:2> ) <EOL> def test_countTestCases_nested ( self ) : <EOL> class Test1 ( unittest . TestCase ) : <EOL> def test1 ( self ) : pass <EOL> def test2 ( self ) : pass <EOL> test2 = unittest . FunctionTestCase ( lambda : None ) <EOL> test3 = unittest . FunctionTestCase ( lambda : None ) <EOL> child = unittest . TestSuite ( ( Test1 ( '<STR_LIT>' ) , test2 ) ) <EOL> parent = unittest . TestSuite ( ( test3 , child , Test1 ( '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( parent . countTestCases ( ) , <NUM_LIT:4> ) <EOL> def test_run__empty_suite ( self ) : <EOL> events = [ ] <EOL> result = LoggingResult ( events ) <EOL> suite = unittest . TestSuite ( ) <EOL> suite . run ( result ) <EOL> self . assertEqual ( events , [ ] ) <EOL> def test_run__requires_result ( self ) : <EOL> suite = unittest . TestSuite ( ) <EOL> try : <EOL> suite . run ( ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_run ( self ) : <EOL> events = [ ] <EOL> result = LoggingResult ( events ) <EOL> class LoggingCase ( unittest . TestCase ) : <EOL> def run ( self , result ) : <EOL> events . append ( '<STR_LIT>' % self . _testMethodName ) <EOL> def test1 ( self ) : pass <EOL> def test2 ( self ) : pass <EOL> tests = [ LoggingCase ( '<STR_LIT>' ) , LoggingCase ( '<STR_LIT>' ) ] <EOL> unittest . TestSuite ( tests ) . run ( result ) <EOL> self . assertEqual ( events , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_addTest__TestCase ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def test ( self ) : pass <EOL> test = Foo ( '<STR_LIT:test>' ) <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( test ) <EOL> self . assertEqual ( suite . countTestCases ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( list ( suite ) , [ test ] ) <EOL> def test_addTest__TestSuite ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def test ( self ) : pass <EOL> suite_2 = unittest . TestSuite ( [ Foo ( '<STR_LIT:test>' ) ] ) <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( suite_2 ) <EOL> self . assertEqual ( suite . countTestCases ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( list ( suite ) , [ suite_2 ] ) <EOL> def test_addTests ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : pass <EOL> def test_2 ( self ) : pass <EOL> test_1 = Foo ( '<STR_LIT>' ) <EOL> test_2 = Foo ( '<STR_LIT>' ) <EOL> inner_suite = unittest . TestSuite ( [ test_2 ] ) <EOL> def gen ( ) : <EOL> yield test_1 <EOL> yield test_2 <EOL> yield inner_suite <EOL> suite_1 = unittest . TestSuite ( ) <EOL> suite_1 . addTests ( gen ( ) ) <EOL> self . assertEqual ( list ( suite_1 ) , list ( gen ( ) ) ) <EOL> suite_2 = unittest . TestSuite ( ) <EOL> for t in gen ( ) : <EOL> suite_2 . addTest ( t ) <EOL> self . assertEqual ( suite_1 , suite_2 ) <EOL> def test_addTest__noniterable ( self ) : <EOL> suite = unittest . TestSuite ( ) <EOL> try : <EOL> suite . addTests ( <NUM_LIT:5> ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_addTest__noncallable ( self ) : <EOL> suite = unittest . TestSuite ( ) <EOL> self . assertRaises ( TypeError , suite . addTest , <NUM_LIT:5> ) <EOL> def test_addTest__casesuiteclass ( self ) : <EOL> suite = unittest . TestSuite ( ) <EOL> self . assertRaises ( TypeError , suite . addTest , Test_TestSuite ) <EOL> self . assertRaises ( TypeError , suite . addTest , unittest . TestSuite ) <EOL> def test_addTests__string ( self ) : <EOL> suite = unittest . TestSuite ( ) <EOL> self . assertRaises ( TypeError , suite . addTests , "<STR_LIT:foo>" ) <EOL> class Test_FunctionTestCase ( TestCase ) : <EOL> def test_countTestCases ( self ) : <EOL> test = unittest . FunctionTestCase ( lambda : None ) <EOL> self . assertEqual ( test . countTestCases ( ) , <NUM_LIT:1> ) <EOL> def test_run_call_order__error_in_setUp ( self ) : <EOL> events = [ ] <EOL> result = LoggingResult ( events ) <EOL> def setUp ( ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> def test ( ) : <EOL> events . append ( '<STR_LIT:test>' ) <EOL> def tearDown ( ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> unittest . FunctionTestCase ( test , setUp , tearDown ) . run ( result ) <EOL> self . assertEqual ( events , expected ) <EOL> def test_run_call_order__error_in_test ( self ) : <EOL> events = [ ] <EOL> result = LoggingResult ( events ) <EOL> def setUp ( ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> def test ( ) : <EOL> events . append ( '<STR_LIT:test>' ) <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> def tearDown ( ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> unittest . FunctionTestCase ( test , setUp , tearDown ) . run ( result ) <EOL> self . assertEqual ( events , expected ) <EOL> def test_run_call_order__failure_in_test ( self ) : <EOL> events = [ ] <EOL> result = LoggingResult ( events ) <EOL> def setUp ( ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> def test ( ) : <EOL> events . append ( '<STR_LIT:test>' ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> def tearDown ( ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> unittest . FunctionTestCase ( test , setUp , tearDown ) . run ( result ) <EOL> self . assertEqual ( events , expected ) <EOL> def test_run_call_order__error_in_tearDown ( self ) : <EOL> events = [ ] <EOL> result = LoggingResult ( events ) <EOL> def setUp ( ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> def test ( ) : <EOL> events . append ( '<STR_LIT:test>' ) <EOL> def tearDown ( ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> unittest . FunctionTestCase ( test , setUp , tearDown ) . run ( result ) <EOL> self . assertEqual ( events , expected ) <EOL> def test_id ( self ) : <EOL> test = unittest . FunctionTestCase ( lambda : None ) <EOL> self . failUnless ( isinstance ( test . id ( ) , basestring ) ) <EOL> def test_shortDescription__no_docstring ( self ) : <EOL> test = unittest . FunctionTestCase ( lambda : None ) <EOL> self . assertEqual ( test . shortDescription ( ) , None ) <EOL> def test_shortDescription__singleline_docstring ( self ) : <EOL> desc = "<STR_LIT>" <EOL> test = unittest . FunctionTestCase ( lambda : None , description = desc ) <EOL> self . assertEqual ( test . shortDescription ( ) , "<STR_LIT>" ) <EOL> class Test_TestResult ( TestCase ) : <EOL> def test_init ( self ) : <EOL> result = unittest . TestResult ( ) <EOL> self . failUnless ( result . wasSuccessful ( ) ) <EOL> self . assertEqual ( len ( result . errors ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( result . failures ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( result . testsRun , <NUM_LIT:0> ) <EOL> self . assertEqual ( result . shouldStop , False ) <EOL> def test_stop ( self ) : <EOL> result = unittest . TestResult ( ) <EOL> result . stop ( ) <EOL> self . assertEqual ( result . shouldStop , True ) <EOL> def test_startTest ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : <EOL> pass <EOL> test = Foo ( '<STR_LIT>' ) <EOL> result = unittest . TestResult ( ) <EOL> result . startTest ( test ) <EOL> self . failUnless ( result . wasSuccessful ( ) ) <EOL> self . assertEqual ( len ( result . errors ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( result . failures ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( result . testsRun , <NUM_LIT:1> ) <EOL> self . assertEqual ( result . shouldStop , False ) <EOL> result . stopTest ( test ) <EOL> def test_stopTest ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : <EOL> pass <EOL> test = Foo ( '<STR_LIT>' ) <EOL> result = unittest . TestResult ( ) <EOL> result . startTest ( test ) <EOL> self . failUnless ( result . wasSuccessful ( ) ) <EOL> self . assertEqual ( len ( result . errors ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( result . failures ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( result . testsRun , <NUM_LIT:1> ) <EOL> self . assertEqual ( result . shouldStop , False ) <EOL> result . stopTest ( test ) <EOL> self . failUnless ( result . wasSuccessful ( ) ) <EOL> self . assertEqual ( len ( result . errors ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( result . failures ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( result . testsRun , <NUM_LIT:1> ) <EOL> self . assertEqual ( result . shouldStop , False ) <EOL> def test_addSuccess ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : <EOL> pass <EOL> test = Foo ( '<STR_LIT>' ) <EOL> result = unittest . TestResult ( ) <EOL> result . startTest ( test ) <EOL> result . addSuccess ( test ) <EOL> result . stopTest ( test ) <EOL> self . failUnless ( result . wasSuccessful ( ) ) <EOL> self . assertEqual ( len ( result . errors ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( result . failures ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( result . testsRun , <NUM_LIT:1> ) <EOL> self . assertEqual ( result . shouldStop , False ) <EOL> def test_addFailure ( self ) : <EOL> import sys <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : <EOL> pass <EOL> test = Foo ( '<STR_LIT>' ) <EOL> try : <EOL> test . fail ( "<STR_LIT:foo>" ) <EOL> except : <EOL> exc_info_tuple = sys . exc_info ( ) <EOL> result = unittest . TestResult ( ) <EOL> result . startTest ( test ) <EOL> result . addFailure ( test , exc_info_tuple ) <EOL> result . stopTest ( test ) <EOL> self . failIf ( result . wasSuccessful ( ) ) <EOL> self . assertEqual ( len ( result . errors ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( result . failures ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( result . testsRun , <NUM_LIT:1> ) <EOL> self . assertEqual ( result . shouldStop , False ) <EOL> test_case , formatted_exc = result . failures [ <NUM_LIT:0> ] <EOL> self . failUnless ( test_case is test ) <EOL> self . failUnless ( isinstance ( formatted_exc , str ) ) <EOL> def test_addError ( self ) : <EOL> import sys <EOL> class Foo ( unittest . TestCase ) : <EOL> def test_1 ( self ) : <EOL> pass <EOL> test = Foo ( '<STR_LIT>' ) <EOL> try : <EOL> raise TypeError ( ) <EOL> except : <EOL> exc_info_tuple = sys . exc_info ( ) <EOL> result = unittest . TestResult ( ) <EOL> result . startTest ( test ) <EOL> result . addError ( test , exc_info_tuple ) <EOL> result . stopTest ( test ) <EOL> self . failIf ( result . wasSuccessful ( ) ) <EOL> self . assertEqual ( len ( result . errors ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( result . failures ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( result . testsRun , <NUM_LIT:1> ) <EOL> self . assertEqual ( result . shouldStop , False ) <EOL> test_case , formatted_exc = result . errors [ <NUM_LIT:0> ] <EOL> self . failUnless ( test_case is test ) <EOL> self . failUnless ( isinstance ( formatted_exc , str ) ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def runTest ( self ) : pass <EOL> def test1 ( self ) : pass <EOL> class Bar ( Foo ) : <EOL> def test2 ( self ) : pass <EOL> class Test_TestCase ( TestCase , TestEquality , TestHashing ) : <EOL> eq_pairs = [ ( Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ) ] <EOL> ne_pairs = [ ( Foo ( '<STR_LIT>' ) , Foo ( '<STR_LIT>' ) ) <EOL> , ( Foo ( '<STR_LIT>' ) , Bar ( '<STR_LIT>' ) ) <EOL> , ( Foo ( '<STR_LIT>' ) , Bar ( '<STR_LIT>' ) ) ] <EOL> def test_init__no_test_name ( self ) : <EOL> class Test ( unittest . TestCase ) : <EOL> def runTest ( self ) : raise MyException ( ) <EOL> def test ( self ) : pass <EOL> self . assertEqual ( Test ( ) . id ( ) [ - <NUM_LIT> : ] , '<STR_LIT>' ) <EOL> def test_init__test_name__valid ( self ) : <EOL> class Test ( unittest . TestCase ) : <EOL> def runTest ( self ) : raise MyException ( ) <EOL> def test ( self ) : pass <EOL> self . assertEqual ( Test ( '<STR_LIT:test>' ) . id ( ) [ - <NUM_LIT:10> : ] , '<STR_LIT>' ) <EOL> def test_init__test_name__invalid ( self ) : <EOL> class Test ( unittest . TestCase ) : <EOL> def runTest ( self ) : raise MyException ( ) <EOL> def test ( self ) : pass <EOL> try : <EOL> Test ( '<STR_LIT>' ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_countTestCases ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def test ( self ) : pass <EOL> self . assertEqual ( Foo ( '<STR_LIT:test>' ) . countTestCases ( ) , <NUM_LIT:1> ) <EOL> def test_defaultTestResult ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> pass <EOL> result = Foo ( ) . defaultTestResult ( ) <EOL> self . assertEqual ( type ( result ) , unittest . TestResult ) <EOL> def test_run_call_order__error_in_setUp ( self ) : <EOL> events = [ ] <EOL> result = LoggingResult ( events ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> def test ( self ) : <EOL> events . append ( '<STR_LIT:test>' ) <EOL> def tearDown ( self ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> Foo ( '<STR_LIT:test>' ) . run ( result ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( events , expected ) <EOL> def test_run_call_order__error_in_test ( self ) : <EOL> events = [ ] <EOL> result = LoggingResult ( events ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> def test ( self ) : <EOL> events . append ( '<STR_LIT:test>' ) <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> Foo ( '<STR_LIT:test>' ) . run ( result ) <EOL> self . assertEqual ( events , expected ) <EOL> def test_run_call_order__failure_in_test ( self ) : <EOL> events = [ ] <EOL> result = LoggingResult ( events ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> def test ( self ) : <EOL> events . append ( '<STR_LIT:test>' ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> Foo ( '<STR_LIT:test>' ) . run ( result ) <EOL> self . assertEqual ( events , expected ) <EOL> def test_run_call_order__error_in_tearDown ( self ) : <EOL> events = [ ] <EOL> result = LoggingResult ( events ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> def test ( self ) : <EOL> events . append ( '<STR_LIT:test>' ) <EOL> def tearDown ( self ) : <EOL> events . append ( '<STR_LIT>' ) <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> Foo ( '<STR_LIT:test>' ) . run ( result ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . assertEqual ( events , expected ) <EOL> def test_failureException__default ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> pass <EOL> self . failUnless ( Foo ( '<STR_LIT:test>' ) . failureException is AssertionError ) <EOL> def test_failureException__subclassing__explicit_raise ( self ) : <EOL> events = [ ] <EOL> result = LoggingResult ( events ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> raise RuntimeError ( ) <EOL> failureException = RuntimeError <EOL> self . failUnless ( Foo ( '<STR_LIT:test>' ) . failureException is RuntimeError ) <EOL> Foo ( '<STR_LIT:test>' ) . run ( result ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( events , expected ) <EOL> def test_failureException__subclassing__implicit_raise ( self ) : <EOL> events = [ ] <EOL> result = LoggingResult ( events ) <EOL> class Foo ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> self . fail ( "<STR_LIT:foo>" ) <EOL> failureException = RuntimeError <EOL> self . failUnless ( Foo ( '<STR_LIT:test>' ) . failureException is RuntimeError ) <EOL> Foo ( '<STR_LIT:test>' ) . run ( result ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( events , expected ) <EOL> def test_setUp ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> pass <EOL> Foo ( ) . setUp ( ) <EOL> def test_tearDown ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> pass <EOL> Foo ( ) . tearDown ( ) <EOL> def test_id ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> pass <EOL> self . failUnless ( isinstance ( Foo ( ) . id ( ) , basestring ) ) <EOL> def test_shortDescription__no_docstring ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> pass <EOL> self . assertEqual ( Foo ( ) . shortDescription ( ) , None ) <EOL> def test_shortDescription__singleline_docstring ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> self . assertEqual ( Foo ( ) . shortDescription ( ) , "<STR_LIT>" ) <EOL> def test_shortDescription__multiline_docstring ( self ) : <EOL> class Foo ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> self . assertEqual ( Foo ( ) . shortDescription ( ) , "<STR_LIT>" ) <EOL> def test_run__uses_defaultTestResult ( self ) : <EOL> events = [ ] <EOL> class Foo ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> events . append ( '<STR_LIT:test>' ) <EOL> def defaultTestResult ( self ) : <EOL> return LoggingResult ( events ) <EOL> Foo ( '<STR_LIT:test>' ) . run ( ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT>' ] <EOL> self . assertEqual ( events , expected ) <EOL> class Test_Assertions ( TestCase ) : <EOL> def test_AlmostEqual ( self ) : <EOL> self . failUnlessAlmostEqual ( <NUM_LIT> , <NUM_LIT:1.0> ) <EOL> self . failIfAlmostEqual ( <NUM_LIT> , <NUM_LIT:1.0> ) <EOL> self . assertRaises ( AssertionError , <EOL> self . failUnlessAlmostEqual , <NUM_LIT> , <NUM_LIT:1.0> ) <EOL> self . assertRaises ( AssertionError , <EOL> self . failIfAlmostEqual , <NUM_LIT> , <NUM_LIT:1.0> ) <EOL> self . failUnlessAlmostEqual ( <NUM_LIT> , <NUM_LIT:1.0> , places = <NUM_LIT:0> ) <EOL> self . assertRaises ( AssertionError , <EOL> self . failUnlessAlmostEqual , <NUM_LIT> , <NUM_LIT:1.0> , places = <NUM_LIT:1> ) <EOL> self . failUnlessAlmostEqual ( <NUM_LIT:0> , <NUM_LIT> + <NUM_LIT> , places = <NUM_LIT:0> ) <EOL> self . failIfAlmostEqual ( <NUM_LIT:0> , <NUM_LIT> + <NUM_LIT> , places = <NUM_LIT:1> ) <EOL> self . assertRaises ( AssertionError , <EOL> self . failUnlessAlmostEqual , <NUM_LIT:0> , <NUM_LIT> + <NUM_LIT> , places = <NUM_LIT:1> ) <EOL> self . assertRaises ( AssertionError , <EOL> self . failIfAlmostEqual , <NUM_LIT:0> , <NUM_LIT> + <NUM_LIT> , places = <NUM_LIT:0> ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( Test_TestCase , Test_TestLoader , <EOL> Test_TestSuite , Test_TestResult , Test_FunctionTestCase , <EOL> Test_Assertions ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
