<s> import datetime <EOL> import unittest <EOL> from testtools import TestCase <EOL> from testtools . testresult . doubles import ExtendedTestResult <EOL> import subunit <EOL> import subunit . iso8601 as iso8601 <EOL> import subunit . test_results <EOL> class LoggingDecorator ( subunit . test_results . HookedTestResultDecorator ) : <EOL> def __init__ ( self , decorated ) : <EOL> self . _calls = <NUM_LIT:0> <EOL> super ( LoggingDecorator , self ) . __init__ ( decorated ) <EOL> def _before_event ( self ) : <EOL> self . _calls += <NUM_LIT:1> <EOL> class AssertBeforeTestResult ( LoggingDecorator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , decorated , test ) : <EOL> self . test = test <EOL> super ( AssertBeforeTestResult , self ) . __init__ ( decorated ) <EOL> def _before_event ( self ) : <EOL> self . test . assertEqual ( <NUM_LIT:1> , self . earlier . _calls ) <EOL> super ( AssertBeforeTestResult , self ) . _before_event ( ) <EOL> class TimeCapturingResult ( unittest . TestResult ) : <EOL> def __init__ ( self ) : <EOL> super ( TimeCapturingResult , self ) . __init__ ( ) <EOL> self . _calls = [ ] <EOL> def time ( self , a_datetime ) : <EOL> self . _calls . append ( a_datetime ) <EOL> class TestHookedTestResultDecorator ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> terminal = unittest . TestResult ( ) <EOL> asserter = AssertBeforeTestResult ( terminal , self ) <EOL> self . result = LoggingDecorator ( asserter ) <EOL> asserter . earlier = self . result <EOL> self . decorated = asserter <EOL> def tearDown ( self ) : <EOL> self . assertEqual ( <NUM_LIT:1> , self . result . _calls ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . decorated . _calls ) <EOL> def test_startTest ( self ) : <EOL> self . result . startTest ( self ) <EOL> def test_startTestRun ( self ) : <EOL> self . result . startTestRun ( ) <EOL> def test_stopTest ( self ) : <EOL> self . result . stopTest ( self ) <EOL> def test_stopTestRun ( self ) : <EOL> self . result . stopTestRun ( ) <EOL> def test_addError ( self ) : <EOL> self . result . addError ( self , subunit . RemoteError ( ) ) <EOL> def test_addError_details ( self ) : <EOL> self . result . addError ( self , details = { } ) <EOL> def test_addFailure ( self ) : <EOL> self . result . addFailure ( self , subunit . RemoteError ( ) ) <EOL> def test_addFailure_details ( self ) : <EOL> self . result . addFailure ( self , details = { } ) <EOL> def test_addSuccess ( self ) : <EOL> self . result . addSuccess ( self ) <EOL> def test_addSuccess_details ( self ) : <EOL> self . result . addSuccess ( self , details = { } ) <EOL> def test_addSkip ( self ) : <EOL> self . result . addSkip ( self , "<STR_LIT:foo>" ) <EOL> def test_addSkip_details ( self ) : <EOL> self . result . addSkip ( self , details = { } ) <EOL> def test_addExpectedFailure ( self ) : <EOL> self . result . addExpectedFailure ( self , subunit . RemoteError ( ) ) <EOL> def test_addExpectedFailure_details ( self ) : <EOL> self . result . addExpectedFailure ( self , details = { } ) <EOL> def test_addUnexpectedSuccess ( self ) : <EOL> self . result . addUnexpectedSuccess ( self ) <EOL> def test_addUnexpectedSuccess_details ( self ) : <EOL> self . result . addUnexpectedSuccess ( self , details = { } ) <EOL> def test_progress ( self ) : <EOL> self . result . progress ( <NUM_LIT:1> , subunit . PROGRESS_SET ) <EOL> def test_wasSuccessful ( self ) : <EOL> self . result . wasSuccessful ( ) <EOL> def test_shouldStop ( self ) : <EOL> self . result . shouldStop <EOL> def test_stop ( self ) : <EOL> self . result . stop ( ) <EOL> def test_time ( self ) : <EOL> self . result . time ( None ) <EOL> class TestAutoTimingTestResultDecorator ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> terminal = TimeCapturingResult ( ) <EOL> self . result = subunit . test_results . AutoTimingTestResultDecorator ( <EOL> terminal ) <EOL> self . decorated = terminal <EOL> def test_without_time_calls_time_is_called_and_not_None ( self ) : <EOL> self . result . startTest ( self ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . decorated . _calls ) ) <EOL> self . assertNotEqual ( None , self . decorated . _calls [ <NUM_LIT:0> ] ) <EOL> def test_no_time_from_progress ( self ) : <EOL> self . result . progress ( <NUM_LIT:1> , subunit . PROGRESS_CUR ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . decorated . _calls ) ) <EOL> def test_no_time_from_shouldStop ( self ) : <EOL> self . decorated . stop ( ) <EOL> self . result . shouldStop <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . decorated . _calls ) ) <EOL> def test_calling_time_inhibits_automatic_time ( self ) : <EOL> time = datetime . datetime ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , iso8601 . Utc ( ) ) <EOL> self . result . time ( time ) <EOL> self . result . startTest ( self ) <EOL> self . result . stopTest ( self ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . decorated . _calls ) ) <EOL> self . assertEqual ( time , self . decorated . _calls [ <NUM_LIT:0> ] ) <EOL> def test_calling_time_None_enables_automatic_time ( self ) : <EOL> time = datetime . datetime ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , iso8601 . Utc ( ) ) <EOL> self . result . time ( time ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . decorated . _calls ) ) <EOL> self . assertEqual ( time , self . decorated . _calls [ <NUM_LIT:0> ] ) <EOL> self . result . time ( None ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( self . decorated . _calls ) ) <EOL> self . assertEqual ( None , self . decorated . _calls [ <NUM_LIT:1> ] ) <EOL> self . result . startTest ( self ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( self . decorated . _calls ) ) <EOL> self . assertNotEqual ( None , self . decorated . _calls [ <NUM_LIT:2> ] ) <EOL> class TestTagCollapsingDecorator ( TestCase ) : <EOL> def test_tags_forwarded_outside_of_tests ( self ) : <EOL> result = ExtendedTestResult ( ) <EOL> tag_collapser = subunit . test_results . TagCollapsingDecorator ( result ) <EOL> tag_collapser . tags ( set ( [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) , set ( ) ) <EOL> self . assertEquals ( <EOL> [ ( '<STR_LIT>' , set ( [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) , set ( [ ] ) ) ] , result . _events ) <EOL> def test_tags_collapsed_inside_of_tests ( self ) : <EOL> result = ExtendedTestResult ( ) <EOL> tag_collapser = subunit . test_results . TagCollapsingDecorator ( result ) <EOL> test = subunit . RemotedTestCase ( '<STR_LIT:foo>' ) <EOL> tag_collapser . startTest ( test ) <EOL> tag_collapser . tags ( set ( [ '<STR_LIT:a>' ] ) , set ( ) ) <EOL> tag_collapser . tags ( set ( [ '<STR_LIT:b>' ] ) , set ( [ '<STR_LIT:a>' ] ) ) <EOL> tag_collapser . tags ( set ( [ '<STR_LIT:c>' ] ) , set ( ) ) <EOL> tag_collapser . stopTest ( test ) <EOL> self . assertEquals ( <EOL> [ ( '<STR_LIT>' , test ) , <EOL> ( '<STR_LIT>' , set ( [ '<STR_LIT:b>' , '<STR_LIT:c>' ] ) , set ( [ '<STR_LIT:a>' ] ) ) , <EOL> ( '<STR_LIT>' , test ) ] , <EOL> result . _events ) <EOL> def test_tags_collapsed_inside_of_tests_different_ordering ( self ) : <EOL> result = ExtendedTestResult ( ) <EOL> tag_collapser = subunit . test_results . TagCollapsingDecorator ( result ) <EOL> test = subunit . RemotedTestCase ( '<STR_LIT:foo>' ) <EOL> tag_collapser . startTest ( test ) <EOL> tag_collapser . tags ( set ( ) , set ( [ '<STR_LIT:a>' ] ) ) <EOL> tag_collapser . tags ( set ( [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) , set ( ) ) <EOL> tag_collapser . tags ( set ( [ '<STR_LIT:c>' ] ) , set ( ) ) <EOL> tag_collapser . stopTest ( test ) <EOL> self . assertEquals ( <EOL> [ ( '<STR_LIT>' , test ) , <EOL> ( '<STR_LIT>' , set ( [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ) , set ( ) ) , <EOL> ( '<STR_LIT>' , test ) ] , <EOL> result . _events ) <EOL> class TestTimeCollapsingDecorator ( TestCase ) : <EOL> def make_time ( self ) : <EOL> return datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:1> , self . getUniqueInteger ( ) , tzinfo = iso8601 . UTC ) <EOL> def test_initial_time_forwarded ( self ) : <EOL> result = ExtendedTestResult ( ) <EOL> tag_collapser = subunit . test_results . TimeCollapsingDecorator ( result ) <EOL> a_time = self . make_time ( ) <EOL> tag_collapser . time ( a_time ) <EOL> self . assertEquals ( [ ( '<STR_LIT:time>' , a_time ) ] , result . _events ) <EOL> def test_time_collapsed_to_first_and_last ( self ) : <EOL> result = ExtendedTestResult ( ) <EOL> tag_collapser = subunit . test_results . TimeCollapsingDecorator ( result ) <EOL> times = [ self . make_time ( ) for i in range ( <NUM_LIT:5> ) ] <EOL> for a_time in times : <EOL> tag_collapser . time ( a_time ) <EOL> tag_collapser . startTest ( subunit . RemotedTestCase ( '<STR_LIT:foo>' ) ) <EOL> self . assertEquals ( <EOL> [ ( '<STR_LIT:time>' , times [ <NUM_LIT:0> ] ) , ( '<STR_LIT:time>' , times [ - <NUM_LIT:1> ] ) ] , result . _events [ : - <NUM_LIT:1> ] ) <EOL> def test_only_one_time_sent ( self ) : <EOL> result = ExtendedTestResult ( ) <EOL> tag_collapser = subunit . test_results . TimeCollapsingDecorator ( result ) <EOL> a_time = self . make_time ( ) <EOL> tag_collapser . time ( a_time ) <EOL> tag_collapser . startTest ( subunit . RemotedTestCase ( '<STR_LIT:foo>' ) ) <EOL> self . assertEquals ( [ ( '<STR_LIT:time>' , a_time ) ] , result . _events [ : - <NUM_LIT:1> ] ) <EOL> def test_duplicate_times_not_sent ( self ) : <EOL> result = ExtendedTestResult ( ) <EOL> tag_collapser = subunit . test_results . TimeCollapsingDecorator ( result ) <EOL> a_time = self . make_time ( ) <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> tag_collapser . time ( a_time ) <EOL> tag_collapser . startTest ( subunit . RemotedTestCase ( '<STR_LIT:foo>' ) ) <EOL> self . assertEquals ( [ ( '<STR_LIT:time>' , a_time ) ] , result . _events [ : - <NUM_LIT:1> ] ) <EOL> def test_no_times_inserted ( self ) : <EOL> result = ExtendedTestResult ( ) <EOL> tag_collapser = subunit . test_results . TimeCollapsingDecorator ( result ) <EOL> a_time = self . make_time ( ) <EOL> tag_collapser . time ( a_time ) <EOL> foo = subunit . RemotedTestCase ( '<STR_LIT:foo>' ) <EOL> tag_collapser . startTest ( foo ) <EOL> tag_collapser . addSuccess ( foo ) <EOL> tag_collapser . stopTest ( foo ) <EOL> self . assertEquals ( <EOL> [ ( '<STR_LIT:time>' , a_time ) , <EOL> ( '<STR_LIT>' , foo ) , <EOL> ( '<STR_LIT>' , foo ) , <EOL> ( '<STR_LIT>' , foo ) ] , result . _events ) <EOL> def test_suite ( ) : <EOL> loader = subunit . tests . TestUtil . TestLoader ( ) <EOL> result = loader . loadTestsFromName ( __name__ ) <EOL> return result </s>
