You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.6 KiB

  1. import pytest
  2. import calculate.templates.template_filters as filters
  3. class TestObj:
  4. def __str__(self):
  5. return "TestObj_value"
  6. @pytest.mark.parametrize('case',
  7. [
  8. {
  9. "name": "empty",
  10. "data": "",
  11. "params": (),
  12. "result": ""
  13. },
  14. {
  15. "name": "none value",
  16. "data": None,
  17. "params": (),
  18. "result": ""
  19. },
  20. {
  21. "name": "obj value",
  22. "data": TestObj(),
  23. "params": (),
  24. "result": "TestObj_value"
  25. },
  26. {
  27. "name": "default",
  28. "data": "123",
  29. "params": (),
  30. "result": "123"
  31. },
  32. {
  33. "name": "default with delimiter",
  34. "data": "123-456",
  35. "params": (),
  36. "result": "123"
  37. },
  38. {
  39. "name": "second field",
  40. "data": "123-456",
  41. "params": (1,),
  42. "result": "456"
  43. },
  44. {
  45. "name": "second field empty",
  46. "data": "",
  47. "params": (1,),
  48. "result": ""
  49. },
  50. {
  51. "name": "second field but one field",
  52. "data": "123",
  53. "params": (1,),
  54. "result": ""
  55. },
  56. {
  57. "name": "use dilimeter",
  58. "data": "123.456",
  59. "params": (1,"."),
  60. "result": "456"
  61. },
  62. ],
  63. ids=lambda x:x["name"])
  64. @pytest.mark.template_filters
  65. def test_filter_cut(case):
  66. assert filters.cut(case["data"], *case["params"]) == case["result"]