<s> import testsupport <EOL> import StringIO , unittest <EOL> import sqlite3 as sqlite <EOL> class LogFileTemplate : <EOL> def write ( self , s ) : <EOL> pass <EOL> class LogFile : <EOL> def __init__ ( self ) : <EOL> pass <EOL> def init_LogFile ( ) : <EOL> LogFile . write = LogFileTemplate . write <EOL> class CommandLoggingTests ( unittest . TestCase , testsupport . TestSupport ) : <EOL> def tearDown ( self ) : <EOL> try : <EOL> self . cnx . close ( ) <EOL> self . removefile ( ) <EOL> except AttributeError : <EOL> pass <EOL> except sqlite . InterfaceError : <EOL> pass <EOL> def CheckNoWrite ( self ) : <EOL> init_LogFile ( ) <EOL> del LogFile . write <EOL> logger = LogFile ( ) <EOL> try : <EOL> self . cnx = sqlite . connect ( self . getfilename ( ) , <EOL> command_logfile = logger ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except ValueError : <EOL> pass <EOL> def CheckWriteNotCallable ( self ) : <EOL> logger = LogFile ( ) <EOL> logger . write = <NUM_LIT:5> <EOL> try : <EOL> self . cnx = sqlite . connect ( self . getfilename ( ) , <EOL> command_logfile = logger ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except ValueError : <EOL> pass <EOL> def CheckLoggingWorks ( self ) : <EOL> logger = StringIO . StringIO ( ) <EOL> expected_output = "<STR_LIT>" . join ( [ <EOL> sqlite . main . _BEGIN , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) + "<STR_LIT>" <EOL> self . cnx = sqlite . connect ( self . getfilename ( ) , <EOL> command_logfile = logger ) <EOL> cu = self . cnx . cursor ( ) <EOL> cu . execute ( "<STR_LIT>" ) <EOL> cu . execute ( "<STR_LIT>" , ( <NUM_LIT:5> , ) ) <EOL> self . cnx . rollback ( ) <EOL> logger . seek ( <NUM_LIT:0> ) <EOL> real_output = logger . read ( ) <EOL> if expected_output != real_output : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def suite ( ) : <EOL> command_logging_suite = unittest . makeSuite ( CommandLoggingTests , "<STR_LIT>" ) <EOL> return command_logging_suite <EOL> def main ( ) : <EOL> runner = unittest . TextTestRunner ( ) <EOL> runner . run ( suite ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
