test_bench.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. try:
  22. fr = open(os.path.join(pdf_dev_path, "result.json"), "r", encoding="utf-8")
  23. lines = fr.readlines()
  24. last_line = lines[-1].strip()
  25. last_score = json.loads(last_line)
  26. print ("last_score:", last_score)
  27. last_simscore = last_score["average_sim_score"]
  28. last_editdistance = last_score["average_edit_distance"]
  29. last_bleu = last_score["average_bleu_score"]
  30. except IOError:
  31. print ("result.json not exist")
  32. os.system(f"python lib/pre_clean.py --tool_name mineru --download_dir {pdf_dev_path}")
  33. now_score = get_score()
  34. print ("now_score:", now_score)
  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. data_path = os.path.join(pdf_dev_path, "ci")
  46. score = calculate_score.Scoring(os.path.join(data_path, "result.json"))
  47. score.calculate_similarity_total("mineru", data_path)
  48. res = score.summary_scores()
  49. return res