test_common.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. import _common as pc
  2. def test_sort_by_keywords():
  3. keywords = {'KEY1': 2, 'KEY2': 0, 'KEY3': 1}
  4. args = 'aaaa bbbb KEY2 KEY1 kkk10 kkk11 ccc ddd KEY3 kkk3 eee'.split()
  5. flat, spec = pc.sort_by_keywords(keywords, args)
  6. assert flat == ['aaaa', 'bbbb', 'ccc', 'ddd', 'eee']
  7. assert spec == {'KEY1': ['kkk10', 'kkk11'], 'KEY2': True, 'KEY3': ['kkk3']}
  8. keywords = {'KEY1': 0, 'KEY2': 4}
  9. args = 'aaaa KEY2 eee'.split()
  10. flat, spec = pc.sort_by_keywords(keywords, args)
  11. assert flat == ['aaaa']
  12. assert spec == {'KEY2': ['eee']}
  13. keywords = {'KEY1': 2, 'KEY2': 2}
  14. args = 'KEY1 k10 KEY2 k20 KEY1 k11 KEY2 k21 KEY1 k13'.split()
  15. flat, spec = pc.sort_by_keywords(keywords, args)
  16. assert flat == []
  17. assert spec == {'KEY1': ['k10', 'k11', 'k13'], 'KEY2': ['k20', 'k21']}
  18. def test_filter_out_by_keyword():
  19. assert pc.filter_out_by_keyword([], 'A') == []
  20. assert pc.filter_out_by_keyword(['x'], 'A') == ['x']
  21. assert pc.filter_out_by_keyword(['x', 'A'], 'A') == ['x']
  22. assert pc.filter_out_by_keyword(['x', 'A', 'B'], 'A') == ['x']
  23. assert pc.filter_out_by_keyword(['x', 'A', 'B', 'y'], 'A') == ['x', 'y']
  24. assert pc.filter_out_by_keyword(['x', 'A', 'A', 'y'], 'A') == ['x', 'y']
  25. assert pc.filter_out_by_keyword(['x', 'A', 'A', 'A'], 'A') == ['x']
  26. assert pc.filter_out_by_keyword(['x', 'A', 'A', 'A', 'B', 'y'], 'A') == ['x', 'y']
  27. assert pc.filter_out_by_keyword(['x', 'A', 'A', 'A', 'B', 'y', 'A'], 'A') == ['x', 'y']
  28. assert pc.filter_out_by_keyword(['x', 'A', 'A', 'A', 'B', 'y', 'A', 'F', 'z'], 'A') == ['x', 'y', 'z']