<s> import py <EOL> from pypy . rpython . test . tool import BaseRtypingTest , LLRtypeMixin , OORtypeMixin <EOL> from pypy . tool . udir import udir <EOL> import os <EOL> exec '<STR_LIT>' % os . name <EOL> def setup_module ( module ) : <EOL> testf = udir . join ( '<STR_LIT>' ) <EOL> module . path = testf . strpath <EOL> class BaseTestPosix ( BaseRtypingTest ) : <EOL> def setup_method ( self , meth ) : <EOL> testfile = open ( path , '<STR_LIT:wb>' ) <EOL> testfile . write ( '<STR_LIT>' ) <EOL> testfile . close ( ) <EOL> def test_open ( self ) : <EOL> def f ( ) : <EOL> ff = posix . open ( path , posix . O_RDONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> return ff <EOL> func = self . interpret ( f , [ ] ) <EOL> assert type ( func ) == int <EOL> def test_fstat ( self ) : <EOL> def fo ( fi ) : <EOL> g = posix . fstat ( fi ) <EOL> return g <EOL> fi = os . open ( path , os . O_RDONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> func = self . interpret ( fo , [ fi ] ) <EOL> stat = os . fstat ( fi ) <EOL> for i in range ( len ( stat ) ) : <EOL> assert long ( getattr ( func , '<STR_LIT>' % i ) ) == stat [ i ] <EOL> def test_stat ( self ) : <EOL> def fo ( ) : <EOL> g = posix . stat ( path ) <EOL> return g <EOL> func = self . interpret ( fo , [ ] ) <EOL> stat = os . stat ( path ) <EOL> for i in range ( len ( stat ) ) : <EOL> assert long ( getattr ( func , '<STR_LIT>' % i ) ) == stat [ i ] <EOL> def test_times ( self ) : <EOL> import py ; py . test . skip ( "<STR_LIT>" ) <EOL> from pypy . rpython . test . test_llinterp import interpret <EOL> times = interpret ( lambda : posix . times ( ) , ( ) ) <EOL> assert isinstance ( times , tuple ) <EOL> assert len ( times ) == <NUM_LIT:5> <EOL> for value in times : <EOL> assert isinstance ( value , int ) <EOL> def test_lseek ( self ) : <EOL> def f ( fi , pos ) : <EOL> posix . lseek ( fi , pos , <NUM_LIT:0> ) <EOL> fi = os . open ( path , os . O_RDONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> func = self . interpret ( f , [ fi , <NUM_LIT:5> ] ) <EOL> res = os . read ( fi , <NUM_LIT:2> ) <EOL> assert res == '<STR_LIT>' <EOL> def test_isatty ( self ) : <EOL> def f ( fi ) : <EOL> posix . isatty ( fi ) <EOL> fi = os . open ( path , os . O_RDONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> func = self . interpret ( f , [ fi ] ) <EOL> assert not func <EOL> os . close ( fi ) <EOL> func = self . interpret ( f , [ fi ] ) <EOL> assert not func <EOL> def test_getcwd ( self ) : <EOL> def f ( ) : <EOL> return posix . getcwd ( ) <EOL> res = self . interpret ( f , [ ] ) <EOL> cwd = os . getcwd ( ) <EOL> assert self . ll_to_string ( res ) == cwd <EOL> def test_write ( self ) : <EOL> def f ( fi ) : <EOL> if fi > <NUM_LIT:0> : <EOL> text = '<STR_LIT>' <EOL> else : <EOL> text = '<STR_LIT>' <EOL> return posix . write ( fi , text ) <EOL> fi = os . open ( path , os . O_WRONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> text = '<STR_LIT>' <EOL> func = self . interpret ( f , [ fi ] ) <EOL> os . close ( fi ) <EOL> fi = os . open ( path , os . O_RDONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> res = os . read ( fi , <NUM_LIT:20> ) <EOL> assert res == text <EOL> def test_read ( self ) : <EOL> def f ( fi , len ) : <EOL> return posix . read ( fi , len ) <EOL> fi = os . open ( path , os . O_WRONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> text = '<STR_LIT>' <EOL> os . write ( fi , text ) <EOL> os . close ( fi ) <EOL> fi = os . open ( path , os . O_RDONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> res = self . interpret ( f , [ fi , <NUM_LIT:20> ] ) <EOL> assert self . ll_to_string ( res ) == text <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_chown ( self ) : <EOL> f = open ( path , "<STR_LIT:w>" ) <EOL> f . write ( "<STR_LIT>" ) <EOL> f . close ( ) <EOL> def f ( ) : <EOL> try : <EOL> posix . chown ( path , os . getuid ( ) , os . getgid ( ) ) <EOL> return <NUM_LIT:1> <EOL> except OSError : <EOL> return <NUM_LIT:2> <EOL> assert self . interpret ( f , [ ] ) == <NUM_LIT:1> <EOL> os . unlink ( path ) <EOL> assert self . interpret ( f , [ ] ) == <NUM_LIT:2> <EOL> def test_close ( self ) : <EOL> def f ( fi ) : <EOL> return posix . close ( fi ) <EOL> fi = os . open ( path , os . O_WRONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> text = '<STR_LIT>' <EOL> os . write ( fi , text ) <EOL> res = self . interpret ( f , [ fi ] ) <EOL> raises ( OSError , os . fstat , fi ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_ftruncate ( self ) : <EOL> def f ( fi , len ) : <EOL> os . ftruncate ( fi , len ) <EOL> fi = os . open ( path , os . O_RDWR , <NUM_LIT:0> <NUM_LIT> ) <EOL> func = self . interpret ( f , [ fi , <NUM_LIT:6> ] ) <EOL> assert os . fstat ( fi ) . st_size == <NUM_LIT:6> <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_getuid ( self ) : <EOL> def f ( ) : <EOL> return os . getuid ( ) <EOL> assert self . interpret ( f , [ ] ) == f ( ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_getgid ( self ) : <EOL> def f ( ) : <EOL> return os . getgid ( ) <EOL> assert self . interpret ( f , [ ] ) == f ( ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_os_setuid ( self ) : <EOL> def f ( ) : <EOL> os . setuid ( os . getuid ( ) ) <EOL> return os . getuid ( ) <EOL> assert self . interpret ( f , [ ] ) == f ( ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_os_sysconf ( self ) : <EOL> def f ( i ) : <EOL> return os . sysconf ( i ) <EOL> assert self . interpret ( f , [ <NUM_LIT> ] ) == f ( <NUM_LIT> ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_os_chroot ( self ) : <EOL> def f ( ) : <EOL> try : <EOL> os . chroot ( '<STR_LIT>' ) <EOL> except OSError : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> assert self . interpret ( f , [ ] ) == <NUM_LIT:1> <EOL> def test_os_wstar ( self ) : <EOL> from pypy . rpython . module . ll_os import RegisterOs <EOL> for name in RegisterOs . w_star : <EOL> if not hasattr ( os , name ) : <EOL> continue <EOL> def fun ( s ) : <EOL> return getattr ( os , name ) ( s ) <EOL> for value in [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:255> ] : <EOL> res = self . interpret ( fun , [ value ] ) <EOL> assert res == fun ( value ) <EOL> class TestLLtype ( BaseTestPosix , LLRtypeMixin ) : <EOL> pass <EOL> class TestOOtype ( BaseTestPosix , OORtypeMixin ) : <EOL> def test_fstat ( self ) : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> def test_os_chroot ( self ) : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> def test_stat ( self ) : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> def test_chown ( self ) : <EOL> py . test . skip ( "<STR_LIT>" ) </s>
