ctc_common_test.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import pytest
  2. from dw_base.spark.udf.contacts.ctc_common import get_shh_email_status
  3. from dw_base.spark.udf.contacts.ctc_common import clean_email_status
  4. @pytest.mark.parametrize("inv, level, expected", [
  5. (True, '-8', 'low'), # level <= -7 且 inv 为 True
  6. (False, '-8', 'high'), # level <= -7 且 inv 为 False
  7. (True, '-1', 'low'), # -7 < level <= 0 且 inv 为 True
  8. (False, '-1', 'middle'), # -7 < level <= 0 且 inv 为 False
  9. (True, 'invalid', 'low'), # 无效的 level 值(ValueError 异常)
  10. ])
  11. def test_get_shh_email_status(inv, level, expected):
  12. result = get_shh_email_status(inv, level)
  13. assert result == expected
  14. @pytest.mark.parametrize("source, match_level, expected", [
  15. ('shh', 1, 'PERFECT_MATCH'),
  16. ('shh', 2, 'SPECULATION_VERIFICATION'),
  17. ('shh', -1, 'SPECULATION_VERIFICATION'),
  18. ('shh', 0.95, 'POSSIBLE_MATCH'),
  19. ('shh', 0.5, 'LOW_MATCH'),
  20. ('snovio', 'valid', 'PERFECT_MATCH'),
  21. ('snovio', 'verified', 'PERFECT_MATCH')
  22. ])
  23. def test_clean_email_status_functionality(source, match_level, expected):
  24. result = clean_email_status(source, match_level)
  25. assert result == expected
  26. if __name__ == '__main__':
  27. pytest.main()