test_read_value.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import pytest
  2. @pytest.mark.usefixtures("state")
  3. def test_read_value_different_id_simple(state):
  4. id1 = state.create_nodevalue(1)
  5. id2 = state.create_nodevalue(2)
  6. assert id1 is not None
  7. assert id2 is not None
  8. v1 = state.read_value(id1)
  9. v2 = state.read_value(id2)
  10. assert v1 == 1
  11. assert v2 == 2
  12. @pytest.mark.usefixtures("state")
  13. def test_read_value_integer_ib_negative(state):
  14. # Just within range
  15. for i in range(-2 ** 63, -2 ** 63 + 10):
  16. id1 = state.create_nodevalue(i)
  17. assert id1 is not None
  18. v = state.read_value(id1)
  19. assert v == i
  20. @pytest.mark.usefixtures("state")
  21. def test_read_value_integer_ib_zero(state):
  22. # Nicely within range
  23. for i in range(-10, 10):
  24. id1 = state.create_nodevalue(i)
  25. assert id1 is not None
  26. v = state.read_value(id1)
  27. assert v == i
  28. @pytest.mark.usefixtures("state")
  29. def test_read_value_integer_ib_positive(state):
  30. # Just within range
  31. for i in range(2 ** 63 - 10, 2 ** 63):
  32. id1 = state.create_nodevalue(i)
  33. assert id1 is not None
  34. v = state.read_value(id1)
  35. assert v == i
  36. @pytest.mark.usefixtures("state")
  37. def test_read_value_boolean(state):
  38. id1 = state.create_nodevalue(True)
  39. id2 = state.create_nodevalue(False)
  40. assert id1 is not None
  41. assert id2 is not None
  42. v1 = state.read_value(id1)
  43. v2 = state.read_value(id2)
  44. assert v1 == True
  45. assert v2 == False
  46. @pytest.mark.usefixtures("state")
  47. def test_read_nodevalue_boolean_same(state):
  48. id1 = state.create_nodevalue(True)
  49. id2 = state.create_nodevalue(True)
  50. assert id1 is not None
  51. assert id2 is not None
  52. v1 = state.read_value(id1)
  53. v2 = state.read_value(id2)
  54. assert v1 == True
  55. assert v2 == True
  56. @pytest.mark.usefixtures("state")
  57. def test_read_value_no_exist(state):
  58. v1 = state.read_value(100000)
  59. assert v1 is None
  60. @pytest.mark.usefixtures("state")
  61. def test_read_value_no_value(state):
  62. id1 = state.create_node()
  63. assert id1 is not None
  64. v1 = state.read_value(id1)
  65. assert v1 is None