<s> from zope . testing import renormalizing <EOL> import doctest <EOL> import errno <EOL> import os <EOL> import re <EOL> import shutil <EOL> import stat <EOL> import tarfile <EOL> import tempfile <EOL> import zc . buildout <EOL> import zc . buildout . testing <EOL> import zc . buildout . tests <EOL> try : <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> import unittest <EOL> optionflags = ( doctest . ELLIPSIS | <EOL> doctest . NORMALIZE_WHITESPACE | <EOL> doctest . REPORT_ONLY_FIRST_FAILURE ) <EOL> def setUp ( test ) : <EOL> zc . buildout . testing . buildoutSetUp ( test ) <EOL> zc . buildout . testing . install ( '<STR_LIT>' , test ) <EOL> zc . buildout . testing . install_develop ( '<STR_LIT>' , test ) <EOL> class NonInformativeTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . dir = os . path . realpath ( tempfile . mkdtemp ( ) ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . dir ) <EOL> for var in list ( os . environ . keys ( ) ) : <EOL> if var . startswith ( '<STR_LIT>' ) : <EOL> del os . environ [ var ] <EOL> def write_file ( self , filename , contents , mode = stat . S_IREAD | stat . S_IWUSR ) : <EOL> path = os . path . join ( self . dir , filename ) <EOL> fh = open ( path , '<STR_LIT:w>' ) <EOL> fh . write ( contents ) <EOL> fh . close ( ) <EOL> os . chmod ( path , mode ) <EOL> return path <EOL> def make_recipe ( self , buildout , name , options ) : <EOL> from hexagonit . recipe . cmmi import Recipe <EOL> parts_directory_path = os . path . join ( self . dir , '<STR_LIT>' ) <EOL> try : <EOL> os . mkdir ( parts_directory_path ) <EOL> except OSError as e : <EOL> if e . errno != errno . EEXIST : <EOL> raise <EOL> bo = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : parts_directory_path , <EOL> '<STR_LIT>' : self . dir , <EOL> } <EOL> } <EOL> bo . update ( buildout ) <EOL> return Recipe ( bo , name , options ) <EOL> def test_working_directory_restored_after_failure ( self ) : <EOL> compile_directory = os . path . join ( self . dir , '<STR_LIT>' ) <EOL> os . makedirs ( compile_directory ) <EOL> recipe = self . make_recipe ( { } , '<STR_LIT:test>' , { '<STR_LIT:path>' : compile_directory } ) <EOL> os . chdir ( self . dir ) <EOL> with self . assertRaises ( zc . buildout . UserError ) : <EOL> recipe . install ( ) <EOL> self . assertEqual ( self . dir , os . getcwd ( ) ) <EOL> def test_working_directory_restored_after_success ( self ) : <EOL> compile_directory = os . path . join ( self . dir , '<STR_LIT>' ) <EOL> os . makedirs ( compile_directory ) <EOL> self . write_file ( os . path . join ( compile_directory , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . make_recipe ( { } , '<STR_LIT:test>' , { '<STR_LIT:path>' : compile_directory } ) <EOL> os . chdir ( self . dir ) <EOL> self . assertEqual ( self . dir , os . getcwd ( ) ) <EOL> def test_compile_directory_exists ( self ) : <EOL> """<STR_LIT>""" <EOL> compile_directory = os . path . join ( self . dir , '<STR_LIT>' ) <EOL> os . makedirs ( compile_directory ) <EOL> recipe = self . make_recipe ( { } , '<STR_LIT:test>' , dict ( url = "<STR_LIT>" ) ) <EOL> os . chdir ( self . dir ) <EOL> with self . assertRaises ( IOError ) : <EOL> recipe . install ( ) <EOL> def test_restart_after_failure ( self ) : <EOL> temp_directory = tempfile . mkdtemp ( dir = self . dir , prefix = "<STR_LIT>" ) <EOL> configure_path = os . path . join ( temp_directory , '<STR_LIT>' ) <EOL> self . write_file ( configure_path , '<STR_LIT>' , mode = stat . S_IRWXU ) <EOL> makefile_path = os . path . join ( temp_directory , '<STR_LIT>' ) <EOL> self . write_file ( makefile_path , '<STR_LIT>' ) <EOL> os . chdir ( temp_directory ) <EOL> ignore , tarfile_path = tempfile . mkstemp ( suffix = "<STR_LIT>" ) <EOL> tar = tarfile . open ( tarfile_path , '<STR_LIT:w>' ) <EOL> tar . add ( '<STR_LIT>' ) <EOL> tar . add ( '<STR_LIT>' ) <EOL> tar . close ( ) <EOL> recipe = self . make_recipe ( { } , '<STR_LIT:test>' , { '<STR_LIT:url>' : tarfile_path } ) <EOL> os . chdir ( self . dir ) <EOL> try : <EOL> with self . assertRaises ( zc . buildout . UserError ) : <EOL> recipe . install ( ) <EOL> with self . assertRaises ( zc . buildout . UserError ) : <EOL> recipe . install ( ) <EOL> finally : <EOL> try : <EOL> shutil . rmtree ( temp_directory ) <EOL> os . remove ( tarfile_path ) <EOL> except : <EOL> pass <EOL> def test_environment_restored_after_building_a_part ( self ) : <EOL> self . failIf ( '<STR_LIT>' in os . environ ) <EOL> self . failIf ( '<STR_LIT>' in os . environ ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( os . environ . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> recipe = self . make_recipe ( { } , '<STR_LIT:test>' , { <EOL> '<STR_LIT:url>' : '<STR_LIT>' % os . path . dirname ( __file__ ) , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> os . chdir ( self . dir ) <EOL> recipe . install ( ) <EOL> self . failIf ( '<STR_LIT>' in os . environ ) <EOL> self . failIf ( '<STR_LIT>' in os . environ ) <EOL> self . assertEqual ( os . environ . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_run__unknown_command ( self ) : <EOL> recipe = self . make_recipe ( { } , '<STR_LIT:test>' , { <EOL> '<STR_LIT:url>' : '<STR_LIT>' % os . path . dirname ( __file__ ) } ) <EOL> with self . assertRaises ( zc . buildout . UserError ) : <EOL> recipe . run ( '<STR_LIT>' ) <EOL> def test_call_script__bbb_for_callable_with_two_parameters ( self ) : <EOL> recipe = self . make_recipe ( { } , '<STR_LIT:test>' , { <EOL> '<STR_LIT:url>' : '<STR_LIT>' % os . path . dirname ( __file__ ) , <EOL> } ) <EOL> filename = os . path . join ( self . dir , '<STR_LIT>' ) <EOL> script = open ( filename , '<STR_LIT:w>' ) <EOL> script . write ( '<STR_LIT>' ) <EOL> script . close ( ) <EOL> try : <EOL> recipe . call_script ( '<STR_LIT>' % filename ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except ValueError as e : <EOL> self . assertEqual ( str ( e ) , '<STR_LIT>' ) <EOL> def test_call_script__augmented_environment_as_third_parameter ( self ) : <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:foo>' <EOL> recipe = self . make_recipe ( { } , '<STR_LIT:test>' , { <EOL> '<STR_LIT:url>' : '<STR_LIT>' % os . path . dirname ( __file__ ) , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> filename = os . path . join ( self . dir , '<STR_LIT>' ) <EOL> script = open ( filename , '<STR_LIT:w>' ) <EOL> script . write ( '<STR_LIT>' ) <EOL> script . close ( ) <EOL> try : <EOL> recipe . call_script ( '<STR_LIT>' % filename ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except ValueError as e : <EOL> self . assertEqual ( str ( e ) , '<STR_LIT>' ) <EOL> def test_suite ( ) : <EOL> suite = unittest . TestSuite ( ( <EOL> doctest . DocFileSuite ( <EOL> '<STR_LIT>' , <EOL> setUp = setUp , <EOL> tearDown = zc . buildout . testing . buildoutTearDown , <EOL> optionflags = optionflags , <EOL> checker = renormalizing . RENormalizing ( [ <EOL> ( re . compile ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) , <EOL> ( re . compile ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) , <EOL> zc . buildout . testing . normalize_path , <EOL> ] ) , <EOL> ) , <EOL> unittest . makeSuite ( NonInformativeTests ) , <EOL> ) ) <EOL> return suite </s>
