run_tests.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. from distutils.dir_util import copy_tree
  2. import os
  3. import sys
  4. import compare
  5. import file
  6. def clean_sources(sources_path):
  7. print("Clean the sources")
  8. # remove the source code of test module and macros
  9. for file_path in ("modules\\test_methods.bas",
  10. "macros\\test_export.bas",
  11. "macros\\test_import.bas"):
  12. sources_path = os.path.abspath(sources_path)
  13. try:
  14. os.remove( file.fjoin(sources_path, file_path) )
  15. except FileNotFoundError:
  16. pass
  17. # remove the reference to OpenAccess.accda from references.csv
  18. path = file.fjoin(sources_path, "references.csv")
  19. tmp_path = file.fjoin(sources_path, "references_tmp.csv")
  20. if file.fexists(path):
  21. with open(path, "r") as ref_file:
  22. with open(tmp_path, "w") as new_ref_file:
  23. for line in ref_file:
  24. if line.strip() != os.path.abspath("..\OpenAccess.accda"):
  25. new_ref_file.write(line)
  26. os.remove(path)
  27. os.rename(tmp_path, path)
  28. print("\n** PREPARATION **")
  29. if not file.fexists("..\\OpenAccess.accda"):
  30. print("unzip OpenAccess.zip in .\\work")
  31. os.system("unzip -q ..\\OpenAccess.zip -d .\\work")
  32. for subdir in (".\\work", ".\\results"):
  33. if file.fexists(subdir):
  34. print("clean "+subdir)
  35. file.frmdir(subdir)
  36. else:
  37. print("make dir "+subdir)
  38. file.fmkdir(subdir)
  39. for zipped_file in ("project0.zip", "db.zip", "empty_project.zip"):
  40. print("unzip .\\initial\\{} to .\\work".format(zipped_file))
  41. os.system("unzip -q .\\initial\\{} -d .\\work".format(zipped_file))
  42. clean_sources(".\\reference\\source")
  43. print("\n** TEST EXPORT **")
  44. accdb_path = ".\\work\\project0.accdb"
  45. print("Export the sources from " + accdb_path)
  46. os.system( accdb_path + " /X test_export" )
  47. clean_sources( ".\\work\\source\\" )
  48. zipped_project0 = ".\\work\\project0.zip"
  49. print("control existence of " + zipped_project0)
  50. if not file.fexists( zipped_project0 ):
  51. print( zipped_project0 +" does not exist" )
  52. sys.exit(1)
  53. source = ".\\work\\source"
  54. target = ".\\results\\source1"
  55. print("Copy {} to {}".format(source, target))
  56. copy_tree(source, target)
  57. print("control the result")
  58. result = compare.compare_dirs( ".\\results\\source1", ".\\reference\\source" )
  59. if result != 0:
  60. sys.exit(result)
  61. print("\n** TEST IMPORTS **")
  62. result_count = 1
  63. for import_project in (".\\work\\empty_project.accdb", ".\\work\\project0.accdb"):
  64. print("Import .\\work\\sources in " + import_project)
  65. os.system(import_project + " /X test_import")
  66. result_count += 1
  67. print("copy {} to {}".format(import_project, ".\\results\\result{}.accdb".format(result_count)))
  68. file.fcopy(import_project, ".\\results\\result{}.accdb".format(result_count))
  69. print("control existence of backup")
  70. if not file.fexists(import_project + ".old"):
  71. print(import_project + ".old do not exist")
  72. sys.exit(1)
  73. print("** TEST RESULTS **")
  74. for id_result in range(2, result_count + 1):
  75. resulting_accdb = ".\\results\\result{}.accdb".format(id_result)
  76. print("Export " + resulting_accdb)
  77. os.system(resulting_accdb + " /X test_export")
  78. print("rename .\\results\\source to .\\results\\source{}".format(id_result))
  79. os.rename(".\\results\\source", ".\\results\\source{}".format(id_result))
  80. print("Control the result")
  81. compare.compare_dirs( ".\\results\\source{}".format(id_result), ".\\reference\\source")
  82. print("** end **")
  83. sys.exit(0)