<s> import unittest <EOL> import pycurl <EOL> import sys <EOL> import tempfile <EOL> import os <EOL> from . import appmanager <EOL> setup_module , teardown_module = appmanager . setup ( ( '<STR_LIT>' , <NUM_LIT> ) ) <EOL> STDOUT_FD_NUM = <NUM_LIT:1> <EOL> def try_fsync ( fd ) : <EOL> try : <EOL> os . fsync ( fd ) <EOL> except OSError : <EOL> pass <EOL> class DefaultWriteFunctionTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . curl = pycurl . Curl ( ) <EOL> def tearDown ( self ) : <EOL> self . curl . close ( ) <EOL> def test_perform_get ( self ) : <EOL> self . curl . setopt ( pycurl . URL , '<STR_LIT>' ) <EOL> self . curl . perform ( ) <EOL> sys . stdout . flush ( ) <EOL> try_fsync ( STDOUT_FD_NUM ) <EOL> def skip_perform_get_with_default_write_function ( self ) : <EOL> self . curl . setopt ( pycurl . URL , '<STR_LIT>' ) <EOL> f = tempfile . NamedTemporaryFile ( ) <EOL> try : <EOL> saved_stdout_fd = os . dup ( STDOUT_FD_NUM ) <EOL> os . dup2 ( f . fileno ( ) , STDOUT_FD_NUM ) <EOL> try : <EOL> self . curl . perform ( ) <EOL> sys . stdout . flush ( ) <EOL> finally : <EOL> try_fsync ( STDOUT_FD_NUM ) <EOL> os . dup2 ( saved_stdout_fd , STDOUT_FD_NUM ) <EOL> os . close ( saved_stdout_fd ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> body = f . read ( ) <EOL> finally : <EOL> f . close ( ) <EOL> self . assertEqual ( '<STR_LIT:success>' , body ) </s>
