test.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. from distutils.dir_util import copy_tree
  2. import os
  3. import sys
  4. import file
  5. import utilities
  6. def _print_(*args):
  7. print(*args)
  8. sys.stdout.flush()
  9. _print_("\n** PREPARATION **")
  10. _print_("\nWARNING: CLOSE ANY OPENED ACCESS PROJECT TO AVOID UNEXPECTED PROBLEMS")
  11. for subdir in (".\\work", ".\\results"):
  12. if file.fexists(subdir):
  13. _print_("clean " + subdir)
  14. file.frmdir(os.path.abspath(subdir))
  15. _print_("make dir " + subdir)
  16. file.fmkdir(os.path.abspath(subdir))
  17. _print_("unzip OpenAccess.zip in .\\work\\")
  18. os.system("unzip -q ..\\OpenAccess.zip -d .\\work\\")
  19. for zipped_file in ("project0.zip", "db.zip", "empty_project.zip"):
  20. _print_("unzip .\\initial\\{} to .\\work".format(zipped_file))
  21. os.system("unzip -q .\\initial\\{} -d .\\work".format(zipped_file))
  22. utilities.clean_sources(".\\reference\\source")
  23. _print_("\n** TEST EXPORT **")
  24. accdb_path = ".\\work\\project0.accdb"
  25. _print_("Export the sources from " + accdb_path)
  26. os.system(accdb_path + " /X test_export")
  27. _print_("Verify the log file")
  28. result = utilities.verify_log(".\\work\\project0_1.log")
  29. if result != 0:
  30. sys.exit(result)
  31. utilities.clean_sources(".\\work\\source\\")
  32. zipped_project0 = ".\\work\\project0.zip"
  33. _print_("control existence of " + zipped_project0)
  34. if not file.fexists(zipped_project0):
  35. _print_(zipped_project0 + " does not exist")
  36. sys.exit(1)
  37. source = ".\\work\\source"
  38. target = ".\\results\\source1"
  39. _print_("Copy {} to {}".format(source, target))
  40. copy_tree(source, target)
  41. _print_("control the result")
  42. result = utilities.compare_dirs(".\\results\\source1", ".\\reference\\source")
  43. if result != 0:
  44. sys.exit(result)
  45. _print_(".\\results\\source1 and .\\reference\\source are identical")
  46. _print_("\n** TEST IMPORTS **")
  47. import_project = ".\\work\\empty_project.accdb"
  48. _print_("Import .\\work\\sources in " + import_project)
  49. os.system(import_project + " /X test_import")
  50. _print_("Verify the log file")
  51. result = utilities.verify_log(".\\work\\empty_project_1.log")
  52. if result != 0:
  53. sys.exit(result)
  54. _print_("copy {} to {}".format(import_project, ".\\results\\empty_project_updated.accdb"))
  55. file.fcopy(import_project, ".\\results\\empty_project_updated.accdb")
  56. _print_("control existence of backup")
  57. if not file.fexists(import_project + ".old"):
  58. _print_(import_project + ".old do not exist")
  59. sys.exit(1)
  60. # at this point, we did a complete export of project0.accdb,
  61. # then an import of the previously created sources in the empty_project.accdb
  62. # we now export the sources of empty_project.accdb to control the integrity of the newly created app
  63. _print_("\n** TEST RE-EXPORTS **")
  64. _print_("Delete .\\work\\source")
  65. file.frmdir(".\\work\\source")
  66. _print_("Export the sources from " + import_project)
  67. os.system(import_project + " /X test_export")
  68. _print_("Verify the log file")
  69. result = utilities.verify_log(".\\work\\empty_project_2.log")
  70. if result != 0:
  71. sys.exit(result)
  72. utilities.clean_sources(".\\work\\source\\")
  73. source = ".\\work\\source"
  74. target = ".\\results\\source2"
  75. _print_("Copy {} to {}".format(source, target))
  76. copy_tree(source, target)
  77. _print_("control the result")
  78. result = utilities.compare_dirs(".\\results\\source2", ".\\reference\\source")
  79. # Do not fail, just warn.
  80. # These files could differ for too many reasons that could not be managed
  81. # if result != 0:
  82. # sys.exit(result)
  83. if result != 0:
  84. _print_("WARNING: Check the files of .\\results\\source2")
  85. else:
  86. _print_(".\\results\\source2 and .\\reference\\source are identical")
  87. _print_("** end **")
  88. sys.exit(0)