okstra 0.113.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 (348) hide show
  1. package/README.kr.md +2 -2
  2. package/README.md +2 -2
  3. package/docs/for-ai/README.md +2 -2
  4. package/docs/for-ai/skills/{okstra-brief.md → okstra-brief-gen.md} +3 -3
  5. package/docs/for-ai/skills/okstra-inspect.md +1 -1
  6. package/docs/kr/architecture.md +11 -11
  7. package/docs/kr/cli.md +1 -1
  8. package/docs/kr/follow-ups/2026-07-10-final-report-option-3.md +51 -0
  9. package/docs/project-structure-overview.md +2 -2
  10. package/package.json +1 -1
  11. package/runtime/BUILD.json +2 -2
  12. package/runtime/agents/workers/report-writer-worker.md +1 -0
  13. package/runtime/prompts/lead/context-loader.md +2 -2
  14. package/runtime/prompts/lead/okstra-lead-contract.md +1 -1
  15. package/runtime/prompts/profiles/_common-contract.md +3 -3
  16. package/runtime/prompts/profiles/implementation-planning.md +1 -1
  17. package/runtime/prompts/profiles/requirements-discovery.md +2 -2
  18. package/runtime/python/okstra_ctl/fix_cycles.py +1 -1
  19. package/runtime/python/okstra_ctl/implementation_stage.py +46 -39
  20. package/runtime/python/okstra_ctl/report_views.py +151 -12
  21. package/runtime/python/okstra_ctl/run.py +24 -24
  22. package/runtime/python/okstra_ctl/wizard.py +3 -3
  23. package/runtime/python/okstra_ctl/worktree.py +1 -1
  24. package/runtime/python/okstra_token_usage/claude.py +58 -19
  25. package/runtime/python/okstra_token_usage/collect.py +3 -1
  26. package/runtime/python/okstra_vendor/__init__.py +3 -0
  27. package/runtime/schemas/final-report-v1.0.schema.json +20 -0
  28. package/runtime/skills/{okstra-brief → okstra-brief-gen}/SKILL.md +6 -6
  29. package/runtime/skills/{okstra-brief → okstra-brief-gen}/references/reporter-confirmations.md +1 -1
  30. package/runtime/skills/{okstra-brief → okstra-brief-gen}/references/tracker-recursion.md +1 -1
  31. package/runtime/skills/okstra-inspect/SKILL.md +2 -2
  32. package/runtime/templates/reports/brief.template.md +2 -2
  33. package/runtime/templates/reports/final-report.template.md +14 -0
  34. package/runtime/templates/reports/i18n/en.json +23 -12
  35. package/runtime/templates/reports/i18n/ko.json +23 -12
  36. package/runtime/templates/reports/report.css +55 -0
  37. package/runtime/templates/reports/report.js +53 -1
  38. package/runtime/validators/validate-brief.py +5 -5
  39. package/runtime/validators/validate-brief.sh +1 -1
  40. package/src/commands/lifecycle/uninstall.mjs +2 -1
  41. package/src/lib/skill-catalog.mjs +2 -1
  42. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/__init__.py +0 -0
  43. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py +0 -41
  44. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_clique.py +0 -112
  45. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_connectivity.py +0 -199
  46. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_density.py +0 -146
  47. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_distance_measures.py +0 -59
  48. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_dominating_set.py +0 -78
  49. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_kcomponents.py +0 -303
  50. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_matching.py +0 -8
  51. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_maxcut.py +0 -94
  52. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_ramsey.py +0 -31
  53. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_steinertree.py +0 -306
  54. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_traveling_salesman.py +0 -1014
  55. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_treewidth.py +0 -274
  56. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_vertex_cover.py +0 -68
  57. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/__init__.py +0 -0
  58. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/base_test.py +0 -81
  59. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_connectivity.py +0 -143
  60. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_correlation.py +0 -122
  61. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_mixing.py +0 -174
  62. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_neighbor_degree.py +0 -107
  63. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_pairs.py +0 -87
  64. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/__init__.py +0 -0
  65. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_basic.py +0 -125
  66. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_centrality.py +0 -192
  67. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_cluster.py +0 -84
  68. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_covering.py +0 -33
  69. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_edgelist.py +0 -240
  70. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_extendability.py +0 -334
  71. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_generators.py +0 -407
  72. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_link_analysis.py +0 -218
  73. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matching.py +0 -327
  74. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matrix.py +0 -138
  75. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_project.py +0 -409
  76. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_redundancy.py +0 -35
  77. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py +0 -80
  78. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/__init__.py +0 -0
  79. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality.py +0 -923
  80. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality_subset.py +0 -354
  81. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_closeness_centrality.py +0 -274
  82. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py +0 -259
  83. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py +0 -147
  84. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_closeness.py +0 -43
  85. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_degree_centrality.py +0 -144
  86. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_dispersion.py +0 -73
  87. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py +0 -186
  88. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_group.py +0 -277
  89. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_harmonic_centrality.py +0 -122
  90. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_katz_centrality.py +0 -345
  91. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_laplacian_centrality.py +0 -220
  92. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_load_centrality.py +0 -344
  93. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_percolation_centrality.py +0 -87
  94. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_reaching.py +0 -140
  95. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_second_order_centrality.py +0 -82
  96. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_subgraph.py +0 -110
  97. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_trophic.py +0 -302
  98. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_voterank.py +0 -64
  99. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/__init__.py +0 -0
  100. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/test_coloring.py +0 -863
  101. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/__init__.py +0 -0
  102. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_asyn_fluid.py +0 -147
  103. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_bipartitions.py +0 -157
  104. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_centrality.py +0 -85
  105. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_divisive.py +0 -106
  106. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_kclique.py +0 -91
  107. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_label_propagation.py +0 -241
  108. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_leiden.py +0 -138
  109. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_local.py +0 -76
  110. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_louvain.py +0 -264
  111. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_lukes.py +0 -152
  112. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_modularity_max.py +0 -340
  113. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_quality.py +0 -139
  114. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_utils.py +0 -26
  115. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/__init__.py +0 -0
  116. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_attracting.py +0 -70
  117. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_biconnected.py +0 -248
  118. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_connected.py +0 -138
  119. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_semiconnected.py +0 -55
  120. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_strongly_connected.py +0 -193
  121. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_weakly_connected.py +0 -96
  122. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/__init__.py +0 -0
  123. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_connectivity.py +0 -421
  124. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_cuts.py +0 -309
  125. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_disjoint_paths.py +0 -249
  126. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_augmentation.py +0 -502
  127. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py +0 -488
  128. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcomponents.py +0 -323
  129. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcutsets.py +0 -280
  130. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_stoer_wagner.py +0 -102
  131. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/__init__.py +0 -0
  132. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gl1.gpickle.bz2 +0 -0
  133. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gw1.gpickle.bz2 +0 -0
  134. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/netgen-2.gpickle.bz2 +0 -0
  135. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_gomory_hu.py +0 -128
  136. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow.py +0 -573
  137. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow_large_graph.py +0 -155
  138. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_mincost.py +0 -475
  139. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_networksimplex.py +0 -481
  140. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/wlm3.gpickle.bz2 +0 -0
  141. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/__init__.py +0 -0
  142. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.A99 +0 -0
  143. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.B99 +0 -0
  144. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.A99 +0 -0
  145. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.B99 +0 -0
  146. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_ismags.py +0 -719
  147. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphism.py +0 -103
  148. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py +0 -490
  149. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_match_helpers.py +0 -64
  150. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py +0 -212
  151. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py +0 -202
  152. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp.py +0 -1655
  153. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp_helpers.py +0 -3118
  154. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py +0 -196
  155. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/__init__.py +0 -0
  156. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_hits.py +0 -77
  157. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_pagerank.py +0 -213
  158. package/runtime/python/okstra_vendor/networkx/algorithms/minors/tests/test_contraction.py +0 -544
  159. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/__init__.py +0 -0
  160. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_all.py +0 -328
  161. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_binary.py +0 -451
  162. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_product.py +0 -491
  163. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_unary.py +0 -55
  164. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/__init__.py +0 -0
  165. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_astar.py +0 -254
  166. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense.py +0 -212
  167. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py +0 -88
  168. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_generic.py +0 -511
  169. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_unweighted.py +0 -149
  170. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_weighted.py +0 -983
  171. package/runtime/python/okstra_vendor/networkx/algorithms/tests/__init__.py +0 -0
  172. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_asteroidal.py +0 -23
  173. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_boundary.py +0 -154
  174. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_bridges.py +0 -144
  175. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_broadcasting.py +0 -109
  176. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chains.py +0 -136
  177. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chordal.py +0 -129
  178. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_clique.py +0 -300
  179. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cluster.py +0 -678
  180. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_communicability.py +0 -80
  181. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_core.py +0 -266
  182. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_covering.py +0 -85
  183. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cuts.py +0 -171
  184. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cycles.py +0 -984
  185. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_d_separation.py +0 -340
  186. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dag.py +0 -835
  187. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_measures.py +0 -831
  188. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_regular.py +0 -85
  189. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominance.py +0 -299
  190. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominating.py +0 -115
  191. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_efficiency.py +0 -58
  192. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_euler.py +0 -314
  193. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graph_hashing.py +0 -872
  194. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graphical.py +0 -163
  195. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hierarchy.py +0 -46
  196. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hybrid.py +0 -24
  197. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_isolate.py +0 -26
  198. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_link_prediction.py +0 -615
  199. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_lowest_common_ancestors.py +0 -459
  200. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_matching.py +0 -556
  201. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_max_weight_clique.py +0 -179
  202. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_mis.py +0 -62
  203. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_moral.py +0 -15
  204. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_node_classification.py +0 -140
  205. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_non_randomness.py +0 -60
  206. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_perfect_graph.py +0 -27
  207. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planar_drawing.py +0 -274
  208. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planarity.py +0 -556
  209. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_polynomials.py +0 -57
  210. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_reciprocity.py +0 -37
  211. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_regular.py +0 -88
  212. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_richclub.py +0 -149
  213. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_similarity.py +0 -1158
  214. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_simple_paths.py +0 -803
  215. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smallworld.py +0 -76
  216. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smetric.py +0 -8
  217. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_sparsifiers.py +0 -138
  218. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_structuralholes.py +0 -191
  219. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_summarization.py +0 -642
  220. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_swap.py +0 -179
  221. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_threshold.py +0 -270
  222. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_time_dependent.py +0 -431
  223. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_tournament.py +0 -161
  224. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_triads.py +0 -248
  225. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_vitality.py +0 -41
  226. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_voronoi.py +0 -103
  227. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_walks.py +0 -54
  228. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_wiener.py +0 -157
  229. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/__init__.py +0 -0
  230. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_beamsearch.py +0 -25
  231. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_bfs.py +0 -203
  232. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_dfs.py +0 -307
  233. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgebfs.py +0 -147
  234. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgedfs.py +0 -131
  235. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/__init__.py +0 -0
  236. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_branchings.py +0 -624
  237. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_coding.py +0 -114
  238. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_decomposition.py +0 -79
  239. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_distance_measures.py +0 -99
  240. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_mst.py +0 -934
  241. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_operations.py +0 -53
  242. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_recognition.py +0 -174
  243. package/runtime/python/okstra_vendor/networkx/classes/tests/__init__.py +0 -0
  244. package/runtime/python/okstra_vendor/networkx/classes/tests/dispatch_interface.py +0 -192
  245. package/runtime/python/okstra_vendor/networkx/classes/tests/historical_tests.py +0 -476
  246. package/runtime/python/okstra_vendor/networkx/classes/tests/test_coreviews.py +0 -362
  247. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph.py +0 -331
  248. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph_historical.py +0 -110
  249. package/runtime/python/okstra_vendor/networkx/classes/tests/test_filters.py +0 -177
  250. package/runtime/python/okstra_vendor/networkx/classes/tests/test_function.py +0 -1045
  251. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph.py +0 -950
  252. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph_historical.py +0 -12
  253. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graphviews.py +0 -349
  254. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multidigraph.py +0 -459
  255. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multigraph.py +0 -528
  256. package/runtime/python/okstra_vendor/networkx/classes/tests/test_reportviews.py +0 -1421
  257. package/runtime/python/okstra_vendor/networkx/classes/tests/test_special.py +0 -131
  258. package/runtime/python/okstra_vendor/networkx/classes/tests/test_subgraphviews.py +0 -371
  259. package/runtime/python/okstra_vendor/networkx/conftest.py +0 -261
  260. package/runtime/python/okstra_vendor/networkx/drawing/tests/__init__.py +0 -0
  261. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_complex.png +0 -0
  262. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_empty_graph.png +0 -0
  263. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_house_with_colors.png +0 -0
  264. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_labels_and_colors.png +0 -0
  265. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_shortest_path.png +0 -0
  266. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_house_with_colors.png +0 -0
  267. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_agraph.py +0 -237
  268. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_image_comparison_pylab_mpl.py +0 -229
  269. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_latex.py +0 -285
  270. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_layout.py +0 -631
  271. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pydot.py +0 -146
  272. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pylab.py +0 -1582
  273. package/runtime/python/okstra_vendor/networkx/generators/tests/__init__.py +0 -0
  274. package/runtime/python/okstra_vendor/networkx/generators/tests/test_atlas.py +0 -75
  275. package/runtime/python/okstra_vendor/networkx/generators/tests/test_classic.py +0 -642
  276. package/runtime/python/okstra_vendor/networkx/generators/tests/test_cographs.py +0 -20
  277. package/runtime/python/okstra_vendor/networkx/generators/tests/test_community.py +0 -362
  278. package/runtime/python/okstra_vendor/networkx/generators/tests/test_degree_seq.py +0 -224
  279. package/runtime/python/okstra_vendor/networkx/generators/tests/test_directed.py +0 -189
  280. package/runtime/python/okstra_vendor/networkx/generators/tests/test_duplication.py +0 -103
  281. package/runtime/python/okstra_vendor/networkx/generators/tests/test_ego.py +0 -39
  282. package/runtime/python/okstra_vendor/networkx/generators/tests/test_expanders.py +0 -182
  283. package/runtime/python/okstra_vendor/networkx/generators/tests/test_geometric.py +0 -488
  284. package/runtime/python/okstra_vendor/networkx/generators/tests/test_harary_graph.py +0 -133
  285. package/runtime/python/okstra_vendor/networkx/generators/tests/test_internet_as_graphs.py +0 -221
  286. package/runtime/python/okstra_vendor/networkx/generators/tests/test_intersection.py +0 -28
  287. package/runtime/python/okstra_vendor/networkx/generators/tests/test_interval_graph.py +0 -144
  288. package/runtime/python/okstra_vendor/networkx/generators/tests/test_joint_degree_seq.py +0 -125
  289. package/runtime/python/okstra_vendor/networkx/generators/tests/test_lattice.py +0 -264
  290. package/runtime/python/okstra_vendor/networkx/generators/tests/test_line.py +0 -316
  291. package/runtime/python/okstra_vendor/networkx/generators/tests/test_mycielski.py +0 -30
  292. package/runtime/python/okstra_vendor/networkx/generators/tests/test_nonisomorphic_trees.py +0 -82
  293. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_clustered.py +0 -33
  294. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_graphs.py +0 -495
  295. package/runtime/python/okstra_vendor/networkx/generators/tests/test_small.py +0 -220
  296. package/runtime/python/okstra_vendor/networkx/generators/tests/test_spectral_graph_forge.py +0 -49
  297. package/runtime/python/okstra_vendor/networkx/generators/tests/test_stochastic.py +0 -72
  298. package/runtime/python/okstra_vendor/networkx/generators/tests/test_sudoku.py +0 -92
  299. package/runtime/python/okstra_vendor/networkx/generators/tests/test_time_series.py +0 -64
  300. package/runtime/python/okstra_vendor/networkx/generators/tests/test_trees.py +0 -195
  301. package/runtime/python/okstra_vendor/networkx/generators/tests/test_triads.py +0 -15
  302. package/runtime/python/okstra_vendor/networkx/linalg/tests/__init__.py +0 -0
  303. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_algebraic_connectivity.py +0 -400
  304. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_attrmatrix.py +0 -108
  305. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_bethehessian.py +0 -40
  306. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_graphmatrix.py +0 -275
  307. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_laplacian.py +0 -334
  308. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_modularity.py +0 -86
  309. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_spectrum.py +0 -70
  310. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/__init__.py +0 -0
  311. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_adjacency.py +0 -78
  312. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_cytoscape.py +0 -78
  313. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_node_link.py +0 -109
  314. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_tree.py +0 -48
  315. package/runtime/python/okstra_vendor/networkx/readwrite/tests/__init__.py +0 -0
  316. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_adjlist.py +0 -354
  317. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_edgelist.py +0 -318
  318. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gexf.py +0 -612
  319. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gml.py +0 -744
  320. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graph6.py +0 -181
  321. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graphml.py +0 -1531
  322. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_leda.py +0 -30
  323. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_p2g.py +0 -63
  324. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_pajek.py +0 -128
  325. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_sparse6.py +0 -166
  326. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_text.py +0 -1742
  327. package/runtime/python/okstra_vendor/networkx/tests/__init__.py +0 -0
  328. package/runtime/python/okstra_vendor/networkx/tests/test_all_random_functions.py +0 -248
  329. package/runtime/python/okstra_vendor/networkx/tests/test_convert.py +0 -321
  330. package/runtime/python/okstra_vendor/networkx/tests/test_convert_numpy.py +0 -531
  331. package/runtime/python/okstra_vendor/networkx/tests/test_convert_pandas.py +0 -349
  332. package/runtime/python/okstra_vendor/networkx/tests/test_convert_scipy.py +0 -281
  333. package/runtime/python/okstra_vendor/networkx/tests/test_exceptions.py +0 -40
  334. package/runtime/python/okstra_vendor/networkx/tests/test_import.py +0 -11
  335. package/runtime/python/okstra_vendor/networkx/tests/test_lazy_imports.py +0 -96
  336. package/runtime/python/okstra_vendor/networkx/tests/test_relabel.py +0 -349
  337. package/runtime/python/okstra_vendor/networkx/tests/test_removed_functions_exception_messages.py +0 -8
  338. package/runtime/python/okstra_vendor/networkx/utils/tests/__init__.py +0 -0
  339. package/runtime/python/okstra_vendor/networkx/utils/tests/test__init.py +0 -11
  340. package/runtime/python/okstra_vendor/networkx/utils/tests/test_backends.py +0 -225
  341. package/runtime/python/okstra_vendor/networkx/utils/tests/test_config.py +0 -263
  342. package/runtime/python/okstra_vendor/networkx/utils/tests/test_decorators.py +0 -510
  343. package/runtime/python/okstra_vendor/networkx/utils/tests/test_heaps.py +0 -131
  344. package/runtime/python/okstra_vendor/networkx/utils/tests/test_mapped_queue.py +0 -268
  345. package/runtime/python/okstra_vendor/networkx/utils/tests/test_misc.py +0 -393
  346. package/runtime/python/okstra_vendor/networkx/utils/tests/test_random_sequence.py +0 -53
  347. package/runtime/python/okstra_vendor/networkx/utils/tests/test_rcm.py +0 -63
  348. package/runtime/python/okstra_vendor/networkx/utils/tests/test_unionfind.py +0 -55
@@ -1,1742 +0,0 @@
1
- import random
2
- from itertools import product
3
- from textwrap import dedent
4
-
5
- import pytest
6
-
7
- import networkx as nx
8
-
9
-
10
- def test_generate_network_text_forest_directed():
11
- # Create a directed forest with labels
12
- graph = nx.balanced_tree(r=2, h=2, create_using=nx.DiGraph)
13
- for node in graph.nodes:
14
- graph.nodes[node]["label"] = "node_" + chr(ord("a") + node)
15
-
16
- node_target = dedent(
17
- """
18
- ╙── 0
19
- ├─╼ 1
20
- │ ├─╼ 3
21
- │ └─╼ 4
22
- └─╼ 2
23
- ├─╼ 5
24
- └─╼ 6
25
- """
26
- ).strip()
27
-
28
- label_target = dedent(
29
- """
30
- ╙── node_a
31
- ├─╼ node_b
32
- │ ├─╼ node_d
33
- │ └─╼ node_e
34
- └─╼ node_c
35
- ├─╼ node_f
36
- └─╼ node_g
37
- """
38
- ).strip()
39
-
40
- # Basic node case
41
- ret = nx.generate_network_text(graph, with_labels=False)
42
- assert "\n".join(ret) == node_target
43
-
44
- # Basic label case
45
- ret = nx.generate_network_text(graph, with_labels=True)
46
- assert "\n".join(ret) == label_target
47
-
48
-
49
- def test_write_network_text_empty_graph():
50
- def _graph_str(g, **kw):
51
- printbuf = []
52
- nx.write_network_text(g, printbuf.append, end="", **kw)
53
- return "\n".join(printbuf)
54
-
55
- assert _graph_str(nx.DiGraph()) == "╙"
56
- assert _graph_str(nx.Graph()) == "╙"
57
- assert _graph_str(nx.DiGraph(), ascii_only=True) == "+"
58
- assert _graph_str(nx.Graph(), ascii_only=True) == "+"
59
-
60
-
61
- def test_write_network_text_within_forest_glyph():
62
- g = nx.DiGraph()
63
- g.add_nodes_from([1, 2, 3, 4])
64
- g.add_edge(2, 4)
65
- lines = []
66
- write = lines.append
67
- nx.write_network_text(g, path=write, end="")
68
- nx.write_network_text(g, path=write, ascii_only=True, end="")
69
- text = "\n".join(lines)
70
- target = dedent(
71
- """
72
- ╟── 1
73
- ╟── 2
74
- ╎ └─╼ 4
75
- ╙── 3
76
- +-- 1
77
- +-- 2
78
- : L-> 4
79
- +-- 3
80
- """
81
- ).strip()
82
- assert text == target
83
-
84
-
85
- def test_generate_network_text_directed_multi_tree():
86
- tree1 = nx.balanced_tree(r=2, h=2, create_using=nx.DiGraph)
87
- tree2 = nx.balanced_tree(r=2, h=2, create_using=nx.DiGraph)
88
- forest = nx.disjoint_union_all([tree1, tree2])
89
- ret = "\n".join(nx.generate_network_text(forest))
90
-
91
- target = dedent(
92
- """
93
- ╟── 0
94
- ╎ ├─╼ 1
95
- ╎ │ ├─╼ 3
96
- ╎ │ └─╼ 4
97
- ╎ └─╼ 2
98
- ╎ ├─╼ 5
99
- ╎ └─╼ 6
100
- ╙── 7
101
- ├─╼ 8
102
- │ ├─╼ 10
103
- │ └─╼ 11
104
- └─╼ 9
105
- ├─╼ 12
106
- └─╼ 13
107
- """
108
- ).strip()
109
- assert ret == target
110
-
111
- tree3 = nx.balanced_tree(r=2, h=2, create_using=nx.DiGraph)
112
- forest = nx.disjoint_union_all([tree1, tree2, tree3])
113
- ret = "\n".join(nx.generate_network_text(forest, sources=[0, 14, 7]))
114
-
115
- target = dedent(
116
- """
117
- ╟── 0
118
- ╎ ├─╼ 1
119
- ╎ │ ├─╼ 3
120
- ╎ │ └─╼ 4
121
- ╎ └─╼ 2
122
- ╎ ├─╼ 5
123
- ╎ └─╼ 6
124
- ╟── 14
125
- ╎ ├─╼ 15
126
- ╎ │ ├─╼ 17
127
- ╎ │ └─╼ 18
128
- ╎ └─╼ 16
129
- ╎ ├─╼ 19
130
- ╎ └─╼ 20
131
- ╙── 7
132
- ├─╼ 8
133
- │ ├─╼ 10
134
- │ └─╼ 11
135
- └─╼ 9
136
- ├─╼ 12
137
- └─╼ 13
138
- """
139
- ).strip()
140
- assert ret == target
141
-
142
- ret = "\n".join(
143
- nx.generate_network_text(forest, sources=[0, 14, 7], ascii_only=True)
144
- )
145
-
146
- target = dedent(
147
- """
148
- +-- 0
149
- : |-> 1
150
- : | |-> 3
151
- : | L-> 4
152
- : L-> 2
153
- : |-> 5
154
- : L-> 6
155
- +-- 14
156
- : |-> 15
157
- : | |-> 17
158
- : | L-> 18
159
- : L-> 16
160
- : |-> 19
161
- : L-> 20
162
- +-- 7
163
- |-> 8
164
- | |-> 10
165
- | L-> 11
166
- L-> 9
167
- |-> 12
168
- L-> 13
169
- """
170
- ).strip()
171
- assert ret == target
172
-
173
-
174
- def test_generate_network_text_undirected_multi_tree():
175
- tree1 = nx.balanced_tree(r=2, h=2, create_using=nx.Graph)
176
- tree2 = nx.balanced_tree(r=2, h=2, create_using=nx.Graph)
177
- tree2 = nx.relabel_nodes(tree2, {n: n + len(tree1) for n in tree2.nodes})
178
- forest = nx.union(tree1, tree2)
179
- ret = "\n".join(nx.generate_network_text(forest, sources=[0, 7]))
180
-
181
- target = dedent(
182
- """
183
- ╟── 0
184
- ╎ ├── 1
185
- ╎ │ ├── 3
186
- ╎ │ └── 4
187
- ╎ └── 2
188
- ╎ ├── 5
189
- ╎ └── 6
190
- ╙── 7
191
- ├── 8
192
- │ ├── 10
193
- │ └── 11
194
- └── 9
195
- ├── 12
196
- └── 13
197
- """
198
- ).strip()
199
- assert ret == target
200
-
201
- ret = "\n".join(nx.generate_network_text(forest, sources=[0, 7], ascii_only=True))
202
-
203
- target = dedent(
204
- """
205
- +-- 0
206
- : |-- 1
207
- : | |-- 3
208
- : | L-- 4
209
- : L-- 2
210
- : |-- 5
211
- : L-- 6
212
- +-- 7
213
- |-- 8
214
- | |-- 10
215
- | L-- 11
216
- L-- 9
217
- |-- 12
218
- L-- 13
219
- """
220
- ).strip()
221
- assert ret == target
222
-
223
-
224
- def test_generate_network_text_forest_undirected():
225
- # Create a directed forest
226
- graph = nx.balanced_tree(r=2, h=2, create_using=nx.Graph)
227
-
228
- node_target0 = dedent(
229
- """
230
- ╙── 0
231
- ├── 1
232
- │ ├── 3
233
- │ └── 4
234
- └── 2
235
- ├── 5
236
- └── 6
237
- """
238
- ).strip()
239
-
240
- # defined starting point
241
- ret = "\n".join(nx.generate_network_text(graph, sources=[0]))
242
- assert ret == node_target0
243
-
244
- # defined starting point
245
- node_target2 = dedent(
246
- """
247
- ╙── 2
248
- ├── 0
249
- │ └── 1
250
- │ ├── 3
251
- │ └── 4
252
- ├── 5
253
- └── 6
254
- """
255
- ).strip()
256
- ret = "\n".join(nx.generate_network_text(graph, sources=[2]))
257
- assert ret == node_target2
258
-
259
-
260
- def test_generate_network_text_overspecified_sources():
261
- """
262
- When sources are directly specified, we won't be able to determine when we
263
- are in the last component, so there will always be a trailing, leftmost
264
- pipe.
265
- """
266
- graph = nx.disjoint_union_all(
267
- [
268
- nx.balanced_tree(r=2, h=1, create_using=nx.DiGraph),
269
- nx.balanced_tree(r=1, h=2, create_using=nx.DiGraph),
270
- nx.balanced_tree(r=2, h=1, create_using=nx.DiGraph),
271
- ]
272
- )
273
-
274
- # defined starting point
275
- target1 = dedent(
276
- """
277
- ╟── 0
278
- ╎ ├─╼ 1
279
- ╎ └─╼ 2
280
- ╟── 3
281
- ╎ └─╼ 4
282
- ╎ └─╼ 5
283
- ╟── 6
284
- ╎ ├─╼ 7
285
- ╎ └─╼ 8
286
- """
287
- ).strip()
288
-
289
- target2 = dedent(
290
- """
291
- ╟── 0
292
- ╎ ├─╼ 1
293
- ╎ └─╼ 2
294
- ╟── 3
295
- ╎ └─╼ 4
296
- ╎ └─╼ 5
297
- ╙── 6
298
- ├─╼ 7
299
- └─╼ 8
300
- """
301
- ).strip()
302
-
303
- got1 = "\n".join(nx.generate_network_text(graph, sources=graph.nodes))
304
- got2 = "\n".join(nx.generate_network_text(graph))
305
- assert got1 == target1
306
- assert got2 == target2
307
-
308
-
309
- def test_write_network_text_iterative_add_directed_edges():
310
- """
311
- Walk through the cases going from a disconnected to fully connected graph
312
- """
313
- graph = nx.DiGraph()
314
- graph.add_nodes_from([1, 2, 3, 4])
315
- lines = []
316
- write = lines.append
317
- write("--- initial state ---")
318
- nx.write_network_text(graph, path=write, end="")
319
- for i, j in product(graph.nodes, graph.nodes):
320
- write(f"--- add_edge({i}, {j}) ---")
321
- graph.add_edge(i, j)
322
- nx.write_network_text(graph, path=write, end="")
323
- text = "\n".join(lines)
324
- # defined starting point
325
- target = dedent(
326
- """
327
- --- initial state ---
328
- ╟── 1
329
- ╟── 2
330
- ╟── 3
331
- ╙── 4
332
- --- add_edge(1, 1) ---
333
- ╟── 1 ╾ 1
334
- ╎ └─╼ ...
335
- ╟── 2
336
- ╟── 3
337
- ╙── 4
338
- --- add_edge(1, 2) ---
339
- ╟── 1 ╾ 1
340
- ╎ ├─╼ 2
341
- ╎ └─╼ ...
342
- ╟── 3
343
- ╙── 4
344
- --- add_edge(1, 3) ---
345
- ╟── 1 ╾ 1
346
- ╎ ├─╼ 2
347
- ╎ ├─╼ 3
348
- ╎ └─╼ ...
349
- ╙── 4
350
- --- add_edge(1, 4) ---
351
- ╙── 1 ╾ 1
352
- ├─╼ 2
353
- ├─╼ 3
354
- ├─╼ 4
355
- └─╼ ...
356
- --- add_edge(2, 1) ---
357
- ╙── 2 ╾ 1
358
- └─╼ 1 ╾ 1
359
- ├─╼ 3
360
- ├─╼ 4
361
- └─╼ ...
362
- --- add_edge(2, 2) ---
363
- ╙── 1 ╾ 1, 2
364
- ├─╼ 2 ╾ 2
365
- │ └─╼ ...
366
- ├─╼ 3
367
- ├─╼ 4
368
- └─╼ ...
369
- --- add_edge(2, 3) ---
370
- ╙── 1 ╾ 1, 2
371
- ├─╼ 2 ╾ 2
372
- │ ├─╼ 3 ╾ 1
373
- │ └─╼ ...
374
- ├─╼ 4
375
- └─╼ ...
376
- --- add_edge(2, 4) ---
377
- ╙── 1 ╾ 1, 2
378
- ├─╼ 2 ╾ 2
379
- │ ├─╼ 3 ╾ 1
380
- │ ├─╼ 4 ╾ 1
381
- │ └─╼ ...
382
- └─╼ ...
383
- --- add_edge(3, 1) ---
384
- ╙── 2 ╾ 1, 2
385
- ├─╼ 1 ╾ 1, 3
386
- │ ├─╼ 3 ╾ 2
387
- │ │ └─╼ ...
388
- │ ├─╼ 4 ╾ 2
389
- │ └─╼ ...
390
- └─╼ ...
391
- --- add_edge(3, 2) ---
392
- ╙── 3 ╾ 1, 2
393
- ├─╼ 1 ╾ 1, 2
394
- │ ├─╼ 2 ╾ 2, 3
395
- │ │ ├─╼ 4 ╾ 1
396
- │ │ └─╼ ...
397
- │ └─╼ ...
398
- └─╼ ...
399
- --- add_edge(3, 3) ---
400
- ╙── 1 ╾ 1, 2, 3
401
- ├─╼ 2 ╾ 2, 3
402
- │ ├─╼ 3 ╾ 1, 3
403
- │ │ └─╼ ...
404
- │ ├─╼ 4 ╾ 1
405
- │ └─╼ ...
406
- └─╼ ...
407
- --- add_edge(3, 4) ---
408
- ╙── 1 ╾ 1, 2, 3
409
- ├─╼ 2 ╾ 2, 3
410
- │ ├─╼ 3 ╾ 1, 3
411
- │ │ ├─╼ 4 ╾ 1, 2
412
- │ │ └─╼ ...
413
- │ └─╼ ...
414
- └─╼ ...
415
- --- add_edge(4, 1) ---
416
- ╙── 2 ╾ 1, 2, 3
417
- ├─╼ 1 ╾ 1, 3, 4
418
- │ ├─╼ 3 ╾ 2, 3
419
- │ │ ├─╼ 4 ╾ 1, 2
420
- │ │ │ └─╼ ...
421
- │ │ └─╼ ...
422
- │ └─╼ ...
423
- └─╼ ...
424
- --- add_edge(4, 2) ---
425
- ╙── 3 ╾ 1, 2, 3
426
- ├─╼ 1 ╾ 1, 2, 4
427
- │ ├─╼ 2 ╾ 2, 3, 4
428
- │ │ ├─╼ 4 ╾ 1, 3
429
- │ │ │ └─╼ ...
430
- │ │ └─╼ ...
431
- │ └─╼ ...
432
- └─╼ ...
433
- --- add_edge(4, 3) ---
434
- ╙── 4 ╾ 1, 2, 3
435
- ├─╼ 1 ╾ 1, 2, 3
436
- │ ├─╼ 2 ╾ 2, 3, 4
437
- │ │ ├─╼ 3 ╾ 1, 3, 4
438
- │ │ │ └─╼ ...
439
- │ │ └─╼ ...
440
- │ └─╼ ...
441
- └─╼ ...
442
- --- add_edge(4, 4) ---
443
- ╙── 1 ╾ 1, 2, 3, 4
444
- ├─╼ 2 ╾ 2, 3, 4
445
- │ ├─╼ 3 ╾ 1, 3, 4
446
- │ │ ├─╼ 4 ╾ 1, 2, 4
447
- │ │ │ └─╼ ...
448
- │ │ └─╼ ...
449
- │ └─╼ ...
450
- └─╼ ...
451
- """
452
- ).strip()
453
- assert target == text
454
-
455
-
456
- def test_write_network_text_iterative_add_undirected_edges():
457
- """
458
- Walk through the cases going from a disconnected to fully connected graph
459
- """
460
- graph = nx.Graph()
461
- graph.add_nodes_from([1, 2, 3, 4])
462
- lines = []
463
- write = lines.append
464
- write("--- initial state ---")
465
- nx.write_network_text(graph, path=write, end="")
466
- for i, j in product(graph.nodes, graph.nodes):
467
- if i == j:
468
- continue
469
- write(f"--- add_edge({i}, {j}) ---")
470
- graph.add_edge(i, j)
471
- nx.write_network_text(graph, path=write, end="")
472
- text = "\n".join(lines)
473
- target = dedent(
474
- """
475
- --- initial state ---
476
- ╟── 1
477
- ╟── 2
478
- ╟── 3
479
- ╙── 4
480
- --- add_edge(1, 2) ---
481
- ╟── 3
482
- ╟── 4
483
- ╙── 1
484
- └── 2
485
- --- add_edge(1, 3) ---
486
- ╟── 4
487
- ╙── 2
488
- └── 1
489
- └── 3
490
- --- add_edge(1, 4) ---
491
- ╙── 2
492
- └── 1
493
- ├── 3
494
- └── 4
495
- --- add_edge(2, 1) ---
496
- ╙── 2
497
- └── 1
498
- ├── 3
499
- └── 4
500
- --- add_edge(2, 3) ---
501
- ╙── 4
502
- └── 1
503
- ├── 2
504
- │ └── 3 ─ 1
505
- └── ...
506
- --- add_edge(2, 4) ---
507
- ╙── 3
508
- ├── 1
509
- │ ├── 2 ─ 3
510
- │ │ └── 4 ─ 1
511
- │ └── ...
512
- └── ...
513
- --- add_edge(3, 1) ---
514
- ╙── 3
515
- ├── 1
516
- │ ├── 2 ─ 3
517
- │ │ └── 4 ─ 1
518
- │ └── ...
519
- └── ...
520
- --- add_edge(3, 2) ---
521
- ╙── 3
522
- ├── 1
523
- │ ├── 2 ─ 3
524
- │ │ └── 4 ─ 1
525
- │ └── ...
526
- └── ...
527
- --- add_edge(3, 4) ---
528
- ╙── 1
529
- ├── 2
530
- │ ├── 3 ─ 1
531
- │ │ └── 4 ─ 1, 2
532
- │ └── ...
533
- └── ...
534
- --- add_edge(4, 1) ---
535
- ╙── 1
536
- ├── 2
537
- │ ├── 3 ─ 1
538
- │ │ └── 4 ─ 1, 2
539
- │ └── ...
540
- └── ...
541
- --- add_edge(4, 2) ---
542
- ╙── 1
543
- ├── 2
544
- │ ├── 3 ─ 1
545
- │ │ └── 4 ─ 1, 2
546
- │ └── ...
547
- └── ...
548
- --- add_edge(4, 3) ---
549
- ╙── 1
550
- ├── 2
551
- │ ├── 3 ─ 1
552
- │ │ └── 4 ─ 1, 2
553
- │ └── ...
554
- └── ...
555
- """
556
- ).strip()
557
- assert target == text
558
-
559
-
560
- def test_write_network_text_iterative_add_random_directed_edges():
561
- """
562
- Walk through the cases going from a disconnected to fully connected graph
563
- """
564
-
565
- rng = random.Random(724466096)
566
- graph = nx.DiGraph()
567
- graph.add_nodes_from([1, 2, 3, 4, 5])
568
- possible_edges = list(product(graph.nodes, graph.nodes))
569
- rng.shuffle(possible_edges)
570
- graph.add_edges_from(possible_edges[0:8])
571
- lines = []
572
- write = lines.append
573
- write("--- initial state ---")
574
- nx.write_network_text(graph, path=write, end="")
575
- for i, j in possible_edges[8:12]:
576
- write(f"--- add_edge({i}, {j}) ---")
577
- graph.add_edge(i, j)
578
- nx.write_network_text(graph, path=write, end="")
579
- text = "\n".join(lines)
580
- target = dedent(
581
- """
582
- --- initial state ---
583
- ╙── 3 ╾ 5
584
- └─╼ 2 ╾ 2
585
- ├─╼ 4 ╾ 4
586
- │ ├─╼ 5
587
- │ │ ├─╼ 1 ╾ 1
588
- │ │ │ └─╼ ...
589
- │ │ └─╼ ...
590
- │ └─╼ ...
591
- └─╼ ...
592
- --- add_edge(4, 1) ---
593
- ╙── 3 ╾ 5
594
- └─╼ 2 ╾ 2
595
- ├─╼ 4 ╾ 4
596
- │ ├─╼ 5
597
- │ │ ├─╼ 1 ╾ 1, 4
598
- │ │ │ └─╼ ...
599
- │ │ └─╼ ...
600
- │ └─╼ ...
601
- └─╼ ...
602
- --- add_edge(2, 1) ---
603
- ╙── 3 ╾ 5
604
- └─╼ 2 ╾ 2
605
- ├─╼ 4 ╾ 4
606
- │ ├─╼ 5
607
- │ │ ├─╼ 1 ╾ 1, 4, 2
608
- │ │ │ └─╼ ...
609
- │ │ └─╼ ...
610
- │ └─╼ ...
611
- └─╼ ...
612
- --- add_edge(5, 2) ---
613
- ╙── 3 ╾ 5
614
- └─╼ 2 ╾ 2, 5
615
- ├─╼ 4 ╾ 4
616
- │ ├─╼ 5
617
- │ │ ├─╼ 1 ╾ 1, 4, 2
618
- │ │ │ └─╼ ...
619
- │ │ └─╼ ...
620
- │ └─╼ ...
621
- └─╼ ...
622
- --- add_edge(1, 5) ---
623
- ╙── 3 ╾ 5
624
- └─╼ 2 ╾ 2, 5
625
- ├─╼ 4 ╾ 4
626
- │ ├─╼ 5 ╾ 1
627
- │ │ ├─╼ 1 ╾ 1, 4, 2
628
- │ │ │ └─╼ ...
629
- │ │ └─╼ ...
630
- │ └─╼ ...
631
- └─╼ ...
632
-
633
- """
634
- ).strip()
635
- assert target == text
636
-
637
-
638
- def test_write_network_text_nearly_forest():
639
- g = nx.DiGraph()
640
- g.add_edge(1, 2)
641
- g.add_edge(1, 5)
642
- g.add_edge(2, 3)
643
- g.add_edge(3, 4)
644
- g.add_edge(5, 6)
645
- g.add_edge(6, 7)
646
- g.add_edge(6, 8)
647
- orig = g.copy()
648
- g.add_edge(1, 8) # forward edge
649
- g.add_edge(4, 2) # back edge
650
- g.add_edge(6, 3) # cross edge
651
- lines = []
652
- write = lines.append
653
- write("--- directed case ---")
654
- nx.write_network_text(orig, path=write, end="")
655
- write("--- add (1, 8), (4, 2), (6, 3) ---")
656
- nx.write_network_text(g, path=write, end="")
657
- write("--- undirected case ---")
658
- nx.write_network_text(orig.to_undirected(), path=write, sources=[1], end="")
659
- write("--- add (1, 8), (4, 2), (6, 3) ---")
660
- nx.write_network_text(g.to_undirected(), path=write, sources=[1], end="")
661
- text = "\n".join(lines)
662
- target = dedent(
663
- """
664
- --- directed case ---
665
- ╙── 1
666
- ├─╼ 2
667
- │ └─╼ 3
668
- │ └─╼ 4
669
- └─╼ 5
670
- └─╼ 6
671
- ├─╼ 7
672
- └─╼ 8
673
- --- add (1, 8), (4, 2), (6, 3) ---
674
- ╙── 1
675
- ├─╼ 2 ╾ 4
676
- │ └─╼ 3 ╾ 6
677
- │ └─╼ 4
678
- │ └─╼ ...
679
- ├─╼ 5
680
- │ └─╼ 6
681
- │ ├─╼ 7
682
- │ ├─╼ 8 ╾ 1
683
- │ └─╼ ...
684
- └─╼ ...
685
- --- undirected case ---
686
- ╙── 1
687
- ├── 2
688
- │ └── 3
689
- │ └── 4
690
- └── 5
691
- └── 6
692
- ├── 7
693
- └── 8
694
- --- add (1, 8), (4, 2), (6, 3) ---
695
- ╙── 1
696
- ├── 2
697
- │ ├── 3
698
- │ │ ├── 4 ─ 2
699
- │ │ └── 6
700
- │ │ ├── 5 ─ 1
701
- │ │ ├── 7
702
- │ │ └── 8 ─ 1
703
- │ └── ...
704
- └── ...
705
- """
706
- ).strip()
707
- assert target == text
708
-
709
-
710
- def test_write_network_text_complete_graph_ascii_only():
711
- graph = nx.generators.complete_graph(5, create_using=nx.DiGraph)
712
- lines = []
713
- write = lines.append
714
- write("--- directed case ---")
715
- nx.write_network_text(graph, path=write, ascii_only=True, end="")
716
- write("--- undirected case ---")
717
- nx.write_network_text(graph.to_undirected(), path=write, ascii_only=True, end="")
718
- text = "\n".join(lines)
719
- target = dedent(
720
- """
721
- --- directed case ---
722
- +-- 0 <- 1, 2, 3, 4
723
- |-> 1 <- 2, 3, 4
724
- | |-> 2 <- 0, 3, 4
725
- | | |-> 3 <- 0, 1, 4
726
- | | | |-> 4 <- 0, 1, 2
727
- | | | | L-> ...
728
- | | | L-> ...
729
- | | L-> ...
730
- | L-> ...
731
- L-> ...
732
- --- undirected case ---
733
- +-- 0
734
- |-- 1
735
- | |-- 2 - 0
736
- | | |-- 3 - 0, 1
737
- | | | L-- 4 - 0, 1, 2
738
- | | L-- ...
739
- | L-- ...
740
- L-- ...
741
- """
742
- ).strip()
743
- assert target == text
744
-
745
-
746
- def test_write_network_text_with_labels():
747
- graph = nx.generators.complete_graph(5, create_using=nx.DiGraph)
748
- for n in graph.nodes:
749
- graph.nodes[n]["label"] = f"Node(n={n})"
750
- lines = []
751
- write = lines.append
752
- nx.write_network_text(graph, path=write, with_labels=True, ascii_only=False, end="")
753
- text = "\n".join(lines)
754
- # Non trees with labels can get somewhat out of hand with network text
755
- # because we need to immediately show every non-tree edge to the right
756
- target = dedent(
757
- """
758
- ╙── Node(n=0) ╾ Node(n=1), Node(n=2), Node(n=3), Node(n=4)
759
- ├─╼ Node(n=1) ╾ Node(n=2), Node(n=3), Node(n=4)
760
- │ ├─╼ Node(n=2) ╾ Node(n=0), Node(n=3), Node(n=4)
761
- │ │ ├─╼ Node(n=3) ╾ Node(n=0), Node(n=1), Node(n=4)
762
- │ │ │ ├─╼ Node(n=4) ╾ Node(n=0), Node(n=1), Node(n=2)
763
- │ │ │ │ └─╼ ...
764
- │ │ │ └─╼ ...
765
- │ │ └─╼ ...
766
- │ └─╼ ...
767
- └─╼ ...
768
- """
769
- ).strip()
770
- assert target == text
771
-
772
-
773
- def test_write_network_text_complete_graphs():
774
- lines = []
775
- write = lines.append
776
- for k in [0, 1, 2, 3, 4, 5]:
777
- g = nx.generators.complete_graph(k)
778
- write(f"--- undirected k={k} ---")
779
- nx.write_network_text(g, path=write, end="")
780
-
781
- for k in [0, 1, 2, 3, 4, 5]:
782
- g = nx.generators.complete_graph(k, nx.DiGraph)
783
- write(f"--- directed k={k} ---")
784
- nx.write_network_text(g, path=write, end="")
785
- text = "\n".join(lines)
786
- target = dedent(
787
- """
788
- --- undirected k=0 ---
789
-
790
- --- undirected k=1 ---
791
- ╙── 0
792
- --- undirected k=2 ---
793
- ╙── 0
794
- └── 1
795
- --- undirected k=3 ---
796
- ╙── 0
797
- ├── 1
798
- │ └── 2 ─ 0
799
- └── ...
800
- --- undirected k=4 ---
801
- ╙── 0
802
- ├── 1
803
- │ ├── 2 ─ 0
804
- │ │ └── 3 ─ 0, 1
805
- │ └── ...
806
- └── ...
807
- --- undirected k=5 ---
808
- ╙── 0
809
- ├── 1
810
- │ ├── 2 ─ 0
811
- │ │ ├── 3 ─ 0, 1
812
- │ │ │ └── 4 ─ 0, 1, 2
813
- │ │ └── ...
814
- │ └── ...
815
- └── ...
816
- --- directed k=0 ---
817
-
818
- --- directed k=1 ---
819
- ╙── 0
820
- --- directed k=2 ---
821
- ╙── 0 ╾ 1
822
- └─╼ 1
823
- └─╼ ...
824
- --- directed k=3 ---
825
- ╙── 0 ╾ 1, 2
826
- ├─╼ 1 ╾ 2
827
- │ ├─╼ 2 ╾ 0
828
- │ │ └─╼ ...
829
- │ └─╼ ...
830
- └─╼ ...
831
- --- directed k=4 ---
832
- ╙── 0 ╾ 1, 2, 3
833
- ├─╼ 1 ╾ 2, 3
834
- │ ├─╼ 2 ╾ 0, 3
835
- │ │ ├─╼ 3 ╾ 0, 1
836
- │ │ │ └─╼ ...
837
- │ │ └─╼ ...
838
- │ └─╼ ...
839
- └─╼ ...
840
- --- directed k=5 ---
841
- ╙── 0 ╾ 1, 2, 3, 4
842
- ├─╼ 1 ╾ 2, 3, 4
843
- │ ├─╼ 2 ╾ 0, 3, 4
844
- │ │ ├─╼ 3 ╾ 0, 1, 4
845
- │ │ │ ├─╼ 4 ╾ 0, 1, 2
846
- │ │ │ │ └─╼ ...
847
- │ │ │ └─╼ ...
848
- │ │ └─╼ ...
849
- │ └─╼ ...
850
- └─╼ ...
851
- """
852
- ).strip()
853
- assert target == text
854
-
855
-
856
- def test_write_network_text_multiple_sources():
857
- g = nx.DiGraph()
858
- g.add_edge(1, 2)
859
- g.add_edge(1, 3)
860
- g.add_edge(2, 4)
861
- g.add_edge(3, 5)
862
- g.add_edge(3, 6)
863
- g.add_edge(5, 4)
864
- g.add_edge(4, 1)
865
- g.add_edge(1, 5)
866
- lines = []
867
- write = lines.append
868
- # Use each node as the starting point to demonstrate how the representation
869
- # changes.
870
- nodes = sorted(g.nodes())
871
- for n in nodes:
872
- write(f"--- source node: {n} ---")
873
- nx.write_network_text(g, path=write, sources=[n], end="")
874
- text = "\n".join(lines)
875
- target = dedent(
876
- """
877
- --- source node: 1 ---
878
- ╙── 1 ╾ 4
879
- ├─╼ 2
880
- │ └─╼ 4 ╾ 5
881
- │ └─╼ ...
882
- ├─╼ 3
883
- │ ├─╼ 5 ╾ 1
884
- │ │ └─╼ ...
885
- │ └─╼ 6
886
- └─╼ ...
887
- --- source node: 2 ---
888
- ╙── 2 ╾ 1
889
- └─╼ 4 ╾ 5
890
- └─╼ 1
891
- ├─╼ 3
892
- │ ├─╼ 5 ╾ 1
893
- │ │ └─╼ ...
894
- │ └─╼ 6
895
- └─╼ ...
896
- --- source node: 3 ---
897
- ╙── 3 ╾ 1
898
- ├─╼ 5 ╾ 1
899
- │ └─╼ 4 ╾ 2
900
- │ └─╼ 1
901
- │ ├─╼ 2
902
- │ │ └─╼ ...
903
- │ └─╼ ...
904
- └─╼ 6
905
- --- source node: 4 ---
906
- ╙── 4 ╾ 2, 5
907
- └─╼ 1
908
- ├─╼ 2
909
- │ └─╼ ...
910
- ├─╼ 3
911
- │ ├─╼ 5 ╾ 1
912
- │ │ └─╼ ...
913
- │ └─╼ 6
914
- └─╼ ...
915
- --- source node: 5 ---
916
- ╙── 5 ╾ 3, 1
917
- └─╼ 4 ╾ 2
918
- └─╼ 1
919
- ├─╼ 2
920
- │ └─╼ ...
921
- ├─╼ 3
922
- │ ├─╼ 6
923
- │ └─╼ ...
924
- └─╼ ...
925
- --- source node: 6 ---
926
- ╙── 6 ╾ 3
927
- """
928
- ).strip()
929
- assert target == text
930
-
931
-
932
- def test_write_network_text_star_graph():
933
- graph = nx.star_graph(5, create_using=nx.Graph)
934
- lines = []
935
- write = lines.append
936
- nx.write_network_text(graph, path=write, end="")
937
- text = "\n".join(lines)
938
- target = dedent(
939
- """
940
- ╙── 1
941
- └── 0
942
- ├── 2
943
- ├── 3
944
- ├── 4
945
- └── 5
946
- """
947
- ).strip()
948
- assert target == text
949
-
950
-
951
- def test_write_network_text_path_graph():
952
- graph = nx.path_graph(3, create_using=nx.Graph)
953
- lines = []
954
- write = lines.append
955
- nx.write_network_text(graph, path=write, end="")
956
- text = "\n".join(lines)
957
- target = dedent(
958
- """
959
- ╙── 0
960
- └── 1
961
- └── 2
962
- """
963
- ).strip()
964
- assert target == text
965
-
966
-
967
- def test_write_network_text_lollipop_graph():
968
- graph = nx.lollipop_graph(4, 2, create_using=nx.Graph)
969
- lines = []
970
- write = lines.append
971
- nx.write_network_text(graph, path=write, end="")
972
- text = "\n".join(lines)
973
- target = dedent(
974
- """
975
- ╙── 5
976
- └── 4
977
- └── 3
978
- ├── 0
979
- │ ├── 1 ─ 3
980
- │ │ └── 2 ─ 0, 3
981
- │ └── ...
982
- └── ...
983
- """
984
- ).strip()
985
- assert target == text
986
-
987
-
988
- def test_write_network_text_wheel_graph():
989
- graph = nx.wheel_graph(7, create_using=nx.Graph)
990
- lines = []
991
- write = lines.append
992
- nx.write_network_text(graph, path=write, end="")
993
- text = "\n".join(lines)
994
- target = dedent(
995
- """
996
- ╙── 1
997
- ├── 0
998
- │ ├── 2 ─ 1
999
- │ │ └── 3 ─ 0
1000
- │ │ └── 4 ─ 0
1001
- │ │ └── 5 ─ 0
1002
- │ │ └── 6 ─ 0, 1
1003
- │ └── ...
1004
- └── ...
1005
- """
1006
- ).strip()
1007
- assert target == text
1008
-
1009
-
1010
- def test_write_network_text_circular_ladder_graph():
1011
- graph = nx.circular_ladder_graph(4, create_using=nx.Graph)
1012
- lines = []
1013
- write = lines.append
1014
- nx.write_network_text(graph, path=write, end="")
1015
- text = "\n".join(lines)
1016
- target = dedent(
1017
- """
1018
- ╙── 0
1019
- ├── 1
1020
- │ ├── 2
1021
- │ │ ├── 3 ─ 0
1022
- │ │ │ └── 7
1023
- │ │ │ ├── 6 ─ 2
1024
- │ │ │ │ └── 5 ─ 1
1025
- │ │ │ │ └── 4 ─ 0, 7
1026
- │ │ │ └── ...
1027
- │ │ └── ...
1028
- │ └── ...
1029
- └── ...
1030
- """
1031
- ).strip()
1032
- assert target == text
1033
-
1034
-
1035
- def test_write_network_text_dorogovtsev_goltsev_mendes_graph():
1036
- graph = nx.dorogovtsev_goltsev_mendes_graph(4, create_using=nx.Graph)
1037
- lines = []
1038
- write = lines.append
1039
- nx.write_network_text(graph, path=write, end="")
1040
- text = "\n".join(lines)
1041
- target = dedent(
1042
- """
1043
- ╙── 15
1044
- ├── 0
1045
- │ ├── 1 ─ 15
1046
- │ │ ├── 2 ─ 0
1047
- │ │ │ ├── 4 ─ 0
1048
- │ │ │ │ ├── 9 ─ 0
1049
- │ │ │ │ │ ├── 22 ─ 0
1050
- │ │ │ │ │ └── 38 ─ 4
1051
- │ │ │ │ ├── 13 ─ 2
1052
- │ │ │ │ │ ├── 34 ─ 2
1053
- │ │ │ │ │ └── 39 ─ 4
1054
- │ │ │ │ ├── 18 ─ 0
1055
- │ │ │ │ ├── 30 ─ 2
1056
- │ │ │ │ └── ...
1057
- │ │ │ ├── 5 ─ 1
1058
- │ │ │ │ ├── 12 ─ 1
1059
- │ │ │ │ │ ├── 29 ─ 1
1060
- │ │ │ │ │ └── 40 ─ 5
1061
- │ │ │ │ ├── 14 ─ 2
1062
- │ │ │ │ │ ├── 35 ─ 2
1063
- │ │ │ │ │ └── 41 ─ 5
1064
- │ │ │ │ ├── 25 ─ 1
1065
- │ │ │ │ ├── 31 ─ 2
1066
- │ │ │ │ └── ...
1067
- │ │ │ ├── 7 ─ 0
1068
- │ │ │ │ ├── 20 ─ 0
1069
- │ │ │ │ └── 32 ─ 2
1070
- │ │ │ ├── 10 ─ 1
1071
- │ │ │ │ ├── 27 ─ 1
1072
- │ │ │ │ └── 33 ─ 2
1073
- │ │ │ ├── 16 ─ 0
1074
- │ │ │ ├── 23 ─ 1
1075
- │ │ │ └── ...
1076
- │ │ ├── 3 ─ 0
1077
- │ │ │ ├── 8 ─ 0
1078
- │ │ │ │ ├── 21 ─ 0
1079
- │ │ │ │ └── 36 ─ 3
1080
- │ │ │ ├── 11 ─ 1
1081
- │ │ │ │ ├── 28 ─ 1
1082
- │ │ │ │ └── 37 ─ 3
1083
- │ │ │ ├── 17 ─ 0
1084
- │ │ │ ├── 24 ─ 1
1085
- │ │ │ └── ...
1086
- │ │ ├── 6 ─ 0
1087
- │ │ │ ├── 19 ─ 0
1088
- │ │ │ └── 26 ─ 1
1089
- │ │ └── ...
1090
- │ └── ...
1091
- └── ...
1092
- """
1093
- ).strip()
1094
- assert target == text
1095
-
1096
-
1097
- def test_write_network_text_tree_max_depth():
1098
- orig = nx.balanced_tree(r=1, h=3, create_using=nx.DiGraph)
1099
- lines = []
1100
- write = lines.append
1101
- write("--- directed case, max_depth=0 ---")
1102
- nx.write_network_text(orig, path=write, end="", max_depth=0)
1103
- write("--- directed case, max_depth=1 ---")
1104
- nx.write_network_text(orig, path=write, end="", max_depth=1)
1105
- write("--- directed case, max_depth=2 ---")
1106
- nx.write_network_text(orig, path=write, end="", max_depth=2)
1107
- write("--- directed case, max_depth=3 ---")
1108
- nx.write_network_text(orig, path=write, end="", max_depth=3)
1109
- write("--- directed case, max_depth=4 ---")
1110
- nx.write_network_text(orig, path=write, end="", max_depth=4)
1111
- write("--- undirected case, max_depth=0 ---")
1112
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=0)
1113
- write("--- undirected case, max_depth=1 ---")
1114
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=1)
1115
- write("--- undirected case, max_depth=2 ---")
1116
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=2)
1117
- write("--- undirected case, max_depth=3 ---")
1118
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=3)
1119
- write("--- undirected case, max_depth=4 ---")
1120
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=4)
1121
- text = "\n".join(lines)
1122
- target = dedent(
1123
- """
1124
- --- directed case, max_depth=0 ---
1125
- ╙ ...
1126
- --- directed case, max_depth=1 ---
1127
- ╙── 0
1128
- └─╼ ...
1129
- --- directed case, max_depth=2 ---
1130
- ╙── 0
1131
- └─╼ 1
1132
- └─╼ ...
1133
- --- directed case, max_depth=3 ---
1134
- ╙── 0
1135
- └─╼ 1
1136
- └─╼ 2
1137
- └─╼ ...
1138
- --- directed case, max_depth=4 ---
1139
- ╙── 0
1140
- └─╼ 1
1141
- └─╼ 2
1142
- └─╼ 3
1143
- --- undirected case, max_depth=0 ---
1144
- ╙ ...
1145
- --- undirected case, max_depth=1 ---
1146
- ╙── 0 ─ 1
1147
- └── ...
1148
- --- undirected case, max_depth=2 ---
1149
- ╙── 0
1150
- └── 1 ─ 2
1151
- └── ...
1152
- --- undirected case, max_depth=3 ---
1153
- ╙── 0
1154
- └── 1
1155
- └── 2 ─ 3
1156
- └── ...
1157
- --- undirected case, max_depth=4 ---
1158
- ╙── 0
1159
- └── 1
1160
- └── 2
1161
- └── 3
1162
- """
1163
- ).strip()
1164
- assert target == text
1165
-
1166
-
1167
- def test_write_network_text_graph_max_depth():
1168
- orig = nx.erdos_renyi_graph(10, 0.15, directed=True, seed=40392)
1169
- lines = []
1170
- write = lines.append
1171
- write("--- directed case, max_depth=None ---")
1172
- nx.write_network_text(orig, path=write, end="", max_depth=None)
1173
- write("--- directed case, max_depth=0 ---")
1174
- nx.write_network_text(orig, path=write, end="", max_depth=0)
1175
- write("--- directed case, max_depth=1 ---")
1176
- nx.write_network_text(orig, path=write, end="", max_depth=1)
1177
- write("--- directed case, max_depth=2 ---")
1178
- nx.write_network_text(orig, path=write, end="", max_depth=2)
1179
- write("--- directed case, max_depth=3 ---")
1180
- nx.write_network_text(orig, path=write, end="", max_depth=3)
1181
- write("--- undirected case, max_depth=None ---")
1182
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=None)
1183
- write("--- undirected case, max_depth=0 ---")
1184
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=0)
1185
- write("--- undirected case, max_depth=1 ---")
1186
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=1)
1187
- write("--- undirected case, max_depth=2 ---")
1188
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=2)
1189
- write("--- undirected case, max_depth=3 ---")
1190
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=3)
1191
- text = "\n".join(lines)
1192
- target = dedent(
1193
- """
1194
- --- directed case, max_depth=None ---
1195
- ╟── 4
1196
- ╎ ├─╼ 0 ╾ 3
1197
- ╎ ├─╼ 5 ╾ 7
1198
- ╎ │ └─╼ 3
1199
- ╎ │ ├─╼ 1 ╾ 9
1200
- ╎ │ │ └─╼ 9 ╾ 6
1201
- ╎ │ │ ├─╼ 6
1202
- ╎ │ │ │ └─╼ ...
1203
- ╎ │ │ ├─╼ 7 ╾ 4
1204
- ╎ │ │ │ ├─╼ 2
1205
- ╎ │ │ │ └─╼ ...
1206
- ╎ │ │ └─╼ ...
1207
- ╎ │ └─╼ ...
1208
- ╎ └─╼ ...
1209
- ╙── 8
1210
- --- directed case, max_depth=0 ---
1211
- ╙ ...
1212
- --- directed case, max_depth=1 ---
1213
- ╟── 4
1214
- ╎ └─╼ ...
1215
- ╙── 8
1216
- --- directed case, max_depth=2 ---
1217
- ╟── 4
1218
- ╎ ├─╼ 0 ╾ 3
1219
- ╎ ├─╼ 5 ╾ 7
1220
- ╎ │ └─╼ ...
1221
- ╎ └─╼ 7 ╾ 9
1222
- ╎ └─╼ ...
1223
- ╙── 8
1224
- --- directed case, max_depth=3 ---
1225
- ╟── 4
1226
- ╎ ├─╼ 0 ╾ 3
1227
- ╎ ├─╼ 5 ╾ 7
1228
- ╎ │ └─╼ 3
1229
- ╎ │ └─╼ ...
1230
- ╎ └─╼ 7 ╾ 9
1231
- ╎ ├─╼ 2
1232
- ╎ └─╼ ...
1233
- ╙── 8
1234
- --- undirected case, max_depth=None ---
1235
- ╟── 8
1236
- ╙── 2
1237
- └── 7
1238
- ├── 4
1239
- │ ├── 0
1240
- │ │ └── 3
1241
- │ │ ├── 1
1242
- │ │ │ └── 9 ─ 7
1243
- │ │ │ └── 6
1244
- │ │ └── 5 ─ 4, 7
1245
- │ └── ...
1246
- └── ...
1247
- --- undirected case, max_depth=0 ---
1248
- ╙ ...
1249
- --- undirected case, max_depth=1 ---
1250
- ╟── 8
1251
- ╙── 2 ─ 7
1252
- └── ...
1253
- --- undirected case, max_depth=2 ---
1254
- ╟── 8
1255
- ╙── 2
1256
- └── 7 ─ 4, 5, 9
1257
- └── ...
1258
- --- undirected case, max_depth=3 ---
1259
- ╟── 8
1260
- ╙── 2
1261
- └── 7
1262
- ├── 4 ─ 0, 5
1263
- │ └── ...
1264
- ├── 5 ─ 4, 3
1265
- │ └── ...
1266
- └── 9 ─ 1, 6
1267
- └── ...
1268
- """
1269
- ).strip()
1270
- assert target == text
1271
-
1272
-
1273
- def test_write_network_text_clique_max_depth():
1274
- orig = nx.complete_graph(5, nx.DiGraph)
1275
- lines = []
1276
- write = lines.append
1277
- write("--- directed case, max_depth=None ---")
1278
- nx.write_network_text(orig, path=write, end="", max_depth=None)
1279
- write("--- directed case, max_depth=0 ---")
1280
- nx.write_network_text(orig, path=write, end="", max_depth=0)
1281
- write("--- directed case, max_depth=1 ---")
1282
- nx.write_network_text(orig, path=write, end="", max_depth=1)
1283
- write("--- directed case, max_depth=2 ---")
1284
- nx.write_network_text(orig, path=write, end="", max_depth=2)
1285
- write("--- directed case, max_depth=3 ---")
1286
- nx.write_network_text(orig, path=write, end="", max_depth=3)
1287
- write("--- undirected case, max_depth=None ---")
1288
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=None)
1289
- write("--- undirected case, max_depth=0 ---")
1290
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=0)
1291
- write("--- undirected case, max_depth=1 ---")
1292
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=1)
1293
- write("--- undirected case, max_depth=2 ---")
1294
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=2)
1295
- write("--- undirected case, max_depth=3 ---")
1296
- nx.write_network_text(orig.to_undirected(), path=write, end="", max_depth=3)
1297
- text = "\n".join(lines)
1298
- target = dedent(
1299
- """
1300
- --- directed case, max_depth=None ---
1301
- ╙── 0 ╾ 1, 2, 3, 4
1302
- ├─╼ 1 ╾ 2, 3, 4
1303
- │ ├─╼ 2 ╾ 0, 3, 4
1304
- │ │ ├─╼ 3 ╾ 0, 1, 4
1305
- │ │ │ ├─╼ 4 ╾ 0, 1, 2
1306
- │ │ │ │ └─╼ ...
1307
- │ │ │ └─╼ ...
1308
- │ │ └─╼ ...
1309
- │ └─╼ ...
1310
- └─╼ ...
1311
- --- directed case, max_depth=0 ---
1312
- ╙ ...
1313
- --- directed case, max_depth=1 ---
1314
- ╙── 0 ╾ 1, 2, 3, 4
1315
- └─╼ ...
1316
- --- directed case, max_depth=2 ---
1317
- ╙── 0 ╾ 1, 2, 3, 4
1318
- ├─╼ 1 ╾ 2, 3, 4
1319
- │ └─╼ ...
1320
- ├─╼ 2 ╾ 1, 3, 4
1321
- │ └─╼ ...
1322
- ├─╼ 3 ╾ 1, 2, 4
1323
- │ └─╼ ...
1324
- └─╼ 4 ╾ 1, 2, 3
1325
- └─╼ ...
1326
- --- directed case, max_depth=3 ---
1327
- ╙── 0 ╾ 1, 2, 3, 4
1328
- ├─╼ 1 ╾ 2, 3, 4
1329
- │ ├─╼ 2 ╾ 0, 3, 4
1330
- │ │ └─╼ ...
1331
- │ ├─╼ 3 ╾ 0, 2, 4
1332
- │ │ └─╼ ...
1333
- │ ├─╼ 4 ╾ 0, 2, 3
1334
- │ │ └─╼ ...
1335
- │ └─╼ ...
1336
- └─╼ ...
1337
- --- undirected case, max_depth=None ---
1338
- ╙── 0
1339
- ├── 1
1340
- │ ├── 2 ─ 0
1341
- │ │ ├── 3 ─ 0, 1
1342
- │ │ │ └── 4 ─ 0, 1, 2
1343
- │ │ └── ...
1344
- │ └── ...
1345
- └── ...
1346
- --- undirected case, max_depth=0 ---
1347
- ╙ ...
1348
- --- undirected case, max_depth=1 ---
1349
- ╙── 0 ─ 1, 2, 3, 4
1350
- └── ...
1351
- --- undirected case, max_depth=2 ---
1352
- ╙── 0
1353
- ├── 1 ─ 2, 3, 4
1354
- │ └── ...
1355
- ├── 2 ─ 1, 3, 4
1356
- │ └── ...
1357
- ├── 3 ─ 1, 2, 4
1358
- │ └── ...
1359
- └── 4 ─ 1, 2, 3
1360
- --- undirected case, max_depth=3 ---
1361
- ╙── 0
1362
- ├── 1
1363
- │ ├── 2 ─ 0, 3, 4
1364
- │ │ └── ...
1365
- │ ├── 3 ─ 0, 2, 4
1366
- │ │ └── ...
1367
- │ └── 4 ─ 0, 2, 3
1368
- └── ...
1369
- """
1370
- ).strip()
1371
- assert target == text
1372
-
1373
-
1374
- def test_write_network_text_custom_label():
1375
- # Create a directed forest with labels
1376
- graph = nx.erdos_renyi_graph(5, 0.4, directed=True, seed=359222358)
1377
- for node in graph.nodes:
1378
- graph.nodes[node]["label"] = f"Node({node})"
1379
- graph.nodes[node]["chr"] = chr(node + ord("a") - 1)
1380
- if node % 2 == 0:
1381
- graph.nodes[node]["part"] = chr(node + ord("a"))
1382
-
1383
- lines = []
1384
- write = lines.append
1385
- write("--- when with_labels=True, uses the 'label' attr ---")
1386
- nx.write_network_text(graph, path=write, with_labels=True, end="", max_depth=None)
1387
- write("--- when with_labels=False, uses str(node) value ---")
1388
- nx.write_network_text(graph, path=write, with_labels=False, end="", max_depth=None)
1389
- write("--- when with_labels is a string, use that attr ---")
1390
- nx.write_network_text(graph, path=write, with_labels="chr", end="", max_depth=None)
1391
- write("--- fallback to str(node) when the attr does not exist ---")
1392
- nx.write_network_text(graph, path=write, with_labels="part", end="", max_depth=None)
1393
-
1394
- text = "\n".join(lines)
1395
- target = dedent(
1396
- """
1397
- --- when with_labels=True, uses the 'label' attr ---
1398
- ╙── Node(1)
1399
- └─╼ Node(3) ╾ Node(2)
1400
- ├─╼ Node(0)
1401
- │ ├─╼ Node(2) ╾ Node(3), Node(4)
1402
- │ │ └─╼ ...
1403
- │ └─╼ Node(4)
1404
- │ └─╼ ...
1405
- └─╼ ...
1406
- --- when with_labels=False, uses str(node) value ---
1407
- ╙── 1
1408
- └─╼ 3 ╾ 2
1409
- ├─╼ 0
1410
- │ ├─╼ 2 ╾ 3, 4
1411
- │ │ └─╼ ...
1412
- │ └─╼ 4
1413
- │ └─╼ ...
1414
- └─╼ ...
1415
- --- when with_labels is a string, use that attr ---
1416
- ╙── a
1417
- └─╼ c ╾ b
1418
- ├─╼ `
1419
- │ ├─╼ b ╾ c, d
1420
- │ │ └─╼ ...
1421
- │ └─╼ d
1422
- │ └─╼ ...
1423
- └─╼ ...
1424
- --- fallback to str(node) when the attr does not exist ---
1425
- ╙── 1
1426
- └─╼ 3 ╾ c
1427
- ├─╼ a
1428
- │ ├─╼ c ╾ 3, e
1429
- │ │ └─╼ ...
1430
- │ └─╼ e
1431
- │ └─╼ ...
1432
- └─╼ ...
1433
- """
1434
- ).strip()
1435
- assert target == text
1436
-
1437
-
1438
- def test_write_network_text_vertical_chains():
1439
- graph1 = nx.lollipop_graph(4, 2, create_using=nx.Graph)
1440
- graph1.add_edge(0, -1)
1441
- graph1.add_edge(-1, -2)
1442
- graph1.add_edge(-2, -3)
1443
-
1444
- graph2 = graph1.to_directed()
1445
- graph2.remove_edges_from([(u, v) for u, v in graph2.edges if v > u])
1446
-
1447
- lines = []
1448
- write = lines.append
1449
- write("--- Undirected UTF ---")
1450
- nx.write_network_text(graph1, path=write, end="", vertical_chains=True)
1451
- write("--- Undirected ASCI ---")
1452
- nx.write_network_text(
1453
- graph1, path=write, end="", vertical_chains=True, ascii_only=True
1454
- )
1455
- write("--- Directed UTF ---")
1456
- nx.write_network_text(graph2, path=write, end="", vertical_chains=True)
1457
- write("--- Directed ASCI ---")
1458
- nx.write_network_text(
1459
- graph2, path=write, end="", vertical_chains=True, ascii_only=True
1460
- )
1461
-
1462
- text = "\n".join(lines)
1463
- target = dedent(
1464
- """
1465
- --- Undirected UTF ---
1466
- ╙── 5
1467
-
1468
- 4
1469
-
1470
- 3
1471
- ├── 0
1472
- │ ├── 1 ─ 3
1473
- │ │ │
1474
- │ │ 2 ─ 0, 3
1475
- │ ├── -1
1476
- │ │ │
1477
- │ │ -2
1478
- │ │ │
1479
- │ │ -3
1480
- │ └── ...
1481
- └── ...
1482
- --- Undirected ASCI ---
1483
- +-- 5
1484
- |
1485
- 4
1486
- |
1487
- 3
1488
- |-- 0
1489
- | |-- 1 - 3
1490
- | | |
1491
- | | 2 - 0, 3
1492
- | |-- -1
1493
- | | |
1494
- | | -2
1495
- | | |
1496
- | | -3
1497
- | L-- ...
1498
- L-- ...
1499
- --- Directed UTF ---
1500
- ╙── 5
1501
-
1502
- 4
1503
-
1504
- 3
1505
- ├─╼ 0 ╾ 1, 2
1506
- │ ╽
1507
- │ -1
1508
- │ ╽
1509
- │ -2
1510
- │ ╽
1511
- │ -3
1512
- ├─╼ 1 ╾ 2
1513
- │ └─╼ ...
1514
- └─╼ 2
1515
- └─╼ ...
1516
- --- Directed ASCI ---
1517
- +-- 5
1518
- !
1519
- 4
1520
- !
1521
- 3
1522
- |-> 0 <- 1, 2
1523
- | !
1524
- | -1
1525
- | !
1526
- | -2
1527
- | !
1528
- | -3
1529
- |-> 1 <- 2
1530
- | L-> ...
1531
- L-> 2
1532
- L-> ...
1533
- """
1534
- ).strip()
1535
- assert target == text
1536
-
1537
-
1538
- def test_collapse_directed():
1539
- graph = nx.balanced_tree(r=2, h=3, create_using=nx.DiGraph)
1540
- lines = []
1541
- write = lines.append
1542
- write("--- Original ---")
1543
- nx.write_network_text(graph, path=write, end="")
1544
- graph.nodes[1]["collapse"] = True
1545
- write("--- Collapse Node 1 ---")
1546
- nx.write_network_text(graph, path=write, end="")
1547
- write("--- Add alternate path (5, 3) to collapsed zone")
1548
- graph.add_edge(5, 3)
1549
- nx.write_network_text(graph, path=write, end="")
1550
- write("--- Collapse Node 0 ---")
1551
- graph.nodes[0]["collapse"] = True
1552
- nx.write_network_text(graph, path=write, end="")
1553
- text = "\n".join(lines)
1554
- target = dedent(
1555
- """
1556
- --- Original ---
1557
- ╙── 0
1558
- ├─╼ 1
1559
- │ ├─╼ 3
1560
- │ │ ├─╼ 7
1561
- │ │ └─╼ 8
1562
- │ └─╼ 4
1563
- │ ├─╼ 9
1564
- │ └─╼ 10
1565
- └─╼ 2
1566
- ├─╼ 5
1567
- │ ├─╼ 11
1568
- │ └─╼ 12
1569
- └─╼ 6
1570
- ├─╼ 13
1571
- └─╼ 14
1572
- --- Collapse Node 1 ---
1573
- ╙── 0
1574
- ├─╼ 1
1575
- │ └─╼ ...
1576
- └─╼ 2
1577
- ├─╼ 5
1578
- │ ├─╼ 11
1579
- │ └─╼ 12
1580
- └─╼ 6
1581
- ├─╼ 13
1582
- └─╼ 14
1583
- --- Add alternate path (5, 3) to collapsed zone
1584
- ╙── 0
1585
- ├─╼ 1
1586
- │ └─╼ ...
1587
- └─╼ 2
1588
- ├─╼ 5
1589
- │ ├─╼ 11
1590
- │ ├─╼ 12
1591
- │ └─╼ 3 ╾ 1
1592
- │ ├─╼ 7
1593
- │ └─╼ 8
1594
- └─╼ 6
1595
- ├─╼ 13
1596
- └─╼ 14
1597
- --- Collapse Node 0 ---
1598
- ╙── 0
1599
- └─╼ ...
1600
- """
1601
- ).strip()
1602
- assert target == text
1603
-
1604
-
1605
- def test_collapse_undirected():
1606
- graph = nx.balanced_tree(r=2, h=3, create_using=nx.Graph)
1607
- lines = []
1608
- write = lines.append
1609
- write("--- Original ---")
1610
- nx.write_network_text(graph, path=write, end="", sources=[0])
1611
- graph.nodes[1]["collapse"] = True
1612
- write("--- Collapse Node 1 ---")
1613
- nx.write_network_text(graph, path=write, end="", sources=[0])
1614
- write("--- Add alternate path (5, 3) to collapsed zone")
1615
- graph.add_edge(5, 3)
1616
- nx.write_network_text(graph, path=write, end="", sources=[0])
1617
- write("--- Collapse Node 0 ---")
1618
- graph.nodes[0]["collapse"] = True
1619
- nx.write_network_text(graph, path=write, end="", sources=[0])
1620
- text = "\n".join(lines)
1621
- target = dedent(
1622
- """
1623
- --- Original ---
1624
- ╙── 0
1625
- ├── 1
1626
- │ ├── 3
1627
- │ │ ├── 7
1628
- │ │ └── 8
1629
- │ └── 4
1630
- │ ├── 9
1631
- │ └── 10
1632
- └── 2
1633
- ├── 5
1634
- │ ├── 11
1635
- │ └── 12
1636
- └── 6
1637
- ├── 13
1638
- └── 14
1639
- --- Collapse Node 1 ---
1640
- ╙── 0
1641
- ├── 1 ─ 3, 4
1642
- │ └── ...
1643
- └── 2
1644
- ├── 5
1645
- │ ├── 11
1646
- │ └── 12
1647
- └── 6
1648
- ├── 13
1649
- └── 14
1650
- --- Add alternate path (5, 3) to collapsed zone
1651
- ╙── 0
1652
- ├── 1 ─ 3, 4
1653
- │ └── ...
1654
- └── 2
1655
- ├── 5
1656
- │ ├── 11
1657
- │ ├── 12
1658
- │ └── 3 ─ 1
1659
- │ ├── 7
1660
- │ └── 8
1661
- └── 6
1662
- ├── 13
1663
- └── 14
1664
- --- Collapse Node 0 ---
1665
- ╙── 0 ─ 1, 2
1666
- └── ...
1667
- """
1668
- ).strip()
1669
- assert target == text
1670
-
1671
-
1672
- def generate_test_graphs():
1673
- """
1674
- Generate a gauntlet of different test graphs with different properties
1675
- """
1676
- import random
1677
-
1678
- rng = random.Random(976689776)
1679
- num_randomized = 3
1680
-
1681
- for directed in [0, 1]:
1682
- cls = nx.DiGraph if directed else nx.Graph
1683
-
1684
- for num_nodes in range(17):
1685
- # Disconnected graph
1686
- graph = cls()
1687
- graph.add_nodes_from(range(num_nodes))
1688
- yield graph
1689
-
1690
- # Randomize graphs
1691
- if num_nodes > 0:
1692
- for p in [0.1, 0.3, 0.5, 0.7, 0.9]:
1693
- for seed in range(num_randomized):
1694
- graph = nx.erdos_renyi_graph(
1695
- num_nodes, p, directed=directed, seed=rng
1696
- )
1697
- yield graph
1698
-
1699
- yield nx.complete_graph(num_nodes, cls)
1700
-
1701
- yield nx.path_graph(3, create_using=cls)
1702
- yield nx.balanced_tree(r=1, h=3, create_using=cls)
1703
- if not directed:
1704
- yield nx.circular_ladder_graph(4, create_using=cls)
1705
- yield nx.star_graph(5, create_using=cls)
1706
- yield nx.lollipop_graph(4, 2, create_using=cls)
1707
- yield nx.wheel_graph(7, create_using=cls)
1708
- yield nx.dorogovtsev_goltsev_mendes_graph(4, create_using=cls)
1709
-
1710
-
1711
- @pytest.mark.parametrize(
1712
- ("vertical_chains", "ascii_only"),
1713
- tuple(
1714
- [
1715
- (vertical_chains, ascii_only)
1716
- for vertical_chains in [0, 1]
1717
- for ascii_only in [0, 1]
1718
- ]
1719
- ),
1720
- )
1721
- def test_network_text_round_trip(vertical_chains, ascii_only):
1722
- """
1723
- Write the graph to network text format, then parse it back in, assert it is
1724
- the same as the original graph. Passing this test is strong validation of
1725
- both the format generator and parser.
1726
- """
1727
- from networkx.readwrite.text import _parse_network_text
1728
-
1729
- for graph in generate_test_graphs():
1730
- graph = nx.relabel_nodes(graph, {n: str(n) for n in graph.nodes})
1731
- lines = list(
1732
- nx.generate_network_text(
1733
- graph, vertical_chains=vertical_chains, ascii_only=ascii_only
1734
- )
1735
- )
1736
- new = _parse_network_text(lines)
1737
- try:
1738
- assert new.nodes == graph.nodes
1739
- assert new.edges == graph.edges
1740
- except Exception:
1741
- nx.write_network_text(graph)
1742
- raise