code: def test_modularity_communities_directed_weighted():
      G = nx.DiGraph()
      G.add_weighted_edges_from(
          [
              (1, 2, 5),
              (1, 3, 3),
              (2, 3, 6),
              (2, 6, 1),
              (1, 4, 1),
              (4, 5, 3),
              (4, 6, 7),
              (5, 6, 2),
              (5, 7, 5),
              (5, 8, 4),
              (6, 8, 3),
          ]
      )
      expected = [frozenset({4, 5, 6, 7, 8}), frozenset({1, 2, 3})]
      assert (
          greedy_modularity_communities(G, weight="weight") == expected
      )
  
      # A large weight of the edge (2, 6) causes 6 to change group, even if it shares
      # only one connection with the new group and 3 with the old one.
      G[2][6]["weight"] = 20
      expected = [frozenset({1, 2, 3, 6}), frozenset({4, 5, 7, 8})]
      assert (
          greedy_modularity_communities(G, weight="weight") == expected
      )
  
file_path: networkx/networkx/algorithms/community/tests/test_modularity_max.py
imports: import pytest
  import networkx
  from networkx.algorithms.community import greedy_modularity_communities, naive_greedy_modularity_communities
label_desc: Use image node_id 8 for calling a global function with example usage: test_modularity_communities_directed_weighted() without return types