<s> import py , sys , ctypes , os <EOL> from pypy . tool . udir import udir <EOL> from pypy . translator . platform import CompilationError , Platform <EOL> from pypy . translator . platform import host <EOL> from pypy . translator . tool . cbuild import ExternalCompilationInfo <EOL> class TestPlatform ( object ) : <EOL> platform = host <EOL> strict_on_stderr = True <EOL> def check_res ( self , res , expected = '<STR_LIT>' ) : <EOL> assert res . out == expected <EOL> if self . strict_on_stderr : <EOL> assert res . err == '<STR_LIT>' <EOL> assert res . returncode == <NUM_LIT:0> <EOL> def test_simple_enough ( self ) : <EOL> cfile = udir . join ( '<STR_LIT>' ) <EOL> cfile . write ( '''<STR_LIT>''' ) <EOL> executable = self . platform . compile ( [ cfile ] , ExternalCompilationInfo ( ) ) <EOL> res = self . platform . execute ( executable ) <EOL> self . check_res ( res ) <EOL> def test_two_files ( self ) : <EOL> cfile = udir . join ( '<STR_LIT>' ) <EOL> cfile . write ( '''<STR_LIT>''' ) <EOL> cfile2 = udir . join ( '<STR_LIT>' ) <EOL> cfile2 . write ( '''<STR_LIT>''' ) <EOL> executable = self . platform . compile ( [ cfile , cfile2 ] , ExternalCompilationInfo ( ) ) <EOL> res = self . platform . execute ( executable ) <EOL> self . check_res ( res ) <EOL> def test_nice_errors ( self ) : <EOL> cfile = udir . join ( '<STR_LIT>' ) <EOL> cfile . write ( '<STR_LIT>' ) <EOL> try : <EOL> executable = self . platform . compile ( [ cfile ] , ExternalCompilationInfo ( ) ) <EOL> except CompilationError , e : <EOL> filename = cfile . dirpath ( ) . join ( cfile . purebasename + '<STR_LIT>' ) <EOL> assert filename . read ( '<STR_LIT:r>' ) == e . err <EOL> else : <EOL> py . test . fail ( "<STR_LIT>" ) <EOL> def test_use_eci ( self ) : <EOL> tmpdir = udir . join ( '<STR_LIT>' ) . ensure ( dir = <NUM_LIT:1> ) <EOL> hfile = tmpdir . join ( '<STR_LIT>' ) <EOL> hfile . write ( '<STR_LIT>' ) <EOL> eci = ExternalCompilationInfo ( include_dirs = [ tmpdir ] ) <EOL> cfile = udir . join ( '<STR_LIT>' ) <EOL> cfile . write ( '''<STR_LIT>''' ) <EOL> executable = self . platform . compile ( [ cfile ] , eci ) <EOL> res = self . platform . execute ( executable ) <EOL> self . check_res ( res ) <EOL> def test_standalone_library ( self ) : <EOL> tmpdir = udir . join ( '<STR_LIT>' ) . ensure ( dir = <NUM_LIT:1> ) <EOL> c_file = tmpdir . join ( '<STR_LIT>' ) <EOL> c_file . write ( '''<STR_LIT>''' ) <EOL> if sys . platform != '<STR_LIT:win32>' : <EOL> eci = ExternalCompilationInfo ( <EOL> libraries = [ '<STR_LIT:m>' ] , <EOL> ) <EOL> else : <EOL> eci = ExternalCompilationInfo ( ) <EOL> executable = self . platform . compile ( [ c_file ] , eci ) <EOL> res = self . platform . execute ( executable ) <EOL> assert res . out . startswith ( '<STR_LIT>' ) <EOL> def test_environment_inheritance ( self ) : <EOL> cmd = '<STR_LIT>' <EOL> res = self . platform . execute ( '<STR_LIT>' , [ '<STR_LIT:-c>' , cmd % <NUM_LIT:1> ] , <EOL> env = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> assert '<STR_LIT>' in res . out <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> try : <EOL> res = self . platform . execute ( '<STR_LIT>' , [ '<STR_LIT:-c>' , cmd % <NUM_LIT:2> ] ) <EOL> assert '<STR_LIT>' in res . out <EOL> finally : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> def test_equality ( ) : <EOL> class X ( Platform ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> class Y ( Platform ) : <EOL> def __init__ ( self , x ) : <EOL> self . x = x <EOL> assert X ( ) == X ( ) <EOL> assert Y ( <NUM_LIT:3> ) == Y ( <NUM_LIT:3> ) <EOL> assert Y ( <NUM_LIT:2> ) != Y ( <NUM_LIT:3> ) </s>
