1 #!/usr/bin/python2 2 # Configure this in order to run the testcases. 3 "setuptestframework.py v 2.6.0.8" 4 5 import os 6 import shutil 7 import tempfile 8 9 10 def maketemp(): 11 temphome = tempfile.gettempdir() 12 tempdir = os.path.join(temphome, "adodbapi_test") 13 try: 14 os.mkdir(tempdir) 15 except: 16 pass 17 return tempdir 18 19 20 def _cleanup_function(testfolder, mdb_name): 21 try: 22 os.unlink(os.path.join(testfolder, mdb_name)) 23 except: 24 pass # mdb database not present 25 try: 26 shutil.rmtree(testfolder) 27 print(" cleaned up folder", testfolder) 28 except: 29 pass # test package not present 30 31 32 def getcleanupfunction(): 33 return _cleanup_function 34 35 36 def find_ado_path(): 37 adoName = os.path.normpath(os.getcwd() + "/../../adodbapi.py") 38 adoPackage = os.path.dirname(adoName) 39 return adoPackage 40 41 42 # make a new package directory for the test copy of ado 43 def makeadopackage(testfolder): 44 adoName = os.path.normpath(os.getcwd() + "/../adodbapi.py") 45 adoPath = os.path.dirname(adoName) 46 if os.path.exists(adoName): 47 newpackage = os.path.join(testfolder, "adodbapi") 48 try: 49 os.makedirs(newpackage) 50 except OSError: 51 print( 52 "*Note: temporary adodbapi package already exists: may be two versions running?" 53 ) 54 for f in os.listdir(adoPath): 55 if f.endswith(".py"): 56 shutil.copy(os.path.join(adoPath, f), newpackage) 57 return testfolder 58 else: 59 raise OSError("Cannot find source of adodbapi to test.") 60 61 62 def makemdb(testfolder, mdb_name): 63 # following setup code borrowed from pywin32 odbc test suite 64 # kindly contributed by Frank Millman. 65 import os 66 67 _accessdatasource = os.path.join(testfolder, mdb_name) 68 if os.path.isfile(_accessdatasource): 69 print("using JET database=", _accessdatasource) 70 else: 71 from win32com.client import constants 72 from win32com.client.gencache import EnsureDispatch 73 74 # Create a brand-new database - what is the story with these? 75 dbe = None 76 for suffix in (".36", ".35", ".30"): 77 try: 78 dbe = EnsureDispatch("DAO.DBEngine" + suffix) 79 break 80 except: 81 pass 82 if dbe: 83 print(" ...Creating ACCESS db at " + _accessdatasource) 84 workspace = dbe.Workspaces(0) 85 newdb = workspace.CreateDatabase( 86 _accessdatasource, constants.dbLangGeneral, constants.dbVersion40 87 ) 88 newdb.Close() 89 else: 90 print(" ...copying test ACCESS db to " + _accessdatasource) 91 mdbName = os.path.abspath( 92 os.path.join(os.path.dirname(__file__), "..", "examples", "test.mdb") 93 ) 94 import shutil 95 96 shutil.copy(mdbName, _accessdatasource) 97 98 return _accessdatasource 99