Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setuptestframework.py 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/usr/bin/python2
  2. # Configure this in order to run the testcases.
  3. "setuptestframework.py v 2.6.0.8"
  4. import os
  5. import shutil
  6. import sys
  7. import tempfile
  8. try:
  9. OSErrors = (WindowsError, OSError)
  10. except NameError: # not running on Windows
  11. OSErrors = OSError
  12. def maketemp():
  13. temphome = tempfile.gettempdir()
  14. tempdir = os.path.join(temphome, "adodbapi_test")
  15. try:
  16. os.mkdir(tempdir)
  17. except:
  18. pass
  19. return tempdir
  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. def getcleanupfunction():
  31. return _cleanup_function
  32. def find_ado_path():
  33. adoName = os.path.normpath(os.getcwd() + "/../../adodbapi.py")
  34. adoPackage = os.path.dirname(adoName)
  35. return adoPackage
  36. # make a new package directory for the test copy of ado
  37. def makeadopackage(testfolder):
  38. adoName = os.path.normpath(os.getcwd() + "/../adodbapi.py")
  39. adoPath = os.path.dirname(adoName)
  40. if os.path.exists(adoName):
  41. newpackage = os.path.join(testfolder, "adodbapi")
  42. try:
  43. os.mkdir(newpackage)
  44. except OSErrors:
  45. print(
  46. "*Note: temporary adodbapi package already exists: may be two versions running?"
  47. )
  48. for f in os.listdir(adoPath):
  49. if f.endswith(".py"):
  50. shutil.copy(os.path.join(adoPath, f), newpackage)
  51. if sys.version_info >= (3, 0): # only when running Py3.n
  52. save = sys.stdout
  53. sys.stdout = None
  54. from lib2to3.main import main # use 2to3 to make test package
  55. main("lib2to3.fixes", args=["-n", "-w", newpackage])
  56. sys.stdout = save
  57. return testfolder
  58. else:
  59. raise EnvironmentError("Connot find source of adodbapi to test.")
  60. def makemdb(testfolder, mdb_name):
  61. # following setup code borrowed from pywin32 odbc test suite
  62. # kindly contributed by Frank Millman.
  63. import os
  64. _accessdatasource = os.path.join(testfolder, mdb_name)
  65. if os.path.isfile(_accessdatasource):
  66. print("using JET database=", _accessdatasource)
  67. else:
  68. try:
  69. from win32com.client import constants
  70. from win32com.client.gencache import EnsureDispatch
  71. win32 = True
  72. except ImportError: # perhaps we are running IronPython
  73. win32 = False # iron Python
  74. try:
  75. from System import Activator, Type
  76. except:
  77. pass
  78. # Create a brand-new database - what is the story with these?
  79. dbe = None
  80. for suffix in (".36", ".35", ".30"):
  81. try:
  82. if win32:
  83. dbe = EnsureDispatch("DAO.DBEngine" + suffix)
  84. else:
  85. type = Type.GetTypeFromProgID("DAO.DBEngine" + suffix)
  86. dbe = Activator.CreateInstance(type)
  87. break
  88. except:
  89. pass
  90. if dbe:
  91. print(" ...Creating ACCESS db at " + _accessdatasource)
  92. if win32:
  93. workspace = dbe.Workspaces(0)
  94. newdb = workspace.CreateDatabase(
  95. _accessdatasource, constants.dbLangGeneral, constants.dbVersion40
  96. )
  97. else:
  98. newdb = dbe.CreateDatabase(
  99. _accessdatasource, ";LANGID=0x0409;CP=1252;COUNTRY=0"
  100. )
  101. newdb.Close()
  102. else:
  103. print(" ...copying test ACCESS db to " + _accessdatasource)
  104. mdbName = os.path.abspath(
  105. os.path.join(os.path.dirname(__file__), "..", "examples", "test.mdb")
  106. )
  107. import shutil
  108. shutil.copy(mdbName, _accessdatasource)
  109. return _accessdatasource
  110. if __name__ == "__main__":
  111. print("Setting up a Jet database for server to use for remote testing...")
  112. temp = maketemp()
  113. makemdb(temp, "server_test.mdb")