utils_for_test_para.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. class UtilsForTestPara:
  3. def __init__(self):
  4. curr_dir = os.path.dirname(os.path.abspath(__file__))
  5. parent_dir = os.path.dirname(curr_dir)
  6. assets_dir = os.path.join(parent_dir, "assets")
  7. self.default_pre_proc_out_dir = os.path.join(assets_dir, "pre_proc_results")
  8. if not os.path.exists(assets_dir):
  9. raise FileNotFoundError("The assets directory does not exist. Please check the path.")
  10. def read_preproc_out_jfiles(self, input_dir=None):
  11. """
  12. Read all preproc_out.json files under the directory input_dir
  13. Parameters
  14. ----------
  15. input_dir : str
  16. The directory where the preproc_out.json files are located.
  17. The default is default_pre_proc_out_dir.
  18. Returns
  19. -------
  20. preproc_out_jsons : list
  21. A list of paths of preproc_out.json files.
  22. """
  23. if input_dir is None:
  24. input_dir = self.default_pre_proc_out_dir
  25. preproc_out_jsons = []
  26. for root, dirs, files in os.walk(input_dir):
  27. for file in files:
  28. if file.endswith("preproc_out.json"):
  29. preproc_out_json_abs_path = os.path.join(root, file)
  30. preproc_out_jsons.append(preproc_out_json_abs_path)
  31. return preproc_out_jsons
  32. if __name__ == "__main__":
  33. utils = UtilsForTestPara()
  34. preproc_out_jsons = utils.read_preproc_out_jfiles()
  35. for preproc_out_json in preproc_out_jsons:
  36. print(preproc_out_json)