run_tests.py 2.8 KB

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