<s> import unittest <EOL> from testtools import ( <EOL> TestCase , <EOL> content , <EOL> content_type , <EOL> ) <EOL> from testtools . compat import _b , _u <EOL> from testtools . helpers import try_import <EOL> from testtools . testresult . doubles import ( <EOL> ExtendedTestResult , <EOL> ) <EOL> fixtures = try_import ( '<STR_LIT>' ) <EOL> LoggingFixture = try_import ( '<STR_LIT>' ) <EOL> class TestFixtureSupport ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestFixtureSupport , self ) . setUp ( ) <EOL> if fixtures is None or LoggingFixture is None : <EOL> self . skipTest ( "<STR_LIT>" ) <EOL> def test_useFixture ( self ) : <EOL> fixture = LoggingFixture ( ) <EOL> class SimpleTest ( TestCase ) : <EOL> def test_foo ( self ) : <EOL> self . useFixture ( fixture ) <EOL> result = unittest . TestResult ( ) <EOL> SimpleTest ( '<STR_LIT>' ) . run ( result ) <EOL> self . assertTrue ( result . wasSuccessful ( ) ) <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , fixture . calls ) <EOL> def test_useFixture_cleanups_raise_caught ( self ) : <EOL> calls = [ ] <EOL> def raiser ( ignored ) : <EOL> calls . append ( '<STR_LIT>' ) <EOL> raise Exception ( '<STR_LIT:foo>' ) <EOL> fixture = fixtures . FunctionFixture ( lambda : None , raiser ) <EOL> class SimpleTest ( TestCase ) : <EOL> def test_foo ( self ) : <EOL> self . useFixture ( fixture ) <EOL> result = unittest . TestResult ( ) <EOL> SimpleTest ( '<STR_LIT>' ) . run ( result ) <EOL> self . assertFalse ( result . wasSuccessful ( ) ) <EOL> self . assertEqual ( [ '<STR_LIT>' ] , calls ) <EOL> def test_useFixture_details_captured ( self ) : <EOL> class DetailsFixture ( fixtures . Fixture ) : <EOL> def setUp ( self ) : <EOL> fixtures . Fixture . setUp ( self ) <EOL> self . addCleanup ( delattr , self , '<STR_LIT:content>' ) <EOL> self . content = [ _b ( '<STR_LIT>' ) ] <EOL> self . addDetail ( '<STR_LIT:content>' , <EOL> content . Content ( content_type . UTF8_TEXT , self . get_content ) ) <EOL> def get_content ( self ) : <EOL> return self . content <EOL> fixture = DetailsFixture ( ) <EOL> class SimpleTest ( TestCase ) : <EOL> def test_foo ( self ) : <EOL> self . useFixture ( fixture ) <EOL> self . addDetail ( '<STR_LIT:content>' , <EOL> content . Content ( content_type . UTF8_TEXT , lambda : [ _b ( '<STR_LIT:foo>' ) ] ) ) <EOL> result = ExtendedTestResult ( ) <EOL> SimpleTest ( '<STR_LIT>' ) . run ( result ) <EOL> self . assertEqual ( '<STR_LIT>' , result . _events [ - <NUM_LIT:2> ] [ <NUM_LIT:0> ] ) <EOL> details = result . _events [ - <NUM_LIT:2> ] [ <NUM_LIT:2> ] <EOL> self . assertEqual ( [ '<STR_LIT:content>' , '<STR_LIT>' ] , sorted ( details . keys ( ) ) ) <EOL> self . assertEqual ( '<STR_LIT:foo>' , _u ( '<STR_LIT>' ) . join ( details [ '<STR_LIT:content>' ] . iter_text ( ) ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> '<STR_LIT>' . join ( details [ '<STR_LIT>' ] . iter_text ( ) ) ) <EOL> def test_useFixture_multiple_details_captured ( self ) : <EOL> class DetailsFixture ( fixtures . Fixture ) : <EOL> def setUp ( self ) : <EOL> fixtures . Fixture . setUp ( self ) <EOL> self . addDetail ( '<STR_LIT>' , content . text_content ( "<STR_LIT:foo>" ) ) <EOL> self . addDetail ( '<STR_LIT>' , content . text_content ( "<STR_LIT:bar>" ) ) <EOL> fixture = DetailsFixture ( ) <EOL> class SimpleTest ( TestCase ) : <EOL> def test_foo ( self ) : <EOL> self . useFixture ( fixture ) <EOL> result = ExtendedTestResult ( ) <EOL> SimpleTest ( '<STR_LIT>' ) . run ( result ) <EOL> self . assertEqual ( '<STR_LIT>' , result . _events [ - <NUM_LIT:2> ] [ <NUM_LIT:0> ] ) <EOL> details = result . _events [ - <NUM_LIT:2> ] [ <NUM_LIT:2> ] <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , sorted ( details ) ) <EOL> self . assertEqual ( '<STR_LIT:foo>' , '<STR_LIT>' . join ( details [ '<STR_LIT>' ] . iter_text ( ) ) ) <EOL> self . assertEqual ( '<STR_LIT:bar>' , '<STR_LIT>' . join ( details [ '<STR_LIT>' ] . iter_text ( ) ) ) <EOL> def test_useFixture_details_captured_from_setUp ( self ) : <EOL> class BrokenFixture ( fixtures . Fixture ) : <EOL> def setUp ( self ) : <EOL> fixtures . Fixture . setUp ( self ) <EOL> self . addDetail ( '<STR_LIT:content>' , content . text_content ( "<STR_LIT>" ) ) <EOL> raise Exception ( ) <EOL> fixture = BrokenFixture ( ) <EOL> class SimpleTest ( TestCase ) : <EOL> def test_foo ( self ) : <EOL> self . useFixture ( fixture ) <EOL> result = ExtendedTestResult ( ) <EOL> SimpleTest ( '<STR_LIT>' ) . run ( result ) <EOL> self . assertEqual ( '<STR_LIT>' , result . _events [ - <NUM_LIT:2> ] [ <NUM_LIT:0> ] ) <EOL> details = result . _events [ - <NUM_LIT:2> ] [ <NUM_LIT:2> ] <EOL> self . assertEqual ( [ '<STR_LIT:content>' , '<STR_LIT>' ] , sorted ( details ) ) <EOL> self . assertEqual ( '<STR_LIT>' , '<STR_LIT>' . join ( details [ '<STR_LIT:content>' ] . iter_text ( ) ) ) <EOL> def test_suite ( ) : <EOL> from unittest import TestLoader <EOL> return TestLoader ( ) . loadTestsFromName ( __name__ ) </s>
