<s> from __future__ import print_function <EOL> import unittest <EOL> import doctest <EOL> import os <EOL> from testresources import ResourcedTestCase , OptimisingTestSuite <EOL> from van . pg import DatabaseManager <EOL> import psycopg2 <EOL> try : <EOL> import transaction <EOL> except ImportError : <EOL> transaction = None <EOL> def init_db ( db ) : <EOL> conn = psycopg2 . connect ( host = db . host , database = db . database ) <EOL> cur = conn . cursor ( ) <EOL> cur . execute ( "<STR_LIT>" ) <EOL> conn . commit ( ) <EOL> conn . close ( ) <EOL> TEMPLATE_DB = DatabaseManager ( initialize_sql = init_db ) <EOL> class TestTemplateDB ( ResourcedTestCase ) : <EOL> resources = ( ( '<STR_LIT>' , DatabaseManager ( template = TEMPLATE_DB ) ) , <EOL> ) <EOL> def setUp ( self ) : <EOL> ResourcedTestCase . setUp ( self ) <EOL> conn = psycopg2 . connect ( host = self . db . host , database = self . db . database ) <EOL> self . conn = self . db . dirty_on_commit_wrapper ( conn ) <EOL> def tearDown ( self ) : <EOL> self . conn . close ( ) <EOL> ResourcedTestCase . tearDown ( self ) <EOL> def test_wrapper_isolation ( self ) : <EOL> cur = self . conn . cursor ( ) <EOL> cur . execute ( "<STR_LIT>" ) <EOL> self . assertFalse ( self . resources [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] . isDirty ( ) ) <EOL> self . conn . commit ( ) <EOL> self . assertTrue ( self . resources [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] . isDirty ( ) ) <EOL> cur = self . conn . cursor ( ) <EOL> cur . execute ( "<STR_LIT>" ) <EOL> self . assertEqual ( cur . fetchall ( ) , [ ( <NUM_LIT:1> , ) ] ) <EOL> test_wrapper_isolation_repeat = test_wrapper_isolation <EOL> class TestDirtyOnCommit ( ResourcedTestCase ) : <EOL> resources = ( ( '<STR_LIT>' , DatabaseManager ( template = TEMPLATE_DB , dirty_on_commit = True ) ) , <EOL> ( '<STR_LIT>' , DatabaseManager ( template = TEMPLATE_DB ) ) , <EOL> ) <EOL> def test_transaction_commit_dirties ( self ) : <EOL> if transaction is None : <EOL> print ( "<STR_LIT>" ) <EOL> dbm_to_dirty = self . resources [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> dbm_keep_clean = self . resources [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> self . assertFalse ( dbm_to_dirty . isDirty ( ) ) <EOL> self . assertFalse ( TEMPLATE_DB . isDirty ( ) ) <EOL> self . assertFalse ( dbm_keep_clean . isDirty ( ) ) <EOL> transaction . commit ( ) <EOL> self . assertTrue ( dbm_to_dirty . isDirty ( ) ) <EOL> self . assertFalse ( TEMPLATE_DB . isDirty ( ) ) <EOL> self . assertFalse ( dbm_keep_clean . isDirty ( ) ) <EOL> def load_tests ( loader , tests , pattern ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( tests ) <EOL> suite . addTest ( OptimisingTestSuite ( tests ) ) <EOL> suite . addTest ( doctest . DocFileSuite ( os . path . join ( '<STR_LIT:..>' , '<STR_LIT>' ) ) ) <EOL> return suite </s>
