<s> "<STR_LIT>" <EOL> from test import test_support <EOL> try : <EOL> import posix <EOL> except ImportError : <EOL> raise test_support . TestSkipped , "<STR_LIT>" <EOL> import time <EOL> import os <EOL> import sys <EOL> import unittest <EOL> import warnings <EOL> warnings . filterwarnings ( '<STR_LIT:ignore>' , '<STR_LIT>' , <EOL> RuntimeWarning ) <EOL> class PosixTester ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> fp = open ( test_support . TESTFN , '<STR_LIT>' ) <EOL> fp . close ( ) <EOL> def tearDown ( self ) : <EOL> os . unlink ( test_support . TESTFN ) <EOL> def testNoArgFunctions ( self ) : <EOL> NO_ARG_FUNCTIONS = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ] <EOL> for name in NO_ARG_FUNCTIONS : <EOL> posix_func = getattr ( posix , name , None ) <EOL> if posix_func is not None : <EOL> posix_func ( ) <EOL> self . assertRaises ( TypeError , posix_func , <NUM_LIT:1> ) <EOL> def test_statvfs ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> self . assert_ ( posix . statvfs ( os . curdir ) ) <EOL> def test_fstatvfs ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> fp = open ( test_support . TESTFN ) <EOL> try : <EOL> self . assert_ ( posix . fstatvfs ( fp . fileno ( ) ) ) <EOL> finally : <EOL> fp . close ( ) <EOL> def test_ftruncate ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> fp = open ( test_support . TESTFN , '<STR_LIT>' ) <EOL> try : <EOL> fp . write ( '<STR_LIT:test>' ) <EOL> fp . flush ( ) <EOL> posix . ftruncate ( fp . fileno ( ) , <NUM_LIT:0> ) <EOL> finally : <EOL> fp . close ( ) <EOL> def test_dup ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> fp = open ( test_support . TESTFN ) <EOL> try : <EOL> fd = posix . dup ( fp . fileno ( ) ) <EOL> self . assert_ ( isinstance ( fd , int ) ) <EOL> os . close ( fd ) <EOL> finally : <EOL> fp . close ( ) <EOL> def test_confstr ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , posix . confstr , "<STR_LIT>" ) <EOL> self . assertEqual ( len ( posix . confstr ( "<STR_LIT>" ) ) > <NUM_LIT:0> , True ) <EOL> def test_dup2 ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> fp1 = open ( test_support . TESTFN ) <EOL> fp2 = open ( test_support . TESTFN ) <EOL> try : <EOL> posix . dup2 ( fp1 . fileno ( ) , fp2 . fileno ( ) ) <EOL> finally : <EOL> fp1 . close ( ) <EOL> fp2 . close ( ) <EOL> def fdopen_helper ( self , * args ) : <EOL> fd = os . open ( test_support . TESTFN , os . O_RDONLY ) <EOL> fp2 = posix . fdopen ( fd , * args ) <EOL> fp2 . close ( ) <EOL> def test_fdopen ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> self . fdopen_helper ( ) <EOL> self . fdopen_helper ( '<STR_LIT:r>' ) <EOL> self . fdopen_helper ( '<STR_LIT:r>' , <NUM_LIT:100> ) <EOL> def test_osexlock ( self ) : <EOL> if hasattr ( posix , "<STR_LIT>" ) : <EOL> fd = os . open ( test_support . TESTFN , <EOL> os . O_WRONLY | os . O_EXLOCK | os . O_CREAT ) <EOL> self . assertRaises ( OSError , os . open , test_support . TESTFN , <EOL> os . O_WRONLY | os . O_EXLOCK | os . O_NONBLOCK ) <EOL> os . close ( fd ) <EOL> if hasattr ( posix , "<STR_LIT>" ) : <EOL> fd = os . open ( test_support . TESTFN , <EOL> os . O_WRONLY | os . O_SHLOCK | os . O_CREAT ) <EOL> self . assertRaises ( OSError , os . open , test_support . TESTFN , <EOL> os . O_WRONLY | os . O_EXLOCK | os . O_NONBLOCK ) <EOL> os . close ( fd ) <EOL> def test_osshlock ( self ) : <EOL> if hasattr ( posix , "<STR_LIT>" ) : <EOL> fd1 = os . open ( test_support . TESTFN , <EOL> os . O_WRONLY | os . O_SHLOCK | os . O_CREAT ) <EOL> fd2 = os . open ( test_support . TESTFN , <EOL> os . O_WRONLY | os . O_SHLOCK | os . O_CREAT ) <EOL> os . close ( fd2 ) <EOL> os . close ( fd1 ) <EOL> if hasattr ( posix , "<STR_LIT>" ) : <EOL> fd = os . open ( test_support . TESTFN , <EOL> os . O_WRONLY | os . O_SHLOCK | os . O_CREAT ) <EOL> self . assertRaises ( OSError , os . open , test_support . TESTFN , <EOL> os . O_RDONLY | os . O_EXLOCK | os . O_NONBLOCK ) <EOL> os . close ( fd ) <EOL> def test_fstat ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> fp = open ( test_support . TESTFN ) <EOL> try : <EOL> self . assert_ ( posix . fstat ( fp . fileno ( ) ) ) <EOL> finally : <EOL> fp . close ( ) <EOL> def test_stat ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> self . assert_ ( posix . stat ( test_support . TESTFN ) ) <EOL> def test_chdir ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> posix . chdir ( os . curdir ) <EOL> self . assertRaises ( OSError , posix . chdir , test_support . TESTFN ) <EOL> def test_lsdir ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> self . assert_ ( test_support . TESTFN in posix . lsdir ( os . curdir ) ) <EOL> def test_access ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> self . assert_ ( posix . access ( test_support . TESTFN , os . R_OK ) ) <EOL> def test_umask ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> old_mask = posix . umask ( <NUM_LIT:0> ) <EOL> self . assert_ ( isinstance ( old_mask , int ) ) <EOL> posix . umask ( old_mask ) <EOL> def test_strerror ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> self . assert_ ( posix . strerror ( <NUM_LIT:0> ) ) <EOL> def test_pipe ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> reader , writer = posix . pipe ( ) <EOL> os . close ( reader ) <EOL> os . close ( writer ) <EOL> def test_tempnam ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> self . assert_ ( posix . tempnam ( ) ) <EOL> self . assert_ ( posix . tempnam ( os . curdir ) ) <EOL> self . assert_ ( posix . tempnam ( os . curdir , '<STR_LIT>' ) ) <EOL> def test_tmpfile ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> fp = posix . tmpfile ( ) <EOL> fp . close ( ) <EOL> def test_utime ( self ) : <EOL> if hasattr ( posix , '<STR_LIT>' ) : <EOL> now = time . time ( ) <EOL> posix . utime ( test_support . TESTFN , None ) <EOL> self . assertRaises ( TypeError , posix . utime , test_support . TESTFN , ( None , None ) ) <EOL> self . assertRaises ( TypeError , posix . utime , test_support . TESTFN , ( now , None ) ) <EOL> self . assertRaises ( TypeError , posix . utime , test_support . TESTFN , ( None , now ) ) <EOL> posix . utime ( test_support . TESTFN , ( int ( now ) , int ( now ) ) ) <EOL> posix . utime ( test_support . TESTFN , ( now , now ) ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( PosixTester ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_main ( ) </s>
