图片解析应用
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.

66 lines
1.8 KiB

  1. import uuid
  2. import pytest
  3. from kazoo.testing import KazooTestCase
  4. class KazooCounterTests(KazooTestCase):
  5. def _makeOne(self, **kw):
  6. path = "/" + uuid.uuid4().hex
  7. return self.client.Counter(path, **kw)
  8. def test_int_counter(self):
  9. counter = self._makeOne()
  10. assert counter.value == 0
  11. counter += 2
  12. counter + 1
  13. assert counter.value == 3
  14. counter -= 3
  15. counter - 1
  16. assert counter.value == -1
  17. def test_int_curator_counter(self):
  18. counter = self._makeOne(support_curator=True)
  19. assert counter.value == 0
  20. counter += 2
  21. counter + 1
  22. assert counter.value == 3
  23. counter -= 3
  24. counter - 1
  25. assert counter.value == -1
  26. counter += 1
  27. counter += 2147483647
  28. assert counter.value == 2147483647
  29. counter -= 2147483647
  30. counter -= 2147483647
  31. assert counter.value == -2147483647
  32. def test_float_counter(self):
  33. counter = self._makeOne(default=0.0)
  34. assert counter.value == 0.0
  35. counter += 2.1
  36. assert counter.value == 2.1
  37. counter -= 3.1
  38. assert counter.value == -1.0
  39. def test_errors(self):
  40. counter = self._makeOne()
  41. with pytest.raises(TypeError):
  42. counter.__add__(2.1)
  43. with pytest.raises(TypeError):
  44. counter.__add__(b"a")
  45. with pytest.raises(TypeError):
  46. counter = self._makeOne(default=0.0, support_curator=True)
  47. def test_pre_post_values(self):
  48. counter = self._makeOne()
  49. assert counter.value == 0
  50. assert counter.pre_value is None
  51. assert counter.post_value is None
  52. counter += 2
  53. assert counter.pre_value == 0
  54. assert counter.post_value == 2
  55. counter -= 3
  56. assert counter.pre_value == 2
  57. assert counter.post_value == -1