okstra 0.114.0 → 0.115.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (326) hide show
  1. package/docs/kr/architecture.md +2 -2
  2. package/docs/kr/follow-ups/2026-07-10-final-report-option-3.md +51 -0
  3. package/package.json +1 -1
  4. package/runtime/BUILD.json +2 -2
  5. package/runtime/agents/workers/report-writer-worker.md +1 -0
  6. package/runtime/prompts/lead/okstra-lead-contract.md +1 -1
  7. package/runtime/python/okstra_ctl/implementation_stage.py +46 -39
  8. package/runtime/python/okstra_ctl/report_views.py +151 -12
  9. package/runtime/python/okstra_ctl/run.py +24 -24
  10. package/runtime/python/okstra_ctl/worktree.py +1 -1
  11. package/runtime/python/okstra_token_usage/claude.py +58 -19
  12. package/runtime/python/okstra_token_usage/collect.py +3 -1
  13. package/runtime/python/okstra_vendor/__init__.py +3 -0
  14. package/runtime/schemas/final-report-v1.0.schema.json +20 -0
  15. package/runtime/templates/reports/final-report.template.md +14 -0
  16. package/runtime/templates/reports/i18n/en.json +23 -12
  17. package/runtime/templates/reports/i18n/ko.json +23 -12
  18. package/runtime/templates/reports/report.css +55 -0
  19. package/runtime/templates/reports/report.js +53 -1
  20. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/__init__.py +0 -0
  21. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py +0 -41
  22. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_clique.py +0 -112
  23. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_connectivity.py +0 -199
  24. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_density.py +0 -146
  25. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_distance_measures.py +0 -59
  26. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_dominating_set.py +0 -78
  27. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_kcomponents.py +0 -303
  28. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_matching.py +0 -8
  29. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_maxcut.py +0 -94
  30. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_ramsey.py +0 -31
  31. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_steinertree.py +0 -306
  32. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_traveling_salesman.py +0 -1014
  33. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_treewidth.py +0 -274
  34. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_vertex_cover.py +0 -68
  35. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/__init__.py +0 -0
  36. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/base_test.py +0 -81
  37. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_connectivity.py +0 -143
  38. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_correlation.py +0 -122
  39. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_mixing.py +0 -174
  40. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_neighbor_degree.py +0 -107
  41. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_pairs.py +0 -87
  42. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/__init__.py +0 -0
  43. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_basic.py +0 -125
  44. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_centrality.py +0 -192
  45. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_cluster.py +0 -84
  46. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_covering.py +0 -33
  47. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_edgelist.py +0 -240
  48. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_extendability.py +0 -334
  49. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_generators.py +0 -407
  50. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_link_analysis.py +0 -218
  51. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matching.py +0 -327
  52. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matrix.py +0 -138
  53. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_project.py +0 -409
  54. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_redundancy.py +0 -35
  55. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py +0 -80
  56. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/__init__.py +0 -0
  57. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality.py +0 -923
  58. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality_subset.py +0 -354
  59. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_closeness_centrality.py +0 -274
  60. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py +0 -259
  61. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py +0 -147
  62. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_closeness.py +0 -43
  63. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_degree_centrality.py +0 -144
  64. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_dispersion.py +0 -73
  65. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py +0 -186
  66. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_group.py +0 -277
  67. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_harmonic_centrality.py +0 -122
  68. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_katz_centrality.py +0 -345
  69. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_laplacian_centrality.py +0 -220
  70. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_load_centrality.py +0 -344
  71. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_percolation_centrality.py +0 -87
  72. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_reaching.py +0 -140
  73. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_second_order_centrality.py +0 -82
  74. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_subgraph.py +0 -110
  75. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_trophic.py +0 -302
  76. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_voterank.py +0 -64
  77. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/__init__.py +0 -0
  78. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/test_coloring.py +0 -863
  79. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/__init__.py +0 -0
  80. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_asyn_fluid.py +0 -147
  81. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_bipartitions.py +0 -157
  82. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_centrality.py +0 -85
  83. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_divisive.py +0 -106
  84. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_kclique.py +0 -91
  85. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_label_propagation.py +0 -241
  86. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_leiden.py +0 -138
  87. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_local.py +0 -76
  88. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_louvain.py +0 -264
  89. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_lukes.py +0 -152
  90. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_modularity_max.py +0 -340
  91. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_quality.py +0 -139
  92. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_utils.py +0 -26
  93. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/__init__.py +0 -0
  94. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_attracting.py +0 -70
  95. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_biconnected.py +0 -248
  96. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_connected.py +0 -138
  97. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_semiconnected.py +0 -55
  98. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_strongly_connected.py +0 -193
  99. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_weakly_connected.py +0 -96
  100. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/__init__.py +0 -0
  101. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_connectivity.py +0 -421
  102. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_cuts.py +0 -309
  103. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_disjoint_paths.py +0 -249
  104. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_augmentation.py +0 -502
  105. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py +0 -488
  106. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcomponents.py +0 -323
  107. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcutsets.py +0 -280
  108. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_stoer_wagner.py +0 -102
  109. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/__init__.py +0 -0
  110. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gl1.gpickle.bz2 +0 -0
  111. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gw1.gpickle.bz2 +0 -0
  112. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/netgen-2.gpickle.bz2 +0 -0
  113. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_gomory_hu.py +0 -128
  114. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow.py +0 -573
  115. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow_large_graph.py +0 -155
  116. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_mincost.py +0 -475
  117. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_networksimplex.py +0 -481
  118. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/wlm3.gpickle.bz2 +0 -0
  119. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/__init__.py +0 -0
  120. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.A99 +0 -0
  121. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.B99 +0 -0
  122. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.A99 +0 -0
  123. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.B99 +0 -0
  124. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_ismags.py +0 -719
  125. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphism.py +0 -103
  126. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py +0 -490
  127. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_match_helpers.py +0 -64
  128. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py +0 -212
  129. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py +0 -202
  130. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp.py +0 -1655
  131. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp_helpers.py +0 -3118
  132. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py +0 -196
  133. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/__init__.py +0 -0
  134. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_hits.py +0 -77
  135. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_pagerank.py +0 -213
  136. package/runtime/python/okstra_vendor/networkx/algorithms/minors/tests/test_contraction.py +0 -544
  137. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/__init__.py +0 -0
  138. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_all.py +0 -328
  139. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_binary.py +0 -451
  140. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_product.py +0 -491
  141. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_unary.py +0 -55
  142. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/__init__.py +0 -0
  143. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_astar.py +0 -254
  144. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense.py +0 -212
  145. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py +0 -88
  146. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_generic.py +0 -511
  147. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_unweighted.py +0 -149
  148. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_weighted.py +0 -983
  149. package/runtime/python/okstra_vendor/networkx/algorithms/tests/__init__.py +0 -0
  150. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_asteroidal.py +0 -23
  151. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_boundary.py +0 -154
  152. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_bridges.py +0 -144
  153. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_broadcasting.py +0 -109
  154. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chains.py +0 -136
  155. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chordal.py +0 -129
  156. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_clique.py +0 -300
  157. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cluster.py +0 -678
  158. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_communicability.py +0 -80
  159. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_core.py +0 -266
  160. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_covering.py +0 -85
  161. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cuts.py +0 -171
  162. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cycles.py +0 -984
  163. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_d_separation.py +0 -340
  164. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dag.py +0 -835
  165. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_measures.py +0 -831
  166. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_regular.py +0 -85
  167. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominance.py +0 -299
  168. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominating.py +0 -115
  169. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_efficiency.py +0 -58
  170. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_euler.py +0 -314
  171. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graph_hashing.py +0 -872
  172. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graphical.py +0 -163
  173. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hierarchy.py +0 -46
  174. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hybrid.py +0 -24
  175. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_isolate.py +0 -26
  176. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_link_prediction.py +0 -615
  177. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_lowest_common_ancestors.py +0 -459
  178. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_matching.py +0 -556
  179. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_max_weight_clique.py +0 -179
  180. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_mis.py +0 -62
  181. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_moral.py +0 -15
  182. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_node_classification.py +0 -140
  183. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_non_randomness.py +0 -60
  184. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_perfect_graph.py +0 -27
  185. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planar_drawing.py +0 -274
  186. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planarity.py +0 -556
  187. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_polynomials.py +0 -57
  188. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_reciprocity.py +0 -37
  189. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_regular.py +0 -88
  190. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_richclub.py +0 -149
  191. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_similarity.py +0 -1158
  192. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_simple_paths.py +0 -803
  193. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smallworld.py +0 -76
  194. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smetric.py +0 -8
  195. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_sparsifiers.py +0 -138
  196. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_structuralholes.py +0 -191
  197. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_summarization.py +0 -642
  198. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_swap.py +0 -179
  199. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_threshold.py +0 -270
  200. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_time_dependent.py +0 -431
  201. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_tournament.py +0 -161
  202. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_triads.py +0 -248
  203. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_vitality.py +0 -41
  204. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_voronoi.py +0 -103
  205. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_walks.py +0 -54
  206. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_wiener.py +0 -157
  207. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/__init__.py +0 -0
  208. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_beamsearch.py +0 -25
  209. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_bfs.py +0 -203
  210. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_dfs.py +0 -307
  211. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgebfs.py +0 -147
  212. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgedfs.py +0 -131
  213. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/__init__.py +0 -0
  214. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_branchings.py +0 -624
  215. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_coding.py +0 -114
  216. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_decomposition.py +0 -79
  217. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_distance_measures.py +0 -99
  218. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_mst.py +0 -934
  219. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_operations.py +0 -53
  220. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_recognition.py +0 -174
  221. package/runtime/python/okstra_vendor/networkx/classes/tests/__init__.py +0 -0
  222. package/runtime/python/okstra_vendor/networkx/classes/tests/dispatch_interface.py +0 -192
  223. package/runtime/python/okstra_vendor/networkx/classes/tests/historical_tests.py +0 -476
  224. package/runtime/python/okstra_vendor/networkx/classes/tests/test_coreviews.py +0 -362
  225. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph.py +0 -331
  226. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph_historical.py +0 -110
  227. package/runtime/python/okstra_vendor/networkx/classes/tests/test_filters.py +0 -177
  228. package/runtime/python/okstra_vendor/networkx/classes/tests/test_function.py +0 -1045
  229. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph.py +0 -950
  230. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph_historical.py +0 -12
  231. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graphviews.py +0 -349
  232. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multidigraph.py +0 -459
  233. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multigraph.py +0 -528
  234. package/runtime/python/okstra_vendor/networkx/classes/tests/test_reportviews.py +0 -1421
  235. package/runtime/python/okstra_vendor/networkx/classes/tests/test_special.py +0 -131
  236. package/runtime/python/okstra_vendor/networkx/classes/tests/test_subgraphviews.py +0 -371
  237. package/runtime/python/okstra_vendor/networkx/conftest.py +0 -261
  238. package/runtime/python/okstra_vendor/networkx/drawing/tests/__init__.py +0 -0
  239. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_complex.png +0 -0
  240. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_empty_graph.png +0 -0
  241. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_house_with_colors.png +0 -0
  242. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_labels_and_colors.png +0 -0
  243. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_shortest_path.png +0 -0
  244. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_house_with_colors.png +0 -0
  245. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_agraph.py +0 -237
  246. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_image_comparison_pylab_mpl.py +0 -229
  247. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_latex.py +0 -285
  248. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_layout.py +0 -631
  249. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pydot.py +0 -146
  250. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pylab.py +0 -1582
  251. package/runtime/python/okstra_vendor/networkx/generators/tests/__init__.py +0 -0
  252. package/runtime/python/okstra_vendor/networkx/generators/tests/test_atlas.py +0 -75
  253. package/runtime/python/okstra_vendor/networkx/generators/tests/test_classic.py +0 -642
  254. package/runtime/python/okstra_vendor/networkx/generators/tests/test_cographs.py +0 -20
  255. package/runtime/python/okstra_vendor/networkx/generators/tests/test_community.py +0 -362
  256. package/runtime/python/okstra_vendor/networkx/generators/tests/test_degree_seq.py +0 -224
  257. package/runtime/python/okstra_vendor/networkx/generators/tests/test_directed.py +0 -189
  258. package/runtime/python/okstra_vendor/networkx/generators/tests/test_duplication.py +0 -103
  259. package/runtime/python/okstra_vendor/networkx/generators/tests/test_ego.py +0 -39
  260. package/runtime/python/okstra_vendor/networkx/generators/tests/test_expanders.py +0 -182
  261. package/runtime/python/okstra_vendor/networkx/generators/tests/test_geometric.py +0 -488
  262. package/runtime/python/okstra_vendor/networkx/generators/tests/test_harary_graph.py +0 -133
  263. package/runtime/python/okstra_vendor/networkx/generators/tests/test_internet_as_graphs.py +0 -221
  264. package/runtime/python/okstra_vendor/networkx/generators/tests/test_intersection.py +0 -28
  265. package/runtime/python/okstra_vendor/networkx/generators/tests/test_interval_graph.py +0 -144
  266. package/runtime/python/okstra_vendor/networkx/generators/tests/test_joint_degree_seq.py +0 -125
  267. package/runtime/python/okstra_vendor/networkx/generators/tests/test_lattice.py +0 -264
  268. package/runtime/python/okstra_vendor/networkx/generators/tests/test_line.py +0 -316
  269. package/runtime/python/okstra_vendor/networkx/generators/tests/test_mycielski.py +0 -30
  270. package/runtime/python/okstra_vendor/networkx/generators/tests/test_nonisomorphic_trees.py +0 -82
  271. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_clustered.py +0 -33
  272. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_graphs.py +0 -495
  273. package/runtime/python/okstra_vendor/networkx/generators/tests/test_small.py +0 -220
  274. package/runtime/python/okstra_vendor/networkx/generators/tests/test_spectral_graph_forge.py +0 -49
  275. package/runtime/python/okstra_vendor/networkx/generators/tests/test_stochastic.py +0 -72
  276. package/runtime/python/okstra_vendor/networkx/generators/tests/test_sudoku.py +0 -92
  277. package/runtime/python/okstra_vendor/networkx/generators/tests/test_time_series.py +0 -64
  278. package/runtime/python/okstra_vendor/networkx/generators/tests/test_trees.py +0 -195
  279. package/runtime/python/okstra_vendor/networkx/generators/tests/test_triads.py +0 -15
  280. package/runtime/python/okstra_vendor/networkx/linalg/tests/__init__.py +0 -0
  281. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_algebraic_connectivity.py +0 -400
  282. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_attrmatrix.py +0 -108
  283. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_bethehessian.py +0 -40
  284. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_graphmatrix.py +0 -275
  285. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_laplacian.py +0 -334
  286. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_modularity.py +0 -86
  287. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_spectrum.py +0 -70
  288. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/__init__.py +0 -0
  289. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_adjacency.py +0 -78
  290. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_cytoscape.py +0 -78
  291. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_node_link.py +0 -109
  292. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_tree.py +0 -48
  293. package/runtime/python/okstra_vendor/networkx/readwrite/tests/__init__.py +0 -0
  294. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_adjlist.py +0 -354
  295. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_edgelist.py +0 -318
  296. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gexf.py +0 -612
  297. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gml.py +0 -744
  298. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graph6.py +0 -181
  299. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graphml.py +0 -1531
  300. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_leda.py +0 -30
  301. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_p2g.py +0 -63
  302. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_pajek.py +0 -128
  303. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_sparse6.py +0 -166
  304. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_text.py +0 -1742
  305. package/runtime/python/okstra_vendor/networkx/tests/__init__.py +0 -0
  306. package/runtime/python/okstra_vendor/networkx/tests/test_all_random_functions.py +0 -248
  307. package/runtime/python/okstra_vendor/networkx/tests/test_convert.py +0 -321
  308. package/runtime/python/okstra_vendor/networkx/tests/test_convert_numpy.py +0 -531
  309. package/runtime/python/okstra_vendor/networkx/tests/test_convert_pandas.py +0 -349
  310. package/runtime/python/okstra_vendor/networkx/tests/test_convert_scipy.py +0 -281
  311. package/runtime/python/okstra_vendor/networkx/tests/test_exceptions.py +0 -40
  312. package/runtime/python/okstra_vendor/networkx/tests/test_import.py +0 -11
  313. package/runtime/python/okstra_vendor/networkx/tests/test_lazy_imports.py +0 -96
  314. package/runtime/python/okstra_vendor/networkx/tests/test_relabel.py +0 -349
  315. package/runtime/python/okstra_vendor/networkx/tests/test_removed_functions_exception_messages.py +0 -8
  316. package/runtime/python/okstra_vendor/networkx/utils/tests/__init__.py +0 -0
  317. package/runtime/python/okstra_vendor/networkx/utils/tests/test__init.py +0 -11
  318. package/runtime/python/okstra_vendor/networkx/utils/tests/test_backends.py +0 -225
  319. package/runtime/python/okstra_vendor/networkx/utils/tests/test_config.py +0 -263
  320. package/runtime/python/okstra_vendor/networkx/utils/tests/test_decorators.py +0 -510
  321. package/runtime/python/okstra_vendor/networkx/utils/tests/test_heaps.py +0 -131
  322. package/runtime/python/okstra_vendor/networkx/utils/tests/test_mapped_queue.py +0 -268
  323. package/runtime/python/okstra_vendor/networkx/utils/tests/test_misc.py +0 -393
  324. package/runtime/python/okstra_vendor/networkx/utils/tests/test_random_sequence.py +0 -53
  325. package/runtime/python/okstra_vendor/networkx/utils/tests/test_rcm.py +0 -63
  326. package/runtime/python/okstra_vendor/networkx/utils/tests/test_unionfind.py +0 -55
@@ -1,1045 +0,0 @@
1
- import random
2
-
3
- import pytest
4
-
5
- import networkx as nx
6
- from networkx.utils import edges_equal, nodes_equal
7
-
8
-
9
- def test_degree_histogram_empty():
10
- G = nx.Graph()
11
- assert nx.degree_histogram(G) == []
12
-
13
-
14
- class TestFunction:
15
- def setup_method(self):
16
- self.G = nx.Graph({0: [1, 2, 3], 1: [1, 2, 0], 4: []}, name="Test")
17
- self.Gdegree = {0: 3, 1: 2, 2: 2, 3: 1, 4: 0}
18
- self.Gnodes = list(range(5))
19
- self.Gedges = [(0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2)]
20
- self.DG = nx.DiGraph({0: [1, 2, 3], 1: [1, 2, 0], 4: []})
21
- self.DGin_degree = {0: 1, 1: 2, 2: 2, 3: 1, 4: 0}
22
- self.DGout_degree = {0: 3, 1: 3, 2: 0, 3: 0, 4: 0}
23
- self.DGnodes = list(range(5))
24
- self.DGedges = [(0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2)]
25
-
26
- def test_describe_info_dict(self):
27
- info_dict = nx.classes.function._create_describe_info_dict(self.G)
28
- assert info_dict["Name of Graph"] == "Test"
29
- assert not info_dict["Directed"]
30
- assert not info_dict["Multigraph"]
31
- assert info_dict["Number of nodes"] == 5
32
- assert info_dict["Number of edges"] == 5
33
- assert info_dict["Average degree (min, max)"] == "2.00 (0, 4)"
34
- assert info_dict["Number of connected components"] == 2
35
-
36
- def test_nodes(self):
37
- assert nodes_equal(self.G.nodes(), list(nx.nodes(self.G)))
38
- assert nodes_equal(self.DG.nodes(), list(nx.nodes(self.DG)))
39
-
40
- def test_edges(self):
41
- assert edges_equal(self.G.edges(), list(nx.edges(self.G)))
42
- assert sorted(self.DG.edges()) == sorted(nx.edges(self.DG))
43
- assert edges_equal(
44
- self.G.edges(nbunch=[0, 1, 3]), list(nx.edges(self.G, nbunch=[0, 1, 3]))
45
- )
46
- assert sorted(self.DG.edges(nbunch=[0, 1, 3])) == sorted(
47
- nx.edges(self.DG, nbunch=[0, 1, 3])
48
- )
49
-
50
- def test_degree(self):
51
- assert edges_equal(self.G.degree(), list(nx.degree(self.G)))
52
- assert sorted(self.DG.degree()) == sorted(nx.degree(self.DG))
53
- assert edges_equal(
54
- self.G.degree(nbunch=[0, 1]), list(nx.degree(self.G, nbunch=[0, 1]))
55
- )
56
- assert sorted(self.DG.degree(nbunch=[0, 1])) == sorted(
57
- nx.degree(self.DG, nbunch=[0, 1])
58
- )
59
- assert edges_equal(
60
- self.G.degree(weight="weight"), list(nx.degree(self.G, weight="weight"))
61
- )
62
- assert sorted(self.DG.degree(weight="weight")) == sorted(
63
- nx.degree(self.DG, weight="weight")
64
- )
65
-
66
- def test_neighbors(self):
67
- assert list(self.G.neighbors(1)) == list(nx.neighbors(self.G, 1))
68
- assert list(self.DG.neighbors(1)) == list(nx.neighbors(self.DG, 1))
69
-
70
- def test_number_of_nodes(self):
71
- assert self.G.number_of_nodes() == nx.number_of_nodes(self.G)
72
- assert self.DG.number_of_nodes() == nx.number_of_nodes(self.DG)
73
-
74
- def test_number_of_edges(self):
75
- assert self.G.number_of_edges() == nx.number_of_edges(self.G)
76
- assert self.DG.number_of_edges() == nx.number_of_edges(self.DG)
77
-
78
- def test_is_directed(self):
79
- assert self.G.is_directed() == nx.is_directed(self.G)
80
- assert self.DG.is_directed() == nx.is_directed(self.DG)
81
-
82
- def test_add_star(self):
83
- G = self.G.copy()
84
- nlist = [12, 13, 14, 15]
85
- nx.add_star(G, nlist)
86
- assert edges_equal(G.edges(nlist), [(12, 13), (12, 14), (12, 15)])
87
-
88
- G = self.G.copy()
89
- nx.add_star(G, nlist, weight=2.0)
90
- assert edges_equal(
91
- G.edges(nlist, data=True),
92
- [
93
- (12, 13, {"weight": 2.0}),
94
- (12, 14, {"weight": 2.0}),
95
- (12, 15, {"weight": 2.0}),
96
- ],
97
- )
98
-
99
- G = self.G.copy()
100
- nlist = [12]
101
- nx.add_star(G, nlist)
102
- assert nodes_equal(G, list(self.G) + nlist)
103
-
104
- G = self.G.copy()
105
- nlist = []
106
- nx.add_star(G, nlist)
107
- assert nodes_equal(G.nodes, self.Gnodes)
108
- assert edges_equal(G.edges, self.G.edges)
109
-
110
- def test_add_path(self):
111
- G = self.G.copy()
112
- nlist = [12, 13, 14, 15]
113
- nx.add_path(G, nlist)
114
- assert edges_equal(G.edges(nlist), [(12, 13), (13, 14), (14, 15)])
115
- G = self.G.copy()
116
- nx.add_path(G, nlist, weight=2.0)
117
- assert edges_equal(
118
- G.edges(nlist, data=True),
119
- [
120
- (12, 13, {"weight": 2.0}),
121
- (13, 14, {"weight": 2.0}),
122
- (14, 15, {"weight": 2.0}),
123
- ],
124
- )
125
-
126
- G = self.G.copy()
127
- nlist = ["node"]
128
- nx.add_path(G, nlist)
129
- assert edges_equal(G.edges(nlist), [])
130
- assert nodes_equal(G, list(self.G) + ["node"])
131
-
132
- G = self.G.copy()
133
- nlist = iter(["node"])
134
- nx.add_path(G, nlist)
135
- assert edges_equal(G.edges(["node"]), [])
136
- assert nodes_equal(G, list(self.G) + ["node"])
137
-
138
- G = self.G.copy()
139
- nlist = [12]
140
- nx.add_path(G, nlist)
141
- assert edges_equal(G.edges(nlist), [])
142
- assert nodes_equal(G, list(self.G) + [12])
143
-
144
- G = self.G.copy()
145
- nlist = iter([12])
146
- nx.add_path(G, nlist)
147
- assert edges_equal(G.edges([12]), [])
148
- assert nodes_equal(G, list(self.G) + [12])
149
-
150
- G = self.G.copy()
151
- nlist = []
152
- nx.add_path(G, nlist)
153
- assert edges_equal(G.edges, self.G.edges)
154
- assert nodes_equal(G, list(self.G))
155
-
156
- G = self.G.copy()
157
- nlist = iter([])
158
- nx.add_path(G, nlist)
159
- assert edges_equal(G.edges, self.G.edges)
160
- assert nodes_equal(G, list(self.G))
161
-
162
- def test_add_cycle(self):
163
- G = self.G.copy()
164
- nlist = [12, 13, 14, 15]
165
- oklists = [
166
- [(12, 13), (12, 15), (13, 14), (14, 15)],
167
- [(12, 13), (13, 14), (14, 15), (15, 12)],
168
- ]
169
- nx.add_cycle(G, nlist)
170
- assert sorted(G.edges(nlist)) in oklists
171
- G = self.G.copy()
172
- oklists = [
173
- [
174
- (12, 13, {"weight": 1.0}),
175
- (12, 15, {"weight": 1.0}),
176
- (13, 14, {"weight": 1.0}),
177
- (14, 15, {"weight": 1.0}),
178
- ],
179
- [
180
- (12, 13, {"weight": 1.0}),
181
- (13, 14, {"weight": 1.0}),
182
- (14, 15, {"weight": 1.0}),
183
- (15, 12, {"weight": 1.0}),
184
- ],
185
- ]
186
- nx.add_cycle(G, nlist, weight=1.0)
187
- assert sorted(G.edges(nlist, data=True)) in oklists
188
-
189
- G = self.G.copy()
190
- nlist = [12]
191
- nx.add_cycle(G, nlist)
192
- assert nodes_equal(G, list(self.G) + nlist)
193
-
194
- G = self.G.copy()
195
- nlist = []
196
- nx.add_cycle(G, nlist)
197
- assert nodes_equal(G.nodes, self.Gnodes)
198
- assert edges_equal(G.edges, self.G.edges)
199
-
200
- def test_subgraph(self):
201
- assert (
202
- self.G.subgraph([0, 1, 2, 4]).adj == nx.subgraph(self.G, [0, 1, 2, 4]).adj
203
- )
204
- assert (
205
- self.DG.subgraph([0, 1, 2, 4]).adj == nx.subgraph(self.DG, [0, 1, 2, 4]).adj
206
- )
207
- assert (
208
- self.G.subgraph([0, 1, 2, 4]).adj
209
- == nx.induced_subgraph(self.G, [0, 1, 2, 4]).adj
210
- )
211
- assert (
212
- self.DG.subgraph([0, 1, 2, 4]).adj
213
- == nx.induced_subgraph(self.DG, [0, 1, 2, 4]).adj
214
- )
215
- # subgraph-subgraph chain is allowed in function interface
216
- H = nx.induced_subgraph(self.G.subgraph([0, 1, 2, 4]), [0, 1, 4])
217
- assert H._graph is not self.G
218
- assert H.adj == self.G.subgraph([0, 1, 4]).adj
219
-
220
- def test_edge_subgraph(self):
221
- assert (
222
- self.G.edge_subgraph([(1, 2), (0, 3)]).adj
223
- == nx.edge_subgraph(self.G, [(1, 2), (0, 3)]).adj
224
- )
225
- assert (
226
- self.DG.edge_subgraph([(1, 2), (0, 3)]).adj
227
- == nx.edge_subgraph(self.DG, [(1, 2), (0, 3)]).adj
228
- )
229
-
230
- def test_create_empty_copy(self):
231
- G = nx.create_empty_copy(self.G, with_data=False)
232
- assert nodes_equal(G, list(self.G))
233
- assert G.graph == {}
234
- assert G._node == {}.fromkeys(self.G.nodes(), {})
235
- assert G._adj == {}.fromkeys(self.G.nodes(), {})
236
- G = nx.create_empty_copy(self.G)
237
- assert nodes_equal(G, list(self.G))
238
- assert G.graph == self.G.graph
239
- assert G._node == self.G._node
240
- assert G._adj == {}.fromkeys(self.G.nodes(), {})
241
-
242
- def test_degree_histogram(self):
243
- assert nx.degree_histogram(self.G) == [1, 1, 1, 1, 1]
244
-
245
- def test_density(self):
246
- assert nx.density(self.G) == 0.5
247
- assert nx.density(self.DG) == 0.3
248
- G = nx.Graph()
249
- G.add_node(1)
250
- assert nx.density(G) == 0.0
251
-
252
- def test_density_selfloop(self):
253
- G = nx.Graph()
254
- G.add_edge(1, 1)
255
- assert nx.density(G) == 0.0
256
- G.add_edge(1, 2)
257
- assert nx.density(G) == 2.0
258
-
259
- def test_freeze(self):
260
- G = nx.freeze(self.G)
261
- assert G.frozen
262
- pytest.raises(nx.NetworkXError, G.add_node, 1)
263
- pytest.raises(nx.NetworkXError, G.add_nodes_from, [1])
264
- pytest.raises(nx.NetworkXError, G.remove_node, 1)
265
- pytest.raises(nx.NetworkXError, G.remove_nodes_from, [1])
266
- pytest.raises(nx.NetworkXError, G.add_edge, 1, 2)
267
- pytest.raises(nx.NetworkXError, G.add_edges_from, [(1, 2)])
268
- pytest.raises(nx.NetworkXError, G.remove_edge, 1, 2)
269
- pytest.raises(nx.NetworkXError, G.remove_edges_from, [(1, 2)])
270
- pytest.raises(nx.NetworkXError, G.clear_edges)
271
- pytest.raises(nx.NetworkXError, G.clear)
272
-
273
- def test_is_frozen(self):
274
- assert not nx.is_frozen(self.G)
275
- G = nx.freeze(self.G)
276
- assert G.frozen == nx.is_frozen(self.G)
277
- assert G.frozen
278
-
279
- def test_node_attributes_are_still_mutable_on_frozen_graph(self):
280
- G = nx.freeze(nx.path_graph(3))
281
- node = G.nodes[0]
282
- node["node_attribute"] = True
283
- assert node["node_attribute"] is True
284
-
285
- def test_edge_attributes_are_still_mutable_on_frozen_graph(self):
286
- G = nx.freeze(nx.path_graph(3))
287
- edge = G.edges[(0, 1)]
288
- edge["edge_attribute"] = True
289
- assert edge["edge_attribute"] is True
290
-
291
- def test_neighbors_complete_graph(self):
292
- graph = nx.complete_graph(100)
293
- pop = random.sample(list(graph), 1)
294
- nbors = list(nx.neighbors(graph, pop[0]))
295
- # should be all the other vertices in the graph
296
- assert len(nbors) == len(graph) - 1
297
-
298
- graph = nx.path_graph(100)
299
- node = random.sample(list(graph), 1)[0]
300
- nbors = list(nx.neighbors(graph, node))
301
- # should be all the other vertices in the graph
302
- if node != 0 and node != 99:
303
- assert len(nbors) == 2
304
- else:
305
- assert len(nbors) == 1
306
-
307
- # create a star graph with 99 outer nodes
308
- graph = nx.star_graph(99)
309
- nbors = list(nx.neighbors(graph, 0))
310
- assert len(nbors) == 99
311
-
312
- def test_non_neighbors(self):
313
- graph = nx.complete_graph(100)
314
- pop = random.sample(list(graph), 1)
315
- nbors = nx.non_neighbors(graph, pop[0])
316
- # should be all the other vertices in the graph
317
- assert len(nbors) == 0
318
-
319
- graph = nx.path_graph(100)
320
- node = random.sample(list(graph), 1)[0]
321
- nbors = nx.non_neighbors(graph, node)
322
- # should be all the other vertices in the graph
323
- if node != 0 and node != 99:
324
- assert len(nbors) == 97
325
- else:
326
- assert len(nbors) == 98
327
-
328
- # create a star graph with 99 outer nodes
329
- graph = nx.star_graph(99)
330
- nbors = nx.non_neighbors(graph, 0)
331
- assert len(nbors) == 0
332
-
333
- # disconnected graph
334
- graph = nx.Graph()
335
- graph.add_nodes_from(range(10))
336
- nbors = nx.non_neighbors(graph, 0)
337
- assert len(nbors) == 9
338
-
339
- def test_non_edges(self):
340
- # All possible edges exist
341
- graph = nx.complete_graph(5)
342
- nedges = list(nx.non_edges(graph))
343
- assert len(nedges) == 0
344
-
345
- graph = nx.path_graph(4)
346
- expected = [(0, 2), (0, 3), (1, 3)]
347
- nedges = list(nx.non_edges(graph))
348
- for u, v in expected:
349
- assert (u, v) in nedges or (v, u) in nedges
350
-
351
- graph = nx.star_graph(4)
352
- expected = [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
353
- nedges = list(nx.non_edges(graph))
354
- for u, v in expected:
355
- assert (u, v) in nedges or (v, u) in nedges
356
-
357
- # Directed graphs
358
- graph = nx.DiGraph()
359
- graph.add_edges_from([(0, 2), (2, 0), (2, 1)])
360
- expected = [(0, 1), (1, 0), (1, 2)]
361
- nedges = list(nx.non_edges(graph))
362
- for e in expected:
363
- assert e in nedges
364
-
365
- def test_is_weighted(self):
366
- G = nx.Graph()
367
- assert not nx.is_weighted(G)
368
-
369
- G = nx.path_graph(4)
370
- assert not nx.is_weighted(G)
371
- assert not nx.is_weighted(G, (2, 3))
372
-
373
- G.add_node(4)
374
- G.add_edge(3, 4, weight=4)
375
- assert not nx.is_weighted(G)
376
- assert nx.is_weighted(G, (3, 4))
377
-
378
- G = nx.DiGraph()
379
- G.add_weighted_edges_from(
380
- [
381
- ("0", "3", 3),
382
- ("0", "1", -5),
383
- ("1", "0", -5),
384
- ("0", "2", 2),
385
- ("1", "2", 4),
386
- ("2", "3", 1),
387
- ]
388
- )
389
- assert nx.is_weighted(G)
390
- assert nx.is_weighted(G, ("1", "0"))
391
-
392
- G = G.to_undirected()
393
- assert nx.is_weighted(G)
394
- assert nx.is_weighted(G, ("1", "0"))
395
-
396
- pytest.raises(nx.NetworkXError, nx.is_weighted, G, (1, 2))
397
-
398
- def test_is_negatively_weighted(self):
399
- G = nx.Graph()
400
- assert not nx.is_negatively_weighted(G)
401
-
402
- G.add_node(1)
403
- G.add_nodes_from([2, 3, 4, 5])
404
- assert not nx.is_negatively_weighted(G)
405
-
406
- G.add_edge(1, 2, weight=4)
407
- assert not nx.is_negatively_weighted(G, (1, 2))
408
-
409
- G.add_edges_from([(1, 3), (2, 4), (2, 6)])
410
- G[1][3]["color"] = "blue"
411
- assert not nx.is_negatively_weighted(G)
412
- assert not nx.is_negatively_weighted(G, (1, 3))
413
-
414
- G[2][4]["weight"] = -2
415
- assert nx.is_negatively_weighted(G, (2, 4))
416
- assert nx.is_negatively_weighted(G)
417
-
418
- G = nx.DiGraph()
419
- G.add_weighted_edges_from(
420
- [
421
- ("0", "3", 3),
422
- ("0", "1", -5),
423
- ("1", "0", -2),
424
- ("0", "2", 2),
425
- ("1", "2", -3),
426
- ("2", "3", 1),
427
- ]
428
- )
429
- assert nx.is_negatively_weighted(G)
430
- assert not nx.is_negatively_weighted(G, ("0", "3"))
431
- assert nx.is_negatively_weighted(G, ("1", "0"))
432
-
433
- pytest.raises(nx.NetworkXError, nx.is_negatively_weighted, G, (1, 4))
434
-
435
-
436
- class TestCommonNeighbors:
437
- @classmethod
438
- def setup_class(cls):
439
- cls.func = staticmethod(nx.common_neighbors)
440
-
441
- def test_func(G, u, v, expected):
442
- result = sorted(cls.func(G, u, v))
443
- assert result == expected
444
-
445
- cls.test = staticmethod(test_func)
446
-
447
- def test_K5(self):
448
- G = nx.complete_graph(5)
449
- self.test(G, 0, 1, [2, 3, 4])
450
-
451
- def test_P3(self):
452
- G = nx.path_graph(3)
453
- self.test(G, 0, 2, [1])
454
-
455
- def test_S4(self):
456
- G = nx.star_graph(4)
457
- self.test(G, 1, 2, [0])
458
-
459
- def test_digraph(self):
460
- with pytest.raises(nx.NetworkXNotImplemented):
461
- G = nx.DiGraph()
462
- G.add_edges_from([(0, 1), (1, 2)])
463
- self.func(G, 0, 2)
464
-
465
- def test_nonexistent_nodes(self):
466
- G = nx.complete_graph(5)
467
- pytest.raises(nx.NetworkXError, nx.common_neighbors, G, 5, 4)
468
- pytest.raises(nx.NetworkXError, nx.common_neighbors, G, 4, 5)
469
- pytest.raises(nx.NetworkXError, nx.common_neighbors, G, 5, 6)
470
-
471
- def test_custom1(self):
472
- """Case of no common neighbors."""
473
- G = nx.Graph()
474
- G.add_nodes_from([0, 1])
475
- self.test(G, 0, 1, [])
476
-
477
- def test_custom2(self):
478
- """Case of equal nodes."""
479
- G = nx.complete_graph(4)
480
- self.test(G, 0, 0, [1, 2, 3])
481
-
482
-
483
- @pytest.mark.parametrize(
484
- "graph_type", (nx.Graph, nx.DiGraph, nx.MultiGraph, nx.MultiDiGraph)
485
- )
486
- def test_set_node_attributes(graph_type):
487
- # Test single value
488
- G = nx.path_graph(3, create_using=graph_type)
489
- vals = 100
490
- attr = "hello"
491
- nx.set_node_attributes(G, vals, attr)
492
- assert G.nodes[0][attr] == vals
493
- assert G.nodes[1][attr] == vals
494
- assert G.nodes[2][attr] == vals
495
-
496
- # Test dictionary
497
- G = nx.path_graph(3, create_using=graph_type)
498
- vals = dict(zip(sorted(G.nodes()), range(len(G))))
499
- attr = "hi"
500
- nx.set_node_attributes(G, vals, attr)
501
- assert G.nodes[0][attr] == 0
502
- assert G.nodes[1][attr] == 1
503
- assert G.nodes[2][attr] == 2
504
-
505
- # Test dictionary of dictionaries
506
- G = nx.path_graph(3, create_using=graph_type)
507
- d = {"hi": 0, "hello": 200}
508
- vals = dict.fromkeys(G.nodes(), d)
509
- vals.pop(0)
510
- nx.set_node_attributes(G, vals)
511
- assert G.nodes[0] == {}
512
- assert G.nodes[1]["hi"] == 0
513
- assert G.nodes[2]["hello"] == 200
514
-
515
-
516
- @pytest.mark.parametrize(
517
- ("values", "name"),
518
- (
519
- ({0: "red", 1: "blue"}, "color"), # values dictionary
520
- ({0: {"color": "red"}, 1: {"color": "blue"}}, None), # dict-of-dict
521
- ),
522
- )
523
- def test_set_node_attributes_ignores_extra_nodes(values, name):
524
- """
525
- When `values` is a dict or dict-of-dict keyed by nodes, ensure that keys
526
- that correspond to nodes not in G are ignored.
527
- """
528
- G = nx.Graph()
529
- G.add_node(0)
530
- nx.set_node_attributes(G, values, name)
531
- assert G.nodes[0]["color"] == "red"
532
- assert 1 not in G.nodes
533
-
534
-
535
- @pytest.mark.parametrize("graph_type", (nx.Graph, nx.DiGraph))
536
- def test_set_edge_attributes(graph_type):
537
- # Test single value
538
- G = nx.path_graph(3, create_using=graph_type)
539
- attr = "hello"
540
- vals = 3
541
- nx.set_edge_attributes(G, vals, attr)
542
- assert G[0][1][attr] == vals
543
- assert G[1][2][attr] == vals
544
-
545
- # Test multiple values
546
- G = nx.path_graph(3, create_using=graph_type)
547
- attr = "hi"
548
- edges = [(0, 1), (1, 2)]
549
- vals = dict(zip(edges, range(len(edges))))
550
- nx.set_edge_attributes(G, vals, attr)
551
- assert G[0][1][attr] == 0
552
- assert G[1][2][attr] == 1
553
-
554
- # Test dictionary of dictionaries
555
- G = nx.path_graph(3, create_using=graph_type)
556
- d = {"hi": 0, "hello": 200}
557
- edges = [(0, 1)]
558
- vals = dict.fromkeys(edges, d)
559
- nx.set_edge_attributes(G, vals)
560
- assert G[0][1]["hi"] == 0
561
- assert G[0][1]["hello"] == 200
562
- assert G[1][2] == {}
563
-
564
-
565
- @pytest.mark.parametrize(
566
- ("values", "name"),
567
- (
568
- ({(0, 1): 1.0, (0, 2): 2.0}, "weight"), # values dict
569
- ({(0, 1): {"weight": 1.0}, (0, 2): {"weight": 2.0}}, None), # values dod
570
- ),
571
- )
572
- def test_set_edge_attributes_ignores_extra_edges(values, name):
573
- """If `values` is a dict or dict-of-dicts containing edges that are not in
574
- G, data associate with these edges should be ignored.
575
- """
576
- G = nx.Graph([(0, 1)])
577
- nx.set_edge_attributes(G, values, name)
578
- assert G[0][1]["weight"] == 1.0
579
- assert (0, 2) not in G.edges
580
-
581
-
582
- @pytest.mark.parametrize("graph_type", (nx.MultiGraph, nx.MultiDiGraph))
583
- def test_set_edge_attributes_multi(graph_type):
584
- # Test single value
585
- G = nx.path_graph(3, create_using=graph_type)
586
- attr = "hello"
587
- vals = 3
588
- nx.set_edge_attributes(G, vals, attr)
589
- assert G[0][1][0][attr] == vals
590
- assert G[1][2][0][attr] == vals
591
-
592
- # Test multiple values
593
- G = nx.path_graph(3, create_using=graph_type)
594
- attr = "hi"
595
- edges = [(0, 1, 0), (1, 2, 0)]
596
- vals = dict(zip(edges, range(len(edges))))
597
- nx.set_edge_attributes(G, vals, attr)
598
- assert G[0][1][0][attr] == 0
599
- assert G[1][2][0][attr] == 1
600
-
601
- # Test dictionary of dictionaries
602
- G = nx.path_graph(3, create_using=graph_type)
603
- d = {"hi": 0, "hello": 200}
604
- edges = [(0, 1, 0)]
605
- vals = dict.fromkeys(edges, d)
606
- nx.set_edge_attributes(G, vals)
607
- assert G[0][1][0]["hi"] == 0
608
- assert G[0][1][0]["hello"] == 200
609
- assert G[1][2][0] == {}
610
-
611
-
612
- @pytest.mark.parametrize(
613
- ("values", "name"),
614
- (
615
- ({(0, 1, 0): 1.0, (0, 2, 0): 2.0}, "weight"), # values dict
616
- ({(0, 1, 0): {"weight": 1.0}, (0, 2, 0): {"weight": 2.0}}, None), # values dod
617
- ),
618
- )
619
- def test_set_edge_attributes_multi_ignores_extra_edges(values, name):
620
- """If `values` is a dict or dict-of-dicts containing edges that are not in
621
- G, data associate with these edges should be ignored.
622
- """
623
- G = nx.MultiGraph([(0, 1, 0), (0, 1, 1)])
624
- nx.set_edge_attributes(G, values, name)
625
- assert G[0][1][0]["weight"] == 1.0
626
- assert G[0][1][1] == {}
627
- assert (0, 2) not in G.edges()
628
-
629
-
630
- def test_get_node_attributes():
631
- graphs = [nx.Graph(), nx.DiGraph(), nx.MultiGraph(), nx.MultiDiGraph()]
632
- for G in graphs:
633
- G = nx.path_graph(3, create_using=G)
634
- attr = "hello"
635
- vals = 100
636
- nx.set_node_attributes(G, vals, attr)
637
- attrs = nx.get_node_attributes(G, attr)
638
- assert attrs[0] == vals
639
- assert attrs[1] == vals
640
- assert attrs[2] == vals
641
- default_val = 1
642
- G.add_node(4)
643
- attrs = nx.get_node_attributes(G, attr, default=default_val)
644
- assert attrs[4] == default_val
645
-
646
-
647
- def test_get_edge_attributes():
648
- graphs = [nx.Graph(), nx.DiGraph(), nx.MultiGraph(), nx.MultiDiGraph()]
649
- for G in graphs:
650
- G = nx.path_graph(3, create_using=G)
651
- attr = "hello"
652
- vals = 100
653
- nx.set_edge_attributes(G, vals, attr)
654
- attrs = nx.get_edge_attributes(G, attr)
655
- assert len(attrs) == 2
656
-
657
- for edge in G.edges:
658
- assert attrs[edge] == vals
659
-
660
- default_val = vals
661
- G.add_edge(4, 5)
662
- deafult_attrs = nx.get_edge_attributes(G, attr, default=default_val)
663
- assert len(deafult_attrs) == 3
664
-
665
- for edge in G.edges:
666
- assert deafult_attrs[edge] == vals
667
-
668
-
669
- @pytest.mark.parametrize(
670
- "graph_type", (nx.Graph, nx.DiGraph, nx.MultiGraph, nx.MultiDiGraph)
671
- )
672
- def test_remove_node_attributes(graph_type):
673
- # Test removing single attribute
674
- G = nx.path_graph(3, create_using=graph_type)
675
- vals = 100
676
- attr = "hello"
677
- nx.set_node_attributes(G, vals, attr)
678
- nx.remove_node_attributes(G, attr)
679
- assert attr not in G.nodes[0]
680
- assert attr not in G.nodes[1]
681
- assert attr not in G.nodes[2]
682
-
683
- # Test removing single attribute when multiple present
684
- G = nx.path_graph(3, create_using=graph_type)
685
- other_vals = 200
686
- other_attr = "other"
687
- nx.set_node_attributes(G, vals, attr)
688
- nx.set_node_attributes(G, other_vals, other_attr)
689
- nx.remove_node_attributes(G, attr)
690
- assert attr not in G.nodes[0]
691
- assert G.nodes[0][other_attr] == other_vals
692
- assert attr not in G.nodes[1]
693
- assert G.nodes[1][other_attr] == other_vals
694
- assert attr not in G.nodes[2]
695
- assert G.nodes[2][other_attr] == other_vals
696
-
697
- # Test removing multiple attributes
698
- G = nx.path_graph(3, create_using=graph_type)
699
- nx.set_node_attributes(G, vals, attr)
700
- nx.set_node_attributes(G, other_vals, other_attr)
701
- nx.remove_node_attributes(G, attr, other_attr)
702
- assert attr not in G.nodes[0] and other_attr not in G.nodes[0]
703
- assert attr not in G.nodes[1] and other_attr not in G.nodes[1]
704
- assert attr not in G.nodes[2] and other_attr not in G.nodes[2]
705
-
706
- # Test removing multiple (but not all) attributes
707
- G = nx.path_graph(3, create_using=graph_type)
708
- third_vals = 300
709
- third_attr = "three"
710
- nx.set_node_attributes(
711
- G,
712
- {
713
- n: {attr: vals, other_attr: other_vals, third_attr: third_vals}
714
- for n in G.nodes()
715
- },
716
- )
717
- nx.remove_node_attributes(G, other_attr, third_attr)
718
- assert other_attr not in G.nodes[0] and third_attr not in G.nodes[0]
719
- assert other_attr not in G.nodes[1] and third_attr not in G.nodes[1]
720
- assert other_attr not in G.nodes[2] and third_attr not in G.nodes[2]
721
- assert G.nodes[0][attr] == vals
722
- assert G.nodes[1][attr] == vals
723
- assert G.nodes[2][attr] == vals
724
-
725
- # Test incomplete node attributes
726
- G = nx.path_graph(3, create_using=graph_type)
727
- nx.set_node_attributes(
728
- G,
729
- {
730
- 1: {attr: vals, other_attr: other_vals},
731
- 2: {attr: vals, other_attr: other_vals},
732
- },
733
- )
734
- nx.remove_node_attributes(G, attr)
735
- assert attr not in G.nodes[0]
736
- assert attr not in G.nodes[1]
737
- assert attr not in G.nodes[2]
738
- assert G.nodes[1][other_attr] == other_vals
739
- assert G.nodes[2][other_attr] == other_vals
740
-
741
- # Test removing on a subset of nodes
742
- G = nx.path_graph(3, create_using=graph_type)
743
- nx.set_node_attributes(
744
- G,
745
- {
746
- n: {attr: vals, other_attr: other_vals, third_attr: third_vals}
747
- for n in G.nodes()
748
- },
749
- )
750
- nx.remove_node_attributes(G, attr, other_attr, nbunch=[0, 1])
751
- assert attr not in G.nodes[0] and other_attr not in G.nodes[0]
752
- assert attr not in G.nodes[1] and other_attr not in G.nodes[1]
753
- assert attr in G.nodes[2] and other_attr in G.nodes[2]
754
- assert third_attr in G.nodes[0] and G.nodes[0][third_attr] == third_vals
755
- assert third_attr in G.nodes[1] and G.nodes[1][third_attr] == third_vals
756
-
757
-
758
- @pytest.mark.parametrize("graph_type", (nx.Graph, nx.DiGraph))
759
- def test_remove_edge_attributes(graph_type):
760
- # Test removing single attribute
761
- G = nx.path_graph(3, create_using=graph_type)
762
- attr = "hello"
763
- vals = 100
764
- nx.set_edge_attributes(G, vals, attr)
765
- nx.remove_edge_attributes(G, attr)
766
- assert len(nx.get_edge_attributes(G, attr)) == 0
767
-
768
- # Test removing only some attributes
769
- G = nx.path_graph(3, create_using=graph_type)
770
- other_attr = "other"
771
- other_vals = 200
772
- nx.set_edge_attributes(G, vals, attr)
773
- nx.set_edge_attributes(G, other_vals, other_attr)
774
- nx.remove_edge_attributes(G, attr)
775
-
776
- assert attr not in G[0][1]
777
- assert attr not in G[1][2]
778
- assert G[0][1][other_attr] == 200
779
- assert G[1][2][other_attr] == 200
780
-
781
- # Test removing multiple attributes
782
- G = nx.path_graph(3, create_using=graph_type)
783
- nx.set_edge_attributes(G, vals, attr)
784
- nx.set_edge_attributes(G, other_vals, other_attr)
785
- nx.remove_edge_attributes(G, attr, other_attr)
786
- assert attr not in G[0][1] and other_attr not in G[0][1]
787
- assert attr not in G[1][2] and other_attr not in G[1][2]
788
-
789
- # Test removing multiple (not all) attributes
790
- G = nx.path_graph(3, create_using=graph_type)
791
- third_attr = "third"
792
- third_vals = 300
793
- nx.set_edge_attributes(
794
- G,
795
- {
796
- (u, v): {attr: vals, other_attr: other_vals, third_attr: third_vals}
797
- for u, v in G.edges()
798
- },
799
- )
800
- nx.remove_edge_attributes(G, other_attr, third_attr)
801
- assert other_attr not in G[0][1] and third_attr not in G[0][1]
802
- assert other_attr not in G[1][2] and third_attr not in G[1][2]
803
- assert G[0][1][attr] == vals
804
- assert G[1][2][attr] == vals
805
-
806
- # Test removing incomplete edge attributes
807
- G = nx.path_graph(3, create_using=graph_type)
808
- nx.set_edge_attributes(G, {(0, 1): {attr: vals, other_attr: other_vals}})
809
- nx.remove_edge_attributes(G, other_attr)
810
- assert other_attr not in G[0][1] and G[0][1][attr] == vals
811
- assert other_attr not in G[1][2]
812
-
813
- # Test removing subset of edge attributes
814
- G = nx.path_graph(3, create_using=graph_type)
815
- nx.set_edge_attributes(
816
- G,
817
- {
818
- (u, v): {attr: vals, other_attr: other_vals, third_attr: third_vals}
819
- for u, v in G.edges()
820
- },
821
- )
822
- nx.remove_edge_attributes(G, other_attr, third_attr, ebunch=[(0, 1)])
823
- assert other_attr not in G[0][1] and third_attr not in G[0][1]
824
- assert other_attr in G[1][2] and third_attr in G[1][2]
825
-
826
-
827
- @pytest.mark.parametrize("graph_type", (nx.MultiGraph, nx.MultiDiGraph))
828
- def test_remove_multi_edge_attributes(graph_type):
829
- # Test removing single attribute
830
- G = nx.path_graph(3, create_using=graph_type)
831
- G.add_edge(1, 2)
832
- attr = "hello"
833
- vals = 100
834
- nx.set_edge_attributes(G, vals, attr)
835
- nx.remove_edge_attributes(G, attr)
836
- assert attr not in G[0][1][0]
837
- assert attr not in G[1][2][0]
838
- assert attr not in G[1][2][1]
839
-
840
- # Test removing only some attributes
841
- G = nx.path_graph(3, create_using=graph_type)
842
- G.add_edge(1, 2)
843
- other_attr = "other"
844
- other_vals = 200
845
- nx.set_edge_attributes(G, vals, attr)
846
- nx.set_edge_attributes(G, other_vals, other_attr)
847
- nx.remove_edge_attributes(G, attr)
848
- assert attr not in G[0][1][0]
849
- assert attr not in G[1][2][0]
850
- assert attr not in G[1][2][1]
851
- assert G[0][1][0][other_attr] == other_vals
852
- assert G[1][2][0][other_attr] == other_vals
853
- assert G[1][2][1][other_attr] == other_vals
854
-
855
- # Test removing multiple attributes
856
- G = nx.path_graph(3, create_using=graph_type)
857
- G.add_edge(1, 2)
858
- nx.set_edge_attributes(G, vals, attr)
859
- nx.set_edge_attributes(G, other_vals, other_attr)
860
- nx.remove_edge_attributes(G, attr, other_attr)
861
- assert attr not in G[0][1][0] and other_attr not in G[0][1][0]
862
- assert attr not in G[1][2][0] and other_attr not in G[1][2][0]
863
- assert attr not in G[1][2][1] and other_attr not in G[1][2][1]
864
-
865
- # Test removing multiple (not all) attributes
866
- G = nx.path_graph(3, create_using=graph_type)
867
- G.add_edge(1, 2)
868
- third_attr = "third"
869
- third_vals = 300
870
- nx.set_edge_attributes(
871
- G,
872
- {
873
- (u, v, k): {attr: vals, other_attr: other_vals, third_attr: third_vals}
874
- for u, v, k in G.edges(keys=True)
875
- },
876
- )
877
- nx.remove_edge_attributes(G, other_attr, third_attr)
878
- assert other_attr not in G[0][1][0] and third_attr not in G[0][1][0]
879
- assert other_attr not in G[1][2][0] and other_attr not in G[1][2][0]
880
- assert other_attr not in G[1][2][1] and other_attr not in G[1][2][1]
881
- assert G[0][1][0][attr] == vals
882
- assert G[1][2][0][attr] == vals
883
- assert G[1][2][1][attr] == vals
884
-
885
- # Test removing incomplete edge attributes
886
- G = nx.path_graph(3, create_using=graph_type)
887
- G.add_edge(1, 2)
888
- nx.set_edge_attributes(
889
- G,
890
- {
891
- (0, 1, 0): {attr: vals, other_attr: other_vals},
892
- (1, 2, 1): {attr: vals, other_attr: other_vals},
893
- },
894
- )
895
- nx.remove_edge_attributes(G, other_attr)
896
- assert other_attr not in G[0][1][0] and G[0][1][0][attr] == vals
897
- assert other_attr not in G[1][2][0]
898
- assert other_attr not in G[1][2][1]
899
-
900
- # Test removing subset of edge attributes
901
- G = nx.path_graph(3, create_using=graph_type)
902
- G.add_edge(1, 2)
903
- nx.set_edge_attributes(
904
- G,
905
- {
906
- (0, 1, 0): {attr: vals, other_attr: other_vals},
907
- (1, 2, 0): {attr: vals, other_attr: other_vals},
908
- (1, 2, 1): {attr: vals, other_attr: other_vals},
909
- },
910
- )
911
- nx.remove_edge_attributes(G, attr, ebunch=[(0, 1, 0), (1, 2, 0)])
912
- assert attr not in G[0][1][0] and other_attr in G[0][1][0]
913
- assert attr not in G[1][2][0] and other_attr in G[1][2][0]
914
- assert attr in G[1][2][1] and other_attr in G[1][2][1]
915
-
916
-
917
- def test_is_empty():
918
- graphs = [nx.Graph(), nx.DiGraph(), nx.MultiGraph(), nx.MultiDiGraph()]
919
- for G in graphs:
920
- assert nx.is_empty(G)
921
- G.add_nodes_from(range(5))
922
- assert nx.is_empty(G)
923
- G.add_edges_from([(1, 2), (3, 4)])
924
- assert not nx.is_empty(G)
925
-
926
-
927
- @pytest.mark.parametrize(
928
- "graph_type", [nx.Graph, nx.DiGraph, nx.MultiGraph, nx.MultiDiGraph]
929
- )
930
- def test_selfloops(graph_type):
931
- G = nx.complete_graph(3, create_using=graph_type)
932
- G.add_edge(0, 0)
933
- assert nodes_equal(nx.nodes_with_selfloops(G), [0])
934
- assert edges_equal(nx.selfloop_edges(G), [(0, 0)])
935
- assert edges_equal(nx.selfloop_edges(G, data=True), [(0, 0, {})])
936
- assert nx.number_of_selfloops(G) == 1
937
-
938
-
939
- @pytest.mark.parametrize(
940
- "graph_type", [nx.Graph, nx.DiGraph, nx.MultiGraph, nx.MultiDiGraph]
941
- )
942
- def test_selfloop_edges_attr(graph_type):
943
- G = nx.complete_graph(3, create_using=graph_type)
944
- G.add_edge(0, 0)
945
- G.add_edge(1, 1, weight=2)
946
- assert edges_equal(
947
- nx.selfloop_edges(G, data=True), [(0, 0, {}), (1, 1, {"weight": 2})]
948
- )
949
- assert edges_equal(nx.selfloop_edges(G, data="weight"), [(0, 0, None), (1, 1, 2)])
950
-
951
-
952
- def test_selfloop_edges_multi_with_data_and_keys():
953
- G = nx.complete_graph(3, create_using=nx.MultiGraph)
954
- G.add_edge(0, 0, weight=10)
955
- G.add_edge(0, 0, weight=100)
956
- assert edges_equal(
957
- nx.selfloop_edges(G, data="weight", keys=True), [(0, 0, 0, 10), (0, 0, 1, 100)]
958
- )
959
-
960
-
961
- @pytest.mark.parametrize("graph_type", [nx.Graph, nx.DiGraph])
962
- def test_selfloops_removal(graph_type):
963
- G = nx.complete_graph(3, create_using=graph_type)
964
- G.add_edge(0, 0)
965
- G.remove_edges_from(nx.selfloop_edges(G, keys=True))
966
- G.add_edge(0, 0)
967
- G.remove_edges_from(nx.selfloop_edges(G, data=True))
968
- G.add_edge(0, 0)
969
- G.remove_edges_from(nx.selfloop_edges(G, keys=True, data=True))
970
-
971
-
972
- @pytest.mark.parametrize("graph_type", [nx.MultiGraph, nx.MultiDiGraph])
973
- def test_selfloops_removal_multi(graph_type):
974
- """test removing selfloops behavior vis-a-vis altering a dict while iterating.
975
- cf. gh-4068"""
976
- G = nx.complete_graph(3, create_using=graph_type)
977
- # Defaults - see gh-4080
978
- G.add_edge(0, 0)
979
- G.add_edge(0, 0)
980
- G.remove_edges_from(nx.selfloop_edges(G))
981
- assert (0, 0) not in G.edges()
982
- # With keys
983
- G.add_edge(0, 0)
984
- G.add_edge(0, 0)
985
- with pytest.raises(RuntimeError):
986
- G.remove_edges_from(nx.selfloop_edges(G, keys=True))
987
- # With data
988
- G.add_edge(0, 0)
989
- G.add_edge(0, 0)
990
- with pytest.raises(TypeError):
991
- G.remove_edges_from(nx.selfloop_edges(G, data=True))
992
- # With keys and data
993
- G.add_edge(0, 0)
994
- G.add_edge(0, 0)
995
- with pytest.raises(RuntimeError):
996
- G.remove_edges_from(nx.selfloop_edges(G, data=True, keys=True))
997
-
998
-
999
- def test_pathweight():
1000
- valid_path = [1, 2, 3]
1001
- invalid_path = [1, 3, 2]
1002
- graphs = [nx.Graph(), nx.DiGraph(), nx.MultiGraph(), nx.MultiDiGraph()]
1003
- edges = [
1004
- (1, 2, {"cost": 5, "dist": 6}),
1005
- (2, 3, {"cost": 3, "dist": 4}),
1006
- (1, 2, {"cost": 1, "dist": 2}),
1007
- ]
1008
- for graph in graphs:
1009
- graph.add_edges_from(edges)
1010
- assert nx.path_weight(graph, valid_path, "cost") == 4
1011
- assert nx.path_weight(graph, valid_path, "dist") == 6
1012
- pytest.raises(nx.NetworkXNoPath, nx.path_weight, graph, invalid_path, "cost")
1013
-
1014
-
1015
- @pytest.mark.parametrize(
1016
- "G", (nx.Graph(), nx.DiGraph(), nx.MultiGraph(), nx.MultiDiGraph())
1017
- )
1018
- def test_ispath(G):
1019
- G.add_edges_from([(1, 2), (2, 3), (1, 2), (3, 4)])
1020
- valid_path = [1, 2, 3, 4]
1021
- invalid_path = [1, 2, 4, 3] # wrong node order
1022
- another_invalid_path = [1, 2, 3, 4, 5] # contains node not in G
1023
- assert nx.is_path(G, valid_path)
1024
- assert not nx.is_path(G, invalid_path)
1025
- assert not nx.is_path(G, another_invalid_path)
1026
-
1027
-
1028
- @pytest.mark.parametrize("G", (nx.Graph(), nx.DiGraph()))
1029
- def test_restricted_view(G):
1030
- G.add_edges_from([(0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2)])
1031
- G.add_node(4)
1032
- H = nx.restricted_view(G, [0, 2, 5], [(1, 2), (3, 4)])
1033
- assert set(H.nodes()) == {1, 3, 4}
1034
- assert set(H.edges()) == {(1, 1)}
1035
-
1036
-
1037
- @pytest.mark.parametrize("G", (nx.MultiGraph(), nx.MultiDiGraph()))
1038
- def test_restricted_view_multi(G):
1039
- G.add_edges_from(
1040
- [(0, 1, 0), (0, 2, 0), (0, 3, 0), (0, 1, 1), (1, 0, 0), (1, 1, 0), (1, 2, 0)]
1041
- )
1042
- G.add_node(4)
1043
- H = nx.restricted_view(G, [0, 2, 5], [(1, 2, 0), (3, 4, 0)])
1044
- assert set(H.nodes()) == {1, 3, 4}
1045
- assert set(H.edges()) == {(1, 1)}