code: def test_run_context_pairs(line_graph):
      batch_size = 4
      sampler = UnsupervisedSampler(
          G=line_graph, length=2, number_of_walks=2
      )
      batches = sampler.run(batch_size)
  
      grouped_by_target = defaultdict(list)
  
      for ids, labels in batches:
          for (target, context), label in zip(ids, labels):
              grouped_by_target[target].append((context, label))
  
      assert len(grouped_by_target) == len(line_graph.nodes())
  
      for target, sampled in grouped_by_target.items():
          # exactly 2 positive and 2 negative context pairs for each target node
          assert len(sampled) == 4
  
          # since each walk has length = 2, there must be an edge between each positive context pair
          for context, label in sampled:
              if label == 1:
                  assert context in set(line_graph.neighbors(target))
  
file_path: stellargraph/tests/data/test_unsupervised_sampler.py
imports: import pytest
  import numpy
  from collections import defaultdict
  from stellargraph.data.unsupervised_sampler import UnsupervisedSampler
  from stellargraph.data.explorer import UniformRandomWalk
  from ..test_utils.graphs import line_graph
label_desc: Use image node_id 3 for calling a global function with example usage: test_run_context_pairs(line_graph) without return types