test_read_reverse_dict.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import pytest
  2. @pytest.mark.usefixtures("state")
  3. def test_read_reverse_dict_no_exists(state):
  4. l = state.read_reverse_dict(-1, "abc")
  5. assert l is None
  6. @pytest.mark.usefixtures("state")
  7. def test_read_reverse_dict_not_found_node(state):
  8. a = state.create_node()
  9. assert a is not None
  10. # Passing data is not enforced, as the data will be interpreted if necessary
  11. l = state.read_reverse_dict(a, "abc")
  12. assert l == []
  13. @pytest.mark.usefixtures("state")
  14. def test_read_reverse_dict_not_found_nodevalue(state):
  15. a = state.create_nodevalue(1)
  16. assert a is not None
  17. # Passing data is not enforced, as the data will be interpreted if necessary
  18. l = state.read_reverse_dict(a, "abc")
  19. assert l == []
  20. @pytest.mark.usefixtures("state")
  21. def test_read_reverse_dict_not_found_edge(state):
  22. a = state.create_node()
  23. b = state.create_node()
  24. c = state.create_edge(a, b)
  25. assert a is not None
  26. assert b is not None
  27. assert c is not None
  28. # Passing data is not enforced, as the data will be interpreted if necessary
  29. l = state.read_reverse_dict(c, "abc")
  30. assert l == []
  31. @pytest.mark.usefixtures("state")
  32. def test_read_reverse_dict_no_primitive(state):
  33. a = state.create_node()
  34. assert a is not None
  35. # Passing data is not enforced, as the data will be interpreted if necessary
  36. l = state.read_reverse_dict(a, a)
  37. assert l == []
  38. @pytest.mark.usefixtures("state")
  39. def test_read_reverse_dict_node_simple(state):
  40. a = state.create_node()
  41. b = state.create_node()
  42. c = state.create_nodevalue("f")
  43. d = state.create_edge(a, b)
  44. e = state.create_edge(d, c)
  45. assert a is not None
  46. assert b is not None
  47. assert c is not None
  48. assert d is not None
  49. assert e is not None
  50. l = state.read_reverse_dict(b, "f")
  51. assert set(l) == set([a])
  52. @pytest.mark.usefixtures("state")
  53. def test_read_reverse_dict_no_match(state):
  54. a = state.create_node()
  55. b = state.create_node()
  56. c = state.create_nodevalue("g")
  57. d = state.create_edge(a, b)
  58. e = state.create_edge(d, c)
  59. assert a is not None
  60. assert b is not None
  61. assert c is not None
  62. assert d is not None
  63. assert e is not None
  64. l = state.read_reverse_dict(b, "f")
  65. assert l == []
  66. @pytest.mark.usefixtures("state")
  67. def test_read_reverse_dict_node_multi(state):
  68. a = state.create_node()
  69. b = state.create_node()
  70. c = state.create_nodevalue("f")
  71. d = state.create_edge(a, b)
  72. e = state.create_edge(d, c)
  73. assert a is not None
  74. assert b is not None
  75. assert c is not None
  76. assert d is not None
  77. assert e is not None
  78. g = state.create_node()
  79. h = state.create_nodevalue("k")
  80. i = state.create_edge(a, g)
  81. j = state.create_edge(i, h)
  82. assert g is not None
  83. assert h is not None
  84. assert i is not None
  85. assert j is not None
  86. l = state.read_reverse_dict(b, "f")
  87. assert set(l) == set([a])
  88. l = state.read_reverse_dict(g, "k")
  89. assert set(l) == set([a])
  90. l = state.read_reverse_dict(a, "l")
  91. assert l == []
  92. @pytest.mark.usefixtures("state")
  93. def test_read_reverse_dict_node_multi_ambiguous(state):
  94. a = state.create_node()
  95. b = state.create_node()
  96. c = state.create_nodevalue("f")
  97. d = state.create_edge(b, a)
  98. e = state.create_edge(d, c)
  99. assert a is not None
  100. assert b is not None
  101. assert c is not None
  102. assert d is not None
  103. assert e is not None
  104. g = state.create_node()
  105. h = state.create_nodevalue("f")
  106. i = state.create_edge(g, a)
  107. j = state.create_edge(i, h)
  108. assert g is not None
  109. assert h is not None
  110. assert i is not None
  111. assert j is not None
  112. l = state.read_reverse_dict(a, "f")
  113. assert set(l) == set([b, g])
  114. @pytest.mark.usefixtures("state")
  115. def test_read_reverse_dict_node_uncertain(state):
  116. a = state.create_node()
  117. b = state.create_node()
  118. c = state.create_nodevalue("f")
  119. d = state.create_edge(a, b)
  120. e = state.create_edge(d, c)
  121. assert a is not None
  122. assert b is not None
  123. assert c is not None
  124. assert d is not None
  125. assert e is not None
  126. h = state.create_nodevalue("g")
  127. i = state.create_edge(d, h)
  128. assert h is not None
  129. assert i is not None
  130. l = state.read_reverse_dict(b, "f")
  131. assert set(l) == set([a])