test_read_incoming.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import pytest
  2. @pytest.mark.usefixtures("state")
  3. def test_read_incoming_node_none(state):
  4. b = state.create_node()
  5. assert b is not None
  6. l = state.read_incoming(b)
  7. assert l is not None
  8. assert set(l) == set([])
  9. @pytest.mark.usefixtures("state")
  10. def test_read_incoming_node_one(state):
  11. a = state.create_node()
  12. b = state.create_node()
  13. c = state.create_edge(a, b)
  14. assert a is not None
  15. assert b is not None
  16. assert c is not None
  17. l = state.read_incoming(a)
  18. assert l is not None
  19. assert set(l) == set([])
  20. l = state.read_incoming(b)
  21. assert l is not None
  22. assert set(l) == set([c])
  23. @pytest.mark.usefixtures("state")
  24. def test_read_incoming_node_multi(state):
  25. a = state.create_node()
  26. b = state.create_node()
  27. c = state.create_edge(a, b)
  28. d = state.create_edge(a, b)
  29. e = state.create_edge(a, b)
  30. assert a is not None
  31. assert b is not None
  32. assert c is not None
  33. assert d is not None
  34. assert e is not None
  35. l = state.read_incoming(a)
  36. assert l is not None
  37. assert set(l) == set([])
  38. l = state.read_incoming(b)
  39. assert l is not None
  40. assert set(l) == set([c, d, e])
  41. @pytest.mark.usefixtures("state")
  42. def test_read_incoming_node_multi_others_unaffected(state):
  43. a = state.create_node()
  44. b = state.create_node()
  45. c = state.create_edge(a, b)
  46. d = state.create_edge(a, b)
  47. e = state.create_edge(a, b)
  48. assert a is not None
  49. assert b is not None
  50. assert c is not None
  51. assert d is not None
  52. assert e is not None
  53. f = state.create_node()
  54. assert f is not None
  55. l = state.read_incoming(a)
  56. assert l is not None
  57. assert set(l) == set([])
  58. l = state.read_incoming(b)
  59. assert l is not None
  60. assert set(l) == set([c, d, e])
  61. l = state.read_incoming(f)
  62. assert l is not None
  63. assert set(l) == set([])
  64. @pytest.mark.usefixtures("state")
  65. def test_read_incoming_edge_none(state):
  66. a = state.create_node()
  67. b = state.create_node()
  68. c = state.create_edge(a, b)
  69. assert a is not None
  70. assert b is not None
  71. assert c is not None
  72. l = state.read_incoming(c)
  73. assert l is not None
  74. assert set(l) == set([])
  75. @pytest.mark.usefixtures("state")
  76. def test_read_incoming_edge_one(state):
  77. a = state.create_node()
  78. b = state.create_node()
  79. c = state.create_edge(a, b)
  80. d = state.create_edge(c, a)
  81. e = state.create_edge(a, c)
  82. assert a is not None
  83. assert b is not None
  84. assert c is not None
  85. assert d is not None
  86. assert e is not None
  87. l = state.read_incoming(c)
  88. assert l is not None
  89. assert set(l) == set([e])
  90. l = state.read_incoming(d)
  91. assert l is not None
  92. assert set(l) == set([])
  93. l = state.read_incoming(e)
  94. assert l is not None
  95. assert set(l) == set([])
  96. @pytest.mark.usefixtures("state")
  97. def test_read_incoming_edge_multi(state):
  98. a = state.create_node()
  99. b = state.create_node()
  100. c = state.create_edge(a, b)
  101. d = state.create_edge(a, c)
  102. e = state.create_edge(b, c)
  103. f = state.create_edge(d, c)
  104. assert a is not None
  105. assert b is not None
  106. assert c is not None
  107. assert d is not None
  108. assert e is not None
  109. assert f is not None
  110. l = state.read_incoming(b)
  111. assert l is not None
  112. assert set(l) == set([c])
  113. l = state.read_incoming(c)
  114. assert l is not None
  115. assert set(l) == set([d, e, f])
  116. l = state.read_incoming(d)
  117. assert l is not None
  118. assert set(l) == set([])
  119. l = state.read_incoming(e)
  120. assert l is not None
  121. assert set(l) == set([])
  122. l = state.read_incoming(f)
  123. assert l is not None
  124. assert set(l) == set([])
  125. @pytest.mark.usefixtures("state")
  126. def test_read_incoming_nodevalue_none(state):
  127. b = state.create_nodevalue(1)
  128. assert b is not None
  129. l = state.read_incoming(b)
  130. assert l is not None
  131. assert set(l) == set([])
  132. @pytest.mark.usefixtures("state")
  133. def test_read_incoming_nodevalue_one(state):
  134. a = state.create_nodevalue(1)
  135. b = state.create_node()
  136. c = state.create_edge(b, a)
  137. assert a is not None
  138. assert b is not None
  139. assert c is not None
  140. l = state.read_incoming(a)
  141. assert l is not None
  142. assert set(l) == set([c])
  143. l = state.read_incoming(b)
  144. assert l is not None
  145. assert set(l) == set([])
  146. @pytest.mark.usefixtures("state")
  147. def test_read_incoming_nodevalue_multi(state):
  148. a = state.create_nodevalue(1)
  149. b = state.create_node()
  150. c = state.create_edge(b, a)
  151. d = state.create_edge(b, a)
  152. e = state.create_edge(b, a)
  153. assert a is not None
  154. assert b is not None
  155. assert c is not None
  156. assert d is not None
  157. assert e is not None
  158. l = state.read_incoming(a)
  159. assert l is not None
  160. assert set(l) == set([c, d, e])
  161. l = state.read_incoming(b)
  162. assert l is not None
  163. assert set(l) == set([])
  164. @pytest.mark.usefixtures("state")
  165. def test_read_incoming_nodevalue_multi_others_unaffected(state):
  166. a = state.create_nodevalue(1)
  167. b = state.create_node()
  168. c = state.create_edge(b, a)
  169. d = state.create_edge(b, a)
  170. e = state.create_edge(b, a)
  171. assert a is not None
  172. assert b is not None
  173. assert c is not None
  174. assert d is not None
  175. assert e is not None
  176. f = state.create_nodevalue(1)
  177. assert f is not None
  178. l = state.read_incoming(a)
  179. assert l is not None
  180. assert set(l) == set([c, d, e])
  181. l = state.read_incoming(b)
  182. assert l is not None
  183. assert set(l) == set([])
  184. l = state.read_incoming(f)
  185. assert l is not None
  186. assert set(l) == set([])
  187. @pytest.mark.usefixtures("state")
  188. def test_read_incoming_node_deleted(state):
  189. b = state.create_node()
  190. assert b is not None
  191. n = state.delete_node(b)
  192. assert n is None
  193. l = state.read_incoming(b)
  194. assert l is None
  195. @pytest.mark.usefixtures("state")
  196. def test_read_incoming_nodevalue_deleted(state):
  197. b = state.create_nodevalue(1)
  198. assert b is not None
  199. n = state.delete_node(b)
  200. assert n is None
  201. l = state.read_incoming(b)
  202. assert l is None
  203. @pytest.mark.usefixtures("state")
  204. def test_read_incoming_edge_deleted(state):
  205. a = state.create_node()
  206. b = state.create_node()
  207. c = state.create_edge(a, b)
  208. assert a is not None
  209. assert b is not None
  210. assert c is not None
  211. n = state.delete_edge(c)
  212. assert n is None
  213. l = state.read_incoming(c)
  214. assert l is None