02_Directory.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import os, sys, mmap, random, string, shutil
  2. from regression import Regression
  3. loader = os.environ['PAL_LOADER']
  4. def prepare_dirs(args):
  5. if os.path.exists("dir_exist.tmp"):
  6. shutil.rmtree("dir_exist.tmp")
  7. if os.path.exists("dir_nonexist.tmp"):
  8. shutil.rmtree("dir_nonexist.tmp")
  9. if os.path.exists("dir_delete.tmp"):
  10. shutil.rmtree("dir_delete.tmp")
  11. global dir_files
  12. os.mkdir("dir_exist.tmp")
  13. dir_files = []
  14. for i in range(5):
  15. file = ''.join([random.choice(string.ascii_letters) for i in range(8)])
  16. f = open("dir_exist.tmp/" + file, "w")
  17. f.close()
  18. dir_files.append(file)
  19. os.mkdir("dir_delete.tmp")
  20. regression = Regression(loader, "Directory", prepare_dirs)
  21. regression.add_check(name="Basic Directory Opening",
  22. check=lambda res: "Directory Open Test 1 OK" in res[0].log and
  23. "Directory Open Test 2 OK" in res[0].log and
  24. "Directory Open Test 3 OK" in res[0].log)
  25. regression.add_check(name="Basic Directory Creation",
  26. check=lambda res: "Directory Creation Test 1 OK" in res[0].log and
  27. "Directory Creation Test 2 OK" in res[0].log and
  28. "Directory Creation Test 3 OK" in res[0].log)
  29. def check_read(res):
  30. global dir_files
  31. for file in dir_files:
  32. if ("Read Directory: " + file) not in res[0].log:
  33. return False
  34. return True
  35. regression.add_check(name="Directory Reading", check=check_read)
  36. regression.add_check(name="Directory Attribute Query",
  37. check=lambda res: "Query: type = 7" in res[0].log)
  38. regression.add_check(name="Directory Attribute Query by Handle",
  39. check=lambda res: "Query by Handle: type = 7" in res[0].log)
  40. regression.add_check(name="Directory Deletion",
  41. check=lambda res: not os.path.exists("dir_delete.tmp"))
  42. rv = regression.run_checks()
  43. if rv: sys.exit(rv)