test_bench.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. class TestBench():
  14. """
  15. test bench
  16. """
  17. def test_ci_ben(self):
  18. """
  19. ci benchmark
  20. """
  21. fr = open(os.path.join(pdf_dev_path, "result.json"), "r", encoding="utf-8")
  22. lines = fr.readlines()
  23. last_line = lines[-1].strip()
  24. last_score = json.loads(last_line)
  25. last_simscore = last_score["average_sim_score"]
  26. last_editdistance = last_score["average_edit_distance"]
  27. last_bleu = last_score["average_bleu_score"]
  28. os.system(f"python tests/test_cli/lib/pre_clean.py --tool_name mineru --download_dir {pdf_dev_path}")
  29. now_score = get_score()
  30. print ("now_score:", now_score)
  31. if not os.path.exists(os.path.join(pdf_dev_path, "ci")):
  32. os.makedirs(os.path.join(pdf_dev_path, "ci"), exist_ok=True)
  33. fw = open(os.path.join(pdf_dev_path, "ci", "result.json"), "w+", encoding="utf-8")
  34. fw.write(json.dumps(now_score) + "\n")
  35. now_simscore = now_score["average_sim_score"]
  36. now_editdistance = now_score["average_edit_distance"]
  37. now_bleu = now_score["average_bleu_score"]
  38. assert last_simscore <= now_simscore
  39. assert last_editdistance <= now_editdistance
  40. assert last_bleu <= now_bleu
  41. def get_score():
  42. """
  43. get score
  44. """
  45. score = calculate_score.Scoring(os.path.join(pdf_dev_path, "result.json"))
  46. score.calculate_similarity_total("mineru", pdf_dev_path)
  47. res = score.summary_scores()
  48. return res