test_platform_observable_performance.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. from __future__ import annotations
  2. from content_agent.business_modules.content_discovery.platform_observable_performance import (
  3. performance_score,
  4. )
  5. def test_douyin_play_count_is_natural_missing_and_score_is_bounded():
  6. result = performance_score(
  7. {
  8. "digg_count": 100000,
  9. "comment_count": 1000,
  10. "share_count": 500,
  11. "collect_count": 1000,
  12. },
  13. "douyin",
  14. )
  15. assert 0 <= result["platform_performance_score"] <= 100
  16. assert {row["field"] for row in result["platform_performance_components"]} == {
  17. "statistics.digg_count",
  18. "statistics.comment_count",
  19. "statistics.share_count",
  20. "statistics.collect_count",
  21. }
  22. assert result["missing_observable_fields"] == [
  23. {
  24. "field": "statistics.play_count",
  25. "missing_type": "natural_platform_missing",
  26. "platform": "douyin",
  27. "evidence": "跨平台字段映射.json",
  28. }
  29. ]
  30. assert "platform_heat" not in result
  31. def test_kuaishou_all_five_fields_supported():
  32. result = performance_score(
  33. {
  34. "play_count": 10000,
  35. "digg_count": 2000,
  36. "comment_count": 200,
  37. "share_count": 100,
  38. "collect_count": 100,
  39. },
  40. "kuaishou",
  41. )
  42. assert len(result["platform_performance_components"]) == 5
  43. assert result["missing_observable_fields"] == []
  44. assert result["platform_performance_score"] is not None
  45. def test_shipinhao_only_digg_supported_and_other_fields_natural_missing():
  46. result = performance_score({"digg_count": 500}, "shipinhao")
  47. assert [row["field"] for row in result["platform_performance_components"]] == [
  48. "statistics.digg_count"
  49. ]
  50. assert {row["field"] for row in result["missing_observable_fields"]} == {
  51. "statistics.comment_count",
  52. "statistics.share_count",
  53. "statistics.collect_count",
  54. "statistics.play_count",
  55. }
  56. def test_supported_field_absent_is_runtime_missing():
  57. result = performance_score({"digg_count": 10}, "douyin")
  58. runtime_missing = [
  59. row for row in result["missing_observable_fields"]
  60. if row.get("missing_type") == "runtime_missing"
  61. ]
  62. assert {row["field"] for row in runtime_missing} == {
  63. "statistics.comment_count",
  64. "statistics.share_count",
  65. "statistics.collect_count",
  66. }