<s> """<STR_LIT>""" <EOL> import sys <EOL> import doctest <EOL> from nose2 import events , loader , session <EOL> from nose2 . plugins import doctests <EOL> from nose2 . tests . _common import TestCase <EOL> class UnitTestDocTestLoader ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> tags = [ '<STR_LIT>' ] <EOL> _RUN_IN_TEMP = True <EOL> def setUp ( self ) : <EOL> self . session = session . Session ( ) <EOL> self . loader = loader . PluggableTestLoader ( self . session ) <EOL> self . plugin = doctests . DocTestLoader ( session = self . session ) <EOL> super ( UnitTestDocTestLoader , self ) . setUp ( ) <EOL> def test___init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . plugin . extensions , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_handle_file ( self ) : <EOL> """<STR_LIT>""" <EOL> doc_test = """<STR_LIT>""" <EOL> txt_event = self . _handle_file ( '<STR_LIT>' , doc_test ) <EOL> rst_event = self . _handle_file ( '<STR_LIT>' , doc_test ) <EOL> py_event = self . _handle_file ( '<STR_LIT>' , """<STR_LIT>""" ) <EOL> for event , ext in [ ( txt_event , '<STR_LIT>' ) , ( rst_event , '<STR_LIT>' ) ] : <EOL> test , = event . extraTests <EOL> self . assertTrue ( isinstance ( test , doctest . DocFileCase ) ) <EOL> self . assertEqual ( repr ( test ) , "<STR_LIT>" % ext ) <EOL> testsuite , = py_event . extraTests <EOL> test , = list ( testsuite ) <EOL> self . assertEqual ( repr ( test ) , '<STR_LIT>' ) <EOL> def test_handle_file_python_without_doctests ( self ) : <EOL> """<STR_LIT>""" <EOL> event = self . _handle_file ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> if sys . version_info >= ( <NUM_LIT:3> , <NUM_LIT:5> ) : <EOL> self . assertEqual ( event . extraTests , [ doctest . DocTestSuite ( ) ] ) <EOL> else : <EOL> self . assertEqual ( event . extraTests , [ ] ) <EOL> def _handle_file ( self , fpath , content ) : <EOL> """<STR_LIT>""" <EOL> fh = open ( fpath , "<STR_LIT:w>" ) <EOL> try : <EOL> fh . write ( content ) <EOL> finally : <EOL> fh . close ( ) <EOL> event = events . HandleFileEvent ( self . loader , fh . name , fpath , None , None ) <EOL> self . plugin . handleFile ( event ) <EOL> return event </s>
