test_reporter.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import json
  2. from library.python.testing.custom_linter_util.reporter import LintReport, LintStatus
  3. from yatest.common import output_path, context
  4. def dump_and_load(report):
  5. report_file = output_path(context.test_name)
  6. report.dump(report_file=report_file)
  7. with open(report_file) as f:
  8. return json.load(f)
  9. def test_empty_report():
  10. report = LintReport()
  11. got = dump_and_load(report)
  12. assert got == {"report": {}}
  13. def test_good_test():
  14. report = LintReport()
  15. report.add("file.cpp", LintStatus.GOOD)
  16. got = dump_and_load(report)
  17. assert got == {
  18. "report": {
  19. "file.cpp": {
  20. "status": "GOOD",
  21. "message": "",
  22. "elapsed": 0.0,
  23. }
  24. }
  25. }
  26. def test_skipped_test():
  27. report = LintReport()
  28. report.add("file.cpp", LintStatus.SKIPPED, "Generated file", elapsed=1.0)
  29. got = dump_and_load(report)
  30. assert got == {
  31. "report": {
  32. "file.cpp": {
  33. "status": "SKIPPED",
  34. "message": "Generated file",
  35. "elapsed": 1.0,
  36. }
  37. }
  38. }
  39. def test_failed_test():
  40. report = LintReport()
  41. report.add("file.cpp", LintStatus.FAIL, "Test failed", elapsed=2.0)
  42. got = dump_and_load(report)
  43. assert got == {
  44. "report": {
  45. "file.cpp": {
  46. "status": "FAIL",
  47. "message": "Test failed",
  48. "elapsed": 2.0,
  49. }
  50. }
  51. }