test.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. else:
  16. _print_("make dir "+subdir)
  17. file.fmkdir(os.path.abspath(subdir))
  18. _print_("unzip OpenAccess.zip in .\\work\\")
  19. os.system("unzip -q ..\\OpenAccess.zip -d .\\work\\")
  20. for zipped_file in ("project0.zip", "db.zip", "empty_project.zip"):
  21. _print_("unzip .\\initial\\{} to .\\work".format(zipped_file))
  22. os.system("unzip -q .\\initial\\{} -d .\\work".format(zipped_file))
  23. utilities.clean_sources(".\\reference\\source")
  24. _print_("\n** TEST EXPORT **")
  25. accdb_path = ".\\work\\project0.accdb"
  26. _print_("Export the sources from " + accdb_path)
  27. os.system( accdb_path + " /X test_export" )
  28. _print_("Verify the log file")
  29. result = utilities.verify_log(".\\work\\project0_1.log")
  30. if result != 0:
  31. sys.exit(result)
  32. utilities.clean_sources( ".\\work\\source\\" )
  33. zipped_project0 = ".\\work\\project0.zip"
  34. _print_("control existence of " + zipped_project0)
  35. if not file.fexists( zipped_project0 ):
  36. _print_( zipped_project0 +" does not exist" )
  37. sys.exit(1)
  38. source = ".\\work\\source"
  39. target = ".\\results\\source1"
  40. _print_("Copy {} to {}".format(source, target))
  41. copy_tree(source, target)
  42. _print_("control the result")
  43. result = utilities.compare_dirs( ".\\results\\source1", ".\\reference\\source" )
  44. if result != 0:
  45. sys.exit(result)
  46. _print_(".\\results\\source1 and .\\reference\\source are identical")
  47. _print_("\n** TEST IMPORTS **")
  48. import_project = ".\\work\\empty_project.accdb"
  49. _print_("Import .\\work\\sources in " + import_project)
  50. os.system(import_project + " /X test_import")
  51. _print_("Verify the log file")
  52. result = utilities.verify_log(".\\work\\empty_project_1.log")
  53. if result != 0:
  54. sys.exit(result)
  55. _print_("copy {} to {}".format(import_project, ".\\results\\empty_project_updated.accdb"))
  56. file.fcopy(import_project, ".\\results\\empty_project_updated.accdb")
  57. _print_("control existence of backup")
  58. if not file.fexists(import_project + ".old"):
  59. _print_(import_project + ".old do not exist")
  60. sys.exit(1)
  61. # at this point, we did a complete export of project0.accdb,
  62. # then an import of the previously created sources in the empty_project.accdb
  63. # we now export the sources of empty_project.accdb to control the integrity of the newly created app
  64. _print_("\n** TEST RE-EXPORTS **")
  65. _print_("Delete .\\work\\source")
  66. file.frmdir(".\\work\\source")
  67. _print_("Export the sources from " + import_project)
  68. os.system( import_project + " /X test_export" )
  69. _print_("Verify the log file")
  70. result = utilities.verify_log(".\\work\\empty_project_2.log")
  71. if result != 0:
  72. sys.exit(result)
  73. utilities.clean_sources( ".\\work\\source\\" )
  74. source = ".\\work\\source"
  75. target = ".\\results\\source2"
  76. _print_("Copy {} to {}".format(source, target))
  77. copy_tree(source, target)
  78. _print_("control the result")
  79. result = utilities.compare_dirs( ".\\results\\source2", ".\\reference\\source" )
  80. if result != 0:
  81. sys.exit(result)
  82. _print_(".\\results\\source2 and .\\reference\\source are identical")
  83. _print_("** end **")
  84. sys.exit(0)