test.py 3.4 KB

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