<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import errno <EOL> import shutil <EOL> import tempfile <EOL> import unittest <EOL> import logging <EOL> from ganeti import utils <EOL> import testutils <EOL> tempfile . TMP_MAX = <NUM_LIT:3> <EOL> class TestResetTempfileModule ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . tmpdir = tempfile . mkdtemp ( ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . tmpdir ) <EOL> def testNoReset ( self ) : <EOL> if ( ( sys . hexversion >= <NUM_LIT> and sys . hexversion < <NUM_LIT> ) or <EOL> sys . hexversion >= <NUM_LIT> ) : <EOL> return <EOL> if ( hasattr ( tempfile . _RandomNameSequence , "<STR_LIT>" ) and <EOL> type ( tempfile . _RandomNameSequence . rng ) == property ) : <EOL> return <EOL> self . _Test ( False ) <EOL> def testReset ( self ) : <EOL> self . _Test ( True ) <EOL> def _Test ( self , reset ) : <EOL> self . failIf ( tempfile . TMP_MAX > <NUM_LIT:10> ) <EOL> ( fd , _ ) = tempfile . mkstemp ( dir = self . tmpdir , prefix = "<STR_LIT>" , suffix = "<STR_LIT>" ) <EOL> os . close ( fd ) <EOL> ( notify_read , notify_write ) = os . pipe ( ) <EOL> pid = os . fork ( ) <EOL> if pid == <NUM_LIT:0> : <EOL> try : <EOL> try : <EOL> if reset : <EOL> utils . ResetTempfileModule ( ) <EOL> os . close ( notify_write ) <EOL> os . read ( notify_read , <NUM_LIT:1> ) <EOL> try : <EOL> ( _ , path ) = tempfile . mkstemp ( dir = self . tmpdir , <EOL> prefix = "<STR_LIT>" , suffix = "<STR_LIT>" ) <EOL> except EnvironmentError , err : <EOL> if err . errno == errno . EEXIST : <EOL> os . _exit ( <NUM_LIT:2> ) <EOL> raise <EOL> logging . debug ( "<STR_LIT>" , path ) <EOL> os . _exit ( <NUM_LIT:0> ) <EOL> except Exception : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> finally : <EOL> os . _exit ( <NUM_LIT:1> ) <EOL> os . close ( notify_read ) <EOL> for _ in range ( tempfile . TMP_MAX ) : <EOL> ( fd , path ) = tempfile . mkstemp ( dir = self . tmpdir , <EOL> prefix = "<STR_LIT>" , suffix = "<STR_LIT>" ) <EOL> os . close ( fd ) <EOL> logging . debug ( "<STR_LIT>" , path ) <EOL> os . close ( notify_write ) <EOL> ( _ , status ) = os . waitpid ( pid , <NUM_LIT:0> ) <EOL> self . failIf ( os . WIFSIGNALED ( status ) ) <EOL> if reset : <EOL> expected = <NUM_LIT:0> <EOL> else : <EOL> expected = <NUM_LIT:2> <EOL> self . assertEqual ( os . WEXITSTATUS ( status ) , expected ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> testutils . GanetiTestProgram ( ) </s>
