code: def test_edge_space_sample():
      space = Graph(node_space=Discrete(3), edge_space=Discrete(3))
      space.seed(0)
      # When num_nodes>1 then num_edges is set to 0
      assert space.sample(num_nodes=1).edges is None
      assert 0 <= len(space.sample(num_edges=3).edges) < 6
  
      sample = space.sample(
          mask=(None, np.array([0, 1, 0], dtype=np.int8))
      )
      assert np.all(sample.edges == 1) or sample.edges is None
  
      sample = space.sample(
          mask=(
              None,
              (
                  np.array([1, 0, 0], dtype=np.int8),
                  np.array([0, 1, 0], dtype=np.int8),
                  np.array([0, 0, 1], dtype=np.int8),
              ),
          ),
          num_edges=3,
      )
      assert np.all(sample.edges == np.array([0, 1, 2]))
  
      with pytest.raises(
          AssertionError,
          match="Expects the number of edges to be greater than 0, actual value: -1",
      ):
          space.sample(num_edges=-1)
  
      space = Graph(node_space=Discrete(3), edge_space=None)
      with pytest.warns(
          UserWarning,
          match=re.escape(
              "\x1b[33mWARN: The number of edges is set (5) but the edge space is None.\x1b[0m"
          ),
      ):
          sample = space.sample(num_edges=5)
      assert sample.edges is None
  
imports: import re
  import numpy
  import pytest
  from gym.spaces import Discrete, Graph, GraphInstance
label_desc: Use image node_id 2 for calling a global function with example usage: test_edge_space_sample() without return types