<s> import autopath <EOL> import py <EOL> import os , time , sys <EOL> from pypy . tool . udir import udir <EOL> from pypy . rlib . rarithmetic import r_longlong <EOL> from pypy . translator . c . test . test_genc import compile <EOL> posix = __import__ ( os . name ) <EOL> def test_time_clock ( ) : <EOL> def does_stuff ( ) : <EOL> return time . clock ( ) <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> t0 = time . clock ( ) <EOL> t1 = f1 ( ) <EOL> t2 = time . clock ( ) <EOL> t3 = f1 ( ) <EOL> t4 = time . clock ( ) <EOL> t5 = f1 ( ) <EOL> t6 = time . clock ( ) <EOL> assert <NUM_LIT:0> <= t2 - t0 <EOL> assert <NUM_LIT:0> <= t3 - t1 <= t4 - t0 <EOL> assert <NUM_LIT:0> <= t4 - t2 <= t5 - t1 <= t6 - t0 <EOL> assert <NUM_LIT:0> <= t5 - t3 <= t6 - t2 <EOL> assert <NUM_LIT:0> <= t6 - t4 <EOL> def test_time_sleep ( ) : <EOL> def does_nothing ( ) : <EOL> time . sleep ( <NUM_LIT> ) <EOL> f1 = compile ( does_nothing , [ ] ) <EOL> t0 = time . time ( ) <EOL> f1 ( ) <EOL> t1 = time . time ( ) <EOL> assert t0 <= t1 <EOL> assert t1 - t0 >= <NUM_LIT> <EOL> def test_os_open ( ) : <EOL> tmpfile = str ( udir . join ( '<STR_LIT>' ) ) <EOL> def does_stuff ( ) : <EOL> fd = os . open ( tmpfile , os . O_WRONLY | os . O_CREAT , <NUM_LIT:0> <NUM_LIT> ) <EOL> os . close ( fd ) <EOL> return fd <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> fd = f1 ( ) <EOL> assert os . path . exists ( tmpfile ) <EOL> def test_failing_os_open ( ) : <EOL> tmpfile = str ( udir . join ( '<STR_LIT>' ) ) <EOL> def does_stuff ( ) : <EOL> fd = os . open ( tmpfile , os . O_RDONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> return fd <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> py . test . raises ( OSError , f1 ) <EOL> assert not os . path . exists ( tmpfile ) <EOL> def test_open_read_write_seek_close ( ) : <EOL> filename = str ( udir . join ( '<STR_LIT>' ) ) <EOL> def does_stuff ( ) : <EOL> fd = os . open ( filename , os . O_WRONLY | os . O_CREAT , <NUM_LIT:0> <NUM_LIT> ) <EOL> count = os . write ( fd , "<STR_LIT>" ) <EOL> assert count == len ( "<STR_LIT>" ) <EOL> os . close ( fd ) <EOL> fd = os . open ( filename , os . O_RDONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> result = os . lseek ( fd , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> assert result == <NUM_LIT:1> <EOL> data = os . read ( fd , <NUM_LIT> ) <EOL> assert data == "<STR_LIT>" <EOL> os . close ( fd ) <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> f1 ( ) <EOL> assert open ( filename , '<STR_LIT:r>' ) . read ( ) == "<STR_LIT>" <EOL> os . unlink ( filename ) <EOL> def test_big_read ( ) : <EOL> filename = str ( udir . join ( '<STR_LIT>' ) ) <EOL> def does_stuff ( ) : <EOL> fd = os . open ( filename , os . O_WRONLY | os . O_CREAT , <NUM_LIT:0> <NUM_LIT> ) <EOL> count = os . write ( fd , "<STR_LIT>" ) <EOL> os . close ( fd ) <EOL> fd = os . open ( filename , os . O_RDONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> data = os . read ( fd , <NUM_LIT> ) <EOL> os . close ( fd ) <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> f1 ( ) <EOL> os . unlink ( filename ) <EOL> def test_ftruncate ( ) : <EOL> if not hasattr ( os , '<STR_LIT>' ) : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> filename = str ( udir . join ( '<STR_LIT>' ) ) <EOL> def does_stuff ( ) : <EOL> fd = os . open ( filename , os . O_WRONLY | os . O_CREAT , <NUM_LIT:0> <NUM_LIT> ) <EOL> os . write ( fd , "<STR_LIT>" ) <EOL> os . close ( fd ) <EOL> fd = os . open ( filename , os . O_RDWR , <NUM_LIT:0> <NUM_LIT> ) <EOL> os . ftruncate ( fd , <NUM_LIT:5> ) <EOL> data = os . read ( fd , <NUM_LIT> ) <EOL> assert data == "<STR_LIT:hello>" <EOL> os . close ( fd ) <EOL> does_stuff ( ) <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> f1 ( ) <EOL> os . unlink ( filename ) <EOL> def test_largefile ( ) : <EOL> if not hasattr ( os , '<STR_LIT>' ) : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> from pypy . module . posix . test . test_posix2 import need_sparse_files <EOL> need_sparse_files ( ) <EOL> filename = str ( udir . join ( '<STR_LIT>' ) ) <EOL> r4800000000 = r_longlong ( <NUM_LIT> L ) <EOL> r4900000000 = r_longlong ( <NUM_LIT> L ) <EOL> r5000000000 = r_longlong ( <NUM_LIT> L ) <EOL> r5200000000 = r_longlong ( <NUM_LIT> L ) <EOL> r9900000000 = r_longlong ( <NUM_LIT> L ) <EOL> r10000000000 = r_longlong ( <NUM_LIT> L ) <EOL> def does_stuff ( ) : <EOL> fd = os . open ( filename , os . O_RDWR | os . O_CREAT , <NUM_LIT:0> <NUM_LIT> ) <EOL> os . ftruncate ( fd , r10000000000 ) <EOL> res = os . lseek ( fd , r9900000000 , <NUM_LIT:0> ) <EOL> assert res == r9900000000 <EOL> res = os . lseek ( fd , - r5000000000 , <NUM_LIT:1> ) <EOL> assert res == r4900000000 <EOL> res = os . lseek ( fd , - r5200000000 , <NUM_LIT:2> ) <EOL> assert res == r4800000000 <EOL> os . close ( fd ) <EOL> st = os . stat ( filename ) <EOL> assert st . st_size == r10000000000 <EOL> does_stuff ( ) <EOL> os . unlink ( filename ) <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> f1 ( ) <EOL> os . unlink ( filename ) <EOL> def test_os_access ( ) : <EOL> filename = str ( py . magic . autopath ( ) ) <EOL> def call_access ( path , mode ) : <EOL> return os . access ( path , mode ) <EOL> f = compile ( call_access , [ str , int ] ) <EOL> for mode in os . R_OK , os . W_OK , os . X_OK , ( os . R_OK | os . W_OK | os . X_OK ) : <EOL> assert f ( filename , mode ) == os . access ( filename , mode ) <EOL> def test_os_stat ( ) : <EOL> filename = str ( py . magic . autopath ( ) ) <EOL> has_blksize = hasattr ( os . stat_result , '<STR_LIT>' ) <EOL> has_blocks = hasattr ( os . stat_result , '<STR_LIT>' ) <EOL> def call_stat ( ) : <EOL> st = os . stat ( filename ) <EOL> res = ( st [ <NUM_LIT:0> ] , st . st_ino , st . st_ctime ) <EOL> if has_blksize : res += ( st . st_blksize , ) <EOL> if has_blocks : res += ( st . st_blocks , ) <EOL> return res <EOL> f = compile ( call_stat , [ ] ) <EOL> res = f ( ) <EOL> assert res [ <NUM_LIT:0> ] == os . stat ( filename ) . st_mode <EOL> assert res [ <NUM_LIT:1> ] == os . stat ( filename ) . st_ino <EOL> st_ctime = res [ <NUM_LIT:2> ] <EOL> if isinstance ( st_ctime , float ) : <EOL> assert st_ctime == os . stat ( filename ) . st_ctime <EOL> else : <EOL> assert st_ctime == int ( os . stat ( filename ) . st_ctime ) <EOL> if has_blksize : <EOL> assert res [ <NUM_LIT:3> ] == os . stat ( filename ) . st_blksize <EOL> if has_blocks : <EOL> assert res [ <NUM_LIT:4> ] == os . stat ( filename ) . st_blocks <EOL> def test_os_stat_raises_winerror ( ) : <EOL> if sys . platform != '<STR_LIT:win32>' : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> def call_stat ( ) : <EOL> try : <EOL> os . stat ( "<STR_LIT>" ) <EOL> except WindowsError , e : <EOL> return e . winerror <EOL> f = compile ( call_stat , [ ] ) <EOL> res = f ( ) <EOL> expected = call_stat ( ) <EOL> assert res == expected <EOL> def test_os_fstat ( ) : <EOL> if os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) . startswith ( '<STR_LIT>' ) : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> filename = str ( py . magic . autopath ( ) ) <EOL> def call_fstat ( ) : <EOL> fd = os . open ( filename , os . O_RDONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> st = os . fstat ( fd ) <EOL> os . close ( fd ) <EOL> return ( st . st_mode , st [ <NUM_LIT:1> ] , st . st_mtime ) <EOL> f = compile ( call_fstat , [ ] ) <EOL> osstat = os . stat ( filename ) <EOL> st_mode , st_ino , st_mtime = f ( ) <EOL> assert st_mode == osstat . st_mode <EOL> if sys . platform != '<STR_LIT:win32>' : <EOL> assert st_ino == osstat . st_ino <EOL> if isinstance ( st_mtime , float ) : <EOL> assert st_mtime == osstat . st_mtime <EOL> else : <EOL> assert st_mtime == int ( osstat . st_mtime ) <EOL> def test_os_isatty ( ) : <EOL> def call_isatty ( fd ) : <EOL> return os . isatty ( fd ) <EOL> f = compile ( call_isatty , [ int ] ) <EOL> assert f ( <NUM_LIT:0> ) == os . isatty ( <NUM_LIT:0> ) <EOL> assert f ( <NUM_LIT:1> ) == os . isatty ( <NUM_LIT:1> ) <EOL> assert f ( <NUM_LIT:2> ) == os . isatty ( <NUM_LIT:2> ) <EOL> def test_getcwd ( ) : <EOL> def does_stuff ( ) : <EOL> return os . getcwd ( ) <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> res = f1 ( ) <EOL> assert res == os . getcwd ( ) <EOL> def test_strerror ( ) : <EOL> def does_stuff ( ) : <EOL> return os . strerror ( <NUM_LIT:2> ) <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> res = f1 ( ) <EOL> assert res == os . strerror ( <NUM_LIT:2> ) <EOL> def test_system ( ) : <EOL> def does_stuff ( cmd ) : <EOL> return os . system ( cmd ) <EOL> f1 = compile ( does_stuff , [ str ] ) <EOL> res = f1 ( "<STR_LIT>" ) <EOL> assert res == <NUM_LIT:0> <EOL> def test_math_pow ( ) : <EOL> import math <EOL> def fn ( x , y ) : <EOL> return math . pow ( x , y ) <EOL> f = compile ( fn , [ float , float ] ) <EOL> assert f ( <NUM_LIT> , <NUM_LIT> ) == math . pow ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert f ( <NUM_LIT> , <NUM_LIT> ) == math . pow ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert f ( <NUM_LIT> , <NUM_LIT:0.0> ) == math . pow ( <NUM_LIT> , <NUM_LIT:0.0> ) <EOL> assert f ( <NUM_LIT> , - <NUM_LIT:1.0> ) == math . pow ( <NUM_LIT> , - <NUM_LIT:1.0> ) <EOL> assert f ( <NUM_LIT> , - <NUM_LIT> ) == math . pow ( <NUM_LIT> , - <NUM_LIT> ) <EOL> assert f ( <NUM_LIT> , <NUM_LIT:0.5> ) == math . pow ( <NUM_LIT> , <NUM_LIT:0.5> ) <EOL> assert f ( <NUM_LIT> , <NUM_LIT:0.5> ) == math . pow ( <NUM_LIT> , <NUM_LIT:0.5> ) <EOL> def test_math_frexp ( ) : <EOL> from math import frexp <EOL> def fn ( x ) : <EOL> return frexp ( x ) <EOL> f = compile ( fn , [ float ] ) <EOL> assert f ( <NUM_LIT> ) == frexp ( <NUM_LIT> ) <EOL> def test_math_modf ( ) : <EOL> from math import modf <EOL> def fn ( x ) : <EOL> return modf ( x ) <EOL> f = compile ( fn , [ float ] ) <EOL> assert f ( <NUM_LIT> ) == modf ( <NUM_LIT> ) <EOL> def test_math_hypot ( ) : <EOL> from math import hypot <EOL> def fn ( x , y ) : <EOL> return hypot ( x , y ) <EOL> f = compile ( fn , [ float , float ] ) <EOL> assert f ( <NUM_LIT> , <NUM_LIT> ) == hypot ( <NUM_LIT> , <NUM_LIT> ) <EOL> simple_math_functions = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> def math_function_test ( funcname ) : <EOL> import random <EOL> import math <EOL> mathfn = getattr ( math , funcname ) <EOL> print funcname , <EOL> def fn ( x ) : <EOL> return mathfn ( x ) <EOL> f = compile ( fn , [ float ] ) <EOL> for x in [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.5> , <NUM_LIT> ] : <EOL> print x <EOL> assert ( funcname , f ( x ) ) == ( funcname , mathfn ( x ) ) <EOL> def test_simple_math_functions ( ) : <EOL> for funcname in simple_math_functions : <EOL> yield math_function_test , funcname <EOL> def test_math_errors ( ) : <EOL> import math <EOL> def fn ( x ) : <EOL> return math . log ( x ) <EOL> f = compile ( fn , [ float ] ) <EOL> assert f ( math . e ) == math . log ( math . e ) <EOL> def check ( mathf , f , v ) : <EOL> try : <EOL> r = mathf ( v ) <EOL> except ( OverflowError , ValueError ) , e : <EOL> py . test . raises ( e . __class__ , f , v ) <EOL> else : <EOL> if r != r : <EOL> u = f ( v ) <EOL> assert u != u <EOL> else : <EOL> u = f ( v ) <EOL> assert u == r <EOL> check ( math . log , f , - <NUM_LIT:1.0> ) <EOL> check ( math . log , f , <NUM_LIT:0.0> ) <EOL> def fmod1_0 ( y ) : <EOL> return math . fmod ( <NUM_LIT:1.0> , y ) <EOL> f = compile ( fmod1_0 , [ float ] ) <EOL> check ( fmod1_0 , f , <NUM_LIT:0.0> ) <EOL> def test_os_path_exists ( ) : <EOL> tmpfile = str ( udir . join ( '<STR_LIT>' ) ) <EOL> def fn ( ) : <EOL> return os . path . exists ( tmpfile ) <EOL> f = compile ( fn , [ ] ) <EOL> open ( tmpfile , '<STR_LIT:w>' ) . close ( ) <EOL> assert f ( ) == True <EOL> os . unlink ( tmpfile ) <EOL> assert f ( ) == False <EOL> def test_os_path_isdir ( ) : <EOL> directory = "<STR_LIT>" <EOL> def fn ( ) : <EOL> return os . path . isdir ( directory ) <EOL> f = compile ( fn , [ ] ) <EOL> assert f ( ) == True <EOL> directory = "<STR_LIT>" <EOL> def fn ( ) : <EOL> return os . path . isdir ( directory ) <EOL> f = compile ( fn , [ ] ) <EOL> assert f ( ) == False <EOL> def test_time_time ( ) : <EOL> import time <EOL> def fn ( ) : <EOL> return time . time ( ) <EOL> f = compile ( fn , [ ] ) <EOL> t0 = time . time ( ) <EOL> res = fn ( ) <EOL> t1 = time . time ( ) <EOL> assert t0 <= res <= t1 <EOL> def test_rarith_parts_to_float ( ) : <EOL> from pypy . rlib . rarithmetic import parts_to_float <EOL> def fn ( sign , beforept , afterpt , exponent ) : <EOL> return parts_to_float ( sign , beforept , afterpt , exponent ) <EOL> f = compile ( fn , [ str , str , str , str ] ) <EOL> data = [ <EOL> ( ( "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT>" ) , <NUM_LIT:1.0> ) , <EOL> ( ( "<STR_LIT:->" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT>" ) , - <NUM_LIT:1.0> ) , <EOL> ( ( "<STR_LIT:->" , "<STR_LIT:1>" , "<STR_LIT:5>" , "<STR_LIT>" ) , - <NUM_LIT> ) , <EOL> ( ( "<STR_LIT:->" , "<STR_LIT:1>" , "<STR_LIT:5>" , "<STR_LIT:2>" ) , - <NUM_LIT> ) , <EOL> ( ( "<STR_LIT:->" , "<STR_LIT:1>" , "<STR_LIT:5>" , "<STR_LIT>" ) , - <NUM_LIT> ) , <EOL> ( ( "<STR_LIT:->" , "<STR_LIT:1>" , "<STR_LIT:5>" , "<STR_LIT>" ) , - <NUM_LIT> ) , <EOL> ] <EOL> for parts , val in data : <EOL> assert f ( * parts ) == val <EOL> def test_rarith_formatd ( ) : <EOL> from pypy . rlib . rarithmetic import formatd <EOL> def fn ( x ) : <EOL> return formatd ( "<STR_LIT>" , x ) <EOL> f = compile ( fn , [ float ] ) <EOL> assert f ( <NUM_LIT:0.0> ) == "<STR_LIT>" <EOL> assert f ( <NUM_LIT> ) == "<STR_LIT>" <EOL> assert f ( <NUM_LIT> ) == "<STR_LIT>" <EOL> def test_rarith_float_to_str ( ) : <EOL> def fn ( f ) : <EOL> return str ( f ) <EOL> f = compile ( fn , [ float ] ) <EOL> res = f ( <NUM_LIT> ) <EOL> assert eval ( res ) == <NUM_LIT> <EOL> def test_os_unlink ( ) : <EOL> tmpfile = str ( udir . join ( '<STR_LIT>' ) ) <EOL> def fn ( ) : <EOL> os . unlink ( tmpfile ) <EOL> f = compile ( fn , [ ] ) <EOL> open ( tmpfile , '<STR_LIT:w>' ) . close ( ) <EOL> fn ( ) <EOL> assert not os . path . exists ( tmpfile ) <EOL> def test_chdir ( ) : <EOL> def does_stuff ( path ) : <EOL> os . chdir ( path ) <EOL> f1 = compile ( does_stuff , [ str ] ) <EOL> curdir = os . getcwd ( ) <EOL> try : <EOL> os . chdir ( '<STR_LIT:..>' ) <EOL> except : pass <EOL> f1 ( curdir ) <EOL> assert curdir == os . getcwd ( ) <EOL> def test_mkdir_rmdir ( ) : <EOL> def does_stuff ( path , delete ) : <EOL> if delete : <EOL> os . rmdir ( path ) <EOL> else : <EOL> os . mkdir ( path , <NUM_LIT:0> <NUM_LIT> ) <EOL> f1 = compile ( does_stuff , [ str , bool ] ) <EOL> dirname = str ( udir . join ( '<STR_LIT>' ) ) <EOL> f1 ( dirname , False ) <EOL> assert os . path . exists ( dirname ) and os . path . isdir ( dirname ) <EOL> f1 ( dirname , True ) <EOL> assert not os . path . exists ( dirname ) <EOL> def test_strerror ( ) : <EOL> def does_stuff ( n ) : <EOL> return os . strerror ( n ) <EOL> f1 = compile ( does_stuff , [ int ] ) <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> res = f1 ( i ) <EOL> assert res == os . strerror ( i ) <EOL> def test_pipe_dup_dup2 ( ) : <EOL> def does_stuff ( ) : <EOL> a , b = os . pipe ( ) <EOL> c = os . dup ( a ) <EOL> d = os . dup ( b ) <EOL> assert a != b <EOL> assert a != c <EOL> assert a != d <EOL> assert b != c <EOL> assert b != d <EOL> assert c != d <EOL> os . close ( c ) <EOL> os . dup2 ( d , c ) <EOL> e , f = os . pipe ( ) <EOL> assert e != a <EOL> assert e != b <EOL> assert e != c <EOL> assert e != d <EOL> assert f != a <EOL> assert f != b <EOL> assert f != c <EOL> assert f != d <EOL> assert f != e <EOL> os . close ( a ) <EOL> os . close ( b ) <EOL> os . close ( c ) <EOL> os . close ( d ) <EOL> os . close ( e ) <EOL> os . close ( f ) <EOL> return <NUM_LIT> <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> res = f1 ( ) <EOL> assert res == <NUM_LIT> <EOL> def test_os_chmod ( ) : <EOL> tmpfile = str ( udir . join ( '<STR_LIT>' ) ) <EOL> f = open ( tmpfile , '<STR_LIT:w>' ) <EOL> f . close ( ) <EOL> tmpfile2 = str ( udir . join ( '<STR_LIT>' ) ) <EOL> f = open ( tmpfile2 , '<STR_LIT:w>' ) <EOL> f . close ( ) <EOL> def does_stuff ( mode ) : <EOL> os . chmod ( tmpfile , mode ) <EOL> f1 = compile ( does_stuff , [ int ] ) <EOL> f1 ( <NUM_LIT> ) <EOL> os . chmod ( tmpfile2 , <NUM_LIT> ) <EOL> assert os . stat ( tmpfile ) . st_mode & <NUM_LIT:0> <NUM_LIT> == os . stat ( tmpfile2 ) . st_mode & <NUM_LIT:0> <NUM_LIT> <EOL> f1 ( <NUM_LIT:0> <NUM_LIT> ) <EOL> os . chmod ( tmpfile2 , <NUM_LIT:0> <NUM_LIT> ) <EOL> assert os . stat ( tmpfile ) . st_mode & <NUM_LIT:0> <NUM_LIT> == os . stat ( tmpfile2 ) . st_mode & <NUM_LIT:0> <NUM_LIT> <EOL> def test_os_rename ( ) : <EOL> tmpfile1 = str ( udir . join ( '<STR_LIT>' ) ) <EOL> tmpfile2 = str ( udir . join ( '<STR_LIT>' ) ) <EOL> f = open ( tmpfile1 , '<STR_LIT:w>' ) <EOL> f . close ( ) <EOL> def does_stuff ( ) : <EOL> os . rename ( tmpfile1 , tmpfile2 ) <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> f1 ( ) <EOL> assert os . path . exists ( tmpfile2 ) <EOL> assert not os . path . exists ( tmpfile1 ) <EOL> def test_os_umask ( ) : <EOL> def does_stuff ( ) : <EOL> mask1 = os . umask ( <NUM_LIT:0> <NUM_LIT> ) <EOL> mask2 = os . umask ( mask1 ) <EOL> return mask2 <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> res = f1 ( ) <EOL> assert res == does_stuff ( ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_os_getpid ( ) : <EOL> def does_stuff ( ) : <EOL> return os . getpid ( ) <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> res = f1 ( ) <EOL> assert res == os . getpid ( ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_os_getpgrp ( ) : <EOL> def does_stuff ( ) : <EOL> return os . getpgrp ( ) <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> res = f1 ( ) <EOL> assert res == os . getpgrp ( ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_os_setpgrp ( ) : <EOL> def does_stuff ( ) : <EOL> return os . setpgrp ( ) <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> res = f1 ( ) <EOL> assert res == os . setpgrp ( ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_links ( ) : <EOL> import stat <EOL> tmpfile1 = str ( udir . join ( '<STR_LIT>' ) ) <EOL> tmpfile2 = str ( udir . join ( '<STR_LIT>' ) ) <EOL> tmpfile3 = str ( udir . join ( '<STR_LIT>' ) ) <EOL> f = open ( tmpfile1 , '<STR_LIT:w>' ) <EOL> f . close ( ) <EOL> def does_stuff ( ) : <EOL> os . symlink ( tmpfile1 , tmpfile2 ) <EOL> os . link ( tmpfile1 , tmpfile3 ) <EOL> assert os . readlink ( tmpfile2 ) == tmpfile1 <EOL> flag = <NUM_LIT:0> <EOL> st = os . lstat ( tmpfile1 ) <EOL> flag = flag * <NUM_LIT:10> + stat . S_ISREG ( st [ <NUM_LIT:0> ] ) <EOL> flag = flag * <NUM_LIT:10> + stat . S_ISLNK ( st [ <NUM_LIT:0> ] ) <EOL> st = os . lstat ( tmpfile2 ) <EOL> flag = flag * <NUM_LIT:10> + stat . S_ISREG ( st [ <NUM_LIT:0> ] ) <EOL> flag = flag * <NUM_LIT:10> + stat . S_ISLNK ( st [ <NUM_LIT:0> ] ) <EOL> st = os . lstat ( tmpfile3 ) <EOL> flag = flag * <NUM_LIT:10> + stat . S_ISREG ( st [ <NUM_LIT:0> ] ) <EOL> flag = flag * <NUM_LIT:10> + stat . S_ISLNK ( st [ <NUM_LIT:0> ] ) <EOL> return flag <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> res = f1 ( ) <EOL> assert res == <NUM_LIT> <EOL> assert os . path . islink ( tmpfile2 ) <EOL> assert not os . path . islink ( tmpfile3 ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_fork ( ) : <EOL> def does_stuff ( ) : <EOL> pid = os . fork ( ) <EOL> if pid == <NUM_LIT:0> : <EOL> os . _exit ( <NUM_LIT:4> ) <EOL> pid1 , status1 = os . waitpid ( pid , <NUM_LIT:0> ) <EOL> assert pid1 == pid <EOL> return status1 <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> status1 = f1 ( ) <EOL> assert os . WIFEXITED ( status1 ) <EOL> assert os . WEXITSTATUS ( status1 ) == <NUM_LIT:4> <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_kill ( ) : <EOL> import signal <EOL> def does_stuff ( ) : <EOL> pid = os . fork ( ) <EOL> if pid == <NUM_LIT:0> : <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> os . _exit ( <NUM_LIT:4> ) <EOL> os . kill ( pid , signal . SIGTERM ) <EOL> pid1 , status1 = os . waitpid ( pid , <NUM_LIT:0> ) <EOL> assert pid1 == pid <EOL> return status1 <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> status1 = f1 ( ) <EOL> assert os . WIFSIGNALED ( status1 ) <EOL> assert os . WTERMSIG ( status1 ) == signal . SIGTERM <EOL> elif hasattr ( os , '<STR_LIT>' ) : <EOL> def test_waitpid ( ) : <EOL> prog = str ( sys . executable ) <EOL> def does_stuff ( ) : <EOL> args = [ prog ] <EOL> args . append ( '<STR_LIT:-c>' ) <EOL> args . append ( '<STR_LIT>' ) <EOL> pid = os . spawnv ( os . P_NOWAIT , prog , args ) <EOL> pid1 , status1 = os . waitpid ( pid , <NUM_LIT:0> ) <EOL> assert pid1 == pid <EOL> return status1 <EOL> f1 = compile ( does_stuff , [ ] ) <EOL> status1 = f1 ( ) <EOL> assert status1 >> <NUM_LIT:8> == <NUM_LIT:4> <EOL> def _real_getenv ( var ) : <EOL> cmd = '''<STR_LIT>''' % ( <EOL> sys . executable , var ) <EOL> g = os . popen ( cmd , '<STR_LIT:r>' ) <EOL> output = g . read ( ) . strip ( ) <EOL> g . close ( ) <EOL> if output == '<STR_LIT:F>' : <EOL> return None <EOL> elif output . startswith ( '<STR_LIT:T>' ) : <EOL> return output [ <NUM_LIT:1> : ] <EOL> else : <EOL> raise ValueError , '<STR_LIT>' % ( output , ) <EOL> def test_dictlike_environ_getitem ( ) : <EOL> def fn ( s ) : <EOL> try : <EOL> return os . environ [ s ] <EOL> except KeyError : <EOL> return '<STR_LIT>' <EOL> func = compile ( fn , [ str ] ) <EOL> os . environ . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> result = func ( '<STR_LIT>' ) <EOL> assert result == os . environ [ '<STR_LIT>' ] <EOL> result = func ( '<STR_LIT>' ) <EOL> assert result == '<STR_LIT>' <EOL> def test_dictlike_environ_get ( ) : <EOL> def fn ( s ) : <EOL> res = os . environ . get ( s ) <EOL> if res is None : res = '<STR_LIT>' <EOL> return res <EOL> func = compile ( fn , [ str ] ) <EOL> os . environ . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> result = func ( '<STR_LIT>' ) <EOL> assert result == os . environ [ '<STR_LIT>' ] <EOL> result = func ( '<STR_LIT>' ) <EOL> assert result == '<STR_LIT>' <EOL> def test_dictlike_environ_setitem ( ) : <EOL> def fn ( s , t1 , t2 , t3 , t4 , t5 ) : <EOL> os . environ [ s ] = t1 <EOL> os . environ [ s ] = t2 <EOL> os . environ [ s ] = t3 <EOL> os . environ [ s ] = t4 <EOL> os . environ [ s ] = t5 <EOL> func = compile ( fn , [ str , str , str , str , str , str ] ) <EOL> func ( '<STR_LIT>' , '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> expected_extra_mallocs = ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) ) <EOL> assert _real_getenv ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> def test_dictlike_environ_delitem ( ) : <EOL> def fn ( s1 , s2 , s3 , s4 , s5 ) : <EOL> for n in range ( <NUM_LIT:10> ) : <EOL> os . environ [ s1 ] = '<STR_LIT>' <EOL> os . environ [ s2 ] = '<STR_LIT>' <EOL> os . environ [ s3 ] = '<STR_LIT>' <EOL> os . environ [ s4 ] = '<STR_LIT>' <EOL> os . environ [ s5 ] = '<STR_LIT>' <EOL> del os . environ [ s3 ] <EOL> del os . environ [ s1 ] <EOL> del os . environ [ s2 ] <EOL> del os . environ [ s4 ] <EOL> try : <EOL> del os . environ [ s2 ] <EOL> except KeyError : <EOL> pass <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> func = compile ( fn , [ str , str , str , str , str ] ) <EOL> if hasattr ( __import__ ( os . name ) , '<STR_LIT>' ) : <EOL> expected_extra_mallocs = range ( <NUM_LIT:2> , <NUM_LIT:10> ) <EOL> else : <EOL> expected_extra_mallocs = range ( <NUM_LIT:10> , <NUM_LIT> ) <EOL> func ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> expected_extra_mallocs = expected_extra_mallocs ) <EOL> assert not _real_getenv ( '<STR_LIT>' ) <EOL> assert not _real_getenv ( '<STR_LIT>' ) <EOL> assert not _real_getenv ( '<STR_LIT>' ) <EOL> assert not _real_getenv ( '<STR_LIT>' ) <EOL> assert _real_getenv ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> def test_dictlike_environ_keys ( ) : <EOL> def fn ( ) : <EOL> return '<STR_LIT:\x00>' . join ( os . environ . keys ( ) ) <EOL> func = compile ( fn , [ ] ) <EOL> os . environ . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> except : <EOL> pass <EOL> result1 = func ( ) . split ( '<STR_LIT:\x00>' ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> result2 = func ( ) . split ( '<STR_LIT:\x00>' ) <EOL> assert '<STR_LIT>' in result1 <EOL> assert '<STR_LIT>' not in result1 <EOL> assert '<STR_LIT>' in result2 <EOL> assert '<STR_LIT>' in result2 <EOL> def test_dictlike_environ_items ( ) : <EOL> def fn ( ) : <EOL> result = [ ] <EOL> for key , value in os . environ . items ( ) : <EOL> result . append ( '<STR_LIT>' % ( key , value ) ) <EOL> return '<STR_LIT:\x00>' . join ( result ) <EOL> func = compile ( fn , [ ] ) <EOL> os . environ . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> result1 = func ( ) . split ( '<STR_LIT:\x00>' ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> result2 = func ( ) . split ( '<STR_LIT:\x00>' ) <EOL> assert ( '<STR_LIT>' % ( os . environ [ '<STR_LIT>' ] , ) ) in result1 <EOL> assert '<STR_LIT>' not in result1 <EOL> assert ( '<STR_LIT>' % ( os . environ [ '<STR_LIT>' ] , ) ) in result2 <EOL> assert '<STR_LIT>' in result2 <EOL> def test_listdir ( ) : <EOL> def mylistdir ( s ) : <EOL> try : <EOL> os . listdir ( '<STR_LIT>' ) <EOL> except OSError : <EOL> pass <EOL> else : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> result = os . listdir ( s ) <EOL> return '<STR_LIT:/>' . join ( result ) <EOL> func = compile ( mylistdir , [ str ] ) <EOL> for testdir in [ str ( udir ) , os . curdir ] : <EOL> result = func ( testdir ) <EOL> result = result . split ( '<STR_LIT:/>' ) <EOL> result . sort ( ) <EOL> compared_with = os . listdir ( testdir ) <EOL> compared_with . sort ( ) <EOL> assert result == compared_with <EOL> if hasattr ( posix , '<STR_LIT>' ) and hasattr ( posix , '<STR_LIT>' ) : <EOL> def test_execv ( ) : <EOL> progname = str ( sys . executable ) <EOL> filename = str ( udir . join ( '<STR_LIT>' ) ) <EOL> def does_stuff ( ) : <EOL> l = [ progname , '<STR_LIT:-c>' , '<STR_LIT>' % filename ] <EOL> pid = os . fork ( ) <EOL> if pid == <NUM_LIT:0> : <EOL> os . execv ( progname , l ) <EOL> else : <EOL> os . waitpid ( pid , <NUM_LIT:0> ) <EOL> func = compile ( does_stuff , [ ] , backendopt = False ) <EOL> func ( ) <EOL> assert open ( filename ) . read ( ) == "<STR_LIT:1>" <EOL> def test_execv_raising ( ) : <EOL> def does_stuff ( ) : <EOL> l = [ ] <EOL> l . append ( "<STR_LIT>" ) <EOL> os . execv ( l [ <NUM_LIT:0> ] , l ) <EOL> func = compile ( does_stuff , [ ] ) <EOL> py . test . raises ( OSError , "<STR_LIT>" ) <EOL> def test_execve ( ) : <EOL> filename = str ( udir . join ( '<STR_LIT>' ) ) <EOL> progname = sys . executable <EOL> def does_stuff ( ) : <EOL> l = [ ] <EOL> l . append ( progname ) <EOL> l . append ( "<STR_LIT:-c>" ) <EOL> l . append ( '<STR_LIT>' % filename ) <EOL> env = { } <EOL> env [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> env [ "<STR_LIT>" ] = "<STR_LIT:a>" <EOL> pid = os . fork ( ) <EOL> if pid == <NUM_LIT:0> : <EOL> os . execve ( progname , l , env ) <EOL> else : <EOL> os . waitpid ( pid , <NUM_LIT:0> ) <EOL> func = compile ( does_stuff , [ ] ) <EOL> func ( ) <EOL> assert open ( filename ) . read ( ) == "<STR_LIT>" <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> def test_spawnv ( ) : <EOL> filename = str ( udir . join ( '<STR_LIT>' ) ) <EOL> progname = str ( sys . executable ) <EOL> scriptpath = udir . join ( '<STR_LIT>' ) <EOL> scriptpath . write ( '<STR_LIT>' % filename ) <EOL> scriptname = str ( scriptpath ) <EOL> def does_stuff ( ) : <EOL> l = [ progname , scriptname ] <EOL> pid = os . spawnv ( os . P_NOWAIT , progname , l ) <EOL> os . waitpid ( pid , <NUM_LIT:0> ) <EOL> func = compile ( does_stuff , [ ] ) <EOL> func ( ) <EOL> assert open ( filename ) . read ( ) == "<STR_LIT:2>" <EOL> def test_utime ( ) : <EOL> path = str ( udir . ensure ( "<STR_LIT>" ) ) <EOL> from time import time , sleep <EOL> t0 = time ( ) <EOL> sleep ( <NUM_LIT:1> ) <EOL> def does_stuff ( flag ) : <EOL> if flag : <EOL> os . utime ( path , None ) <EOL> else : <EOL> os . utime ( path , ( int ( t0 ) , int ( t0 ) ) ) <EOL> func = compile ( does_stuff , [ int ] ) <EOL> func ( <NUM_LIT:1> ) <EOL> assert os . stat ( path ) . st_atime > t0 <EOL> func ( <NUM_LIT:0> ) <EOL> assert int ( os . stat ( path ) . st_atime ) == int ( t0 ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def test_os_uname ( ) : <EOL> def does_stuff ( num ) : <EOL> tup = os . uname ( ) <EOL> lst = [ tup [ <NUM_LIT:0> ] , tup [ <NUM_LIT:1> ] , tup [ <NUM_LIT:2> ] , tup [ <NUM_LIT:3> ] , tup [ <NUM_LIT:4> ] ] <EOL> return lst [ num ] <EOL> func = compile ( does_stuff , [ int ] ) <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> res = func ( i ) <EOL> assert res == os . uname ( ) [ i ] </s>
