test_bench.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """
  2. bench
  3. """
  4. import os
  5. import shutil
  6. import json
  7. from lib import calculate_score
  8. import pytest
  9. from conf import conf
  10. code_path = os.environ.get('GITHUB_WORKSPACE')
  11. pdf_dev_path = conf.conf["pdf_dev_path"]
  12. pdf_res_path = conf.conf["pdf_res_path"]
  13. last_simscore = 0
  14. last_editdistance = 0
  15. last_bleu = 0
  16. class TestBench():
  17. """
  18. test bench
  19. """
  20. def test_ci_ben(self):
  21. """
  22. ci benchmark
  23. """
  24. try:
  25. fr = open(os.path.join(pdf_dev_path, "result.json"), "r", encoding="utf-8")
  26. lines = fr.readlines()
  27. last_line = lines[-1].strip()
  28. last_score = json.loads(last_line)
  29. last_simscore = last_score["average_sim_score"]
  30. last_editdistance = last_score["average_edit_distance"]
  31. last_bleu = last_score["average_bleu_score"]
  32. except IOError:
  33. print ("result.json not exist")
  34. os.system(f"python tests/test_cli/lib/pre_clean.py --tool_name mineru --download_dir {pdf_dev_path}")
  35. now_score = get_score()
  36. print ("now_score:", now_score)
  37. if not os.path.exists(os.path.join(pdf_dev_path, "ci")):
  38. os.makedirs(os.path.join(pdf_dev_path, "ci"), exist_ok=True)
  39. fw = open(os.path.join(pdf_dev_path, "ci", "result.json"), "w+", encoding="utf-8")
  40. fw.write(json.dumps(now_score) + "\n")
  41. now_simscore = now_score["average_sim_score"]
  42. now_editdistance = now_score["average_edit_distance"]
  43. now_bleu = now_score["average_bleu_score"]
  44. assert last_simscore <= now_simscore
  45. assert last_editdistance <= now_editdistance
  46. assert last_bleu <= now_bleu
  47. def get_score():
  48. """
  49. get score
  50. """
  51. score = calculate_score.Scoring(os.path.join(pdf_dev_path, "result.json"))
  52. score.calculate_similarity_total("mineru", pdf_dev_path)
  53. res = score.summary_scores()
  54. return res