code: def test_node_space_sample():
      space = Graph(node_space=Discrete(3), edge_space=None)
      space.seed(0)
  
      sample = space.sample(
          mask=(
              tuple(
                  np.array([0, 1, 0], dtype=np.int8) for _ in range(5)
              ),
              None,
          ),
          num_nodes=5,
      )
      assert sample in space
      assert np.all(sample.nodes == 1)
  
      sample = space.sample(
          (
              (
                  np.array([1, 0, 0], dtype=np.int8),
                  np.array([0, 1, 0], dtype=np.int8),
              ),
              None,
          ),
          num_nodes=2,
      )
      assert sample in space
      assert np.all(sample.nodes == np.array([0, 1]))
  
      with pytest.warns(
          UserWarning,
          match=re.escape(
              "The number of edges is set (5) but the edge space is None."
          ),
      ):
          sample = space.sample(num_edges=5)
          assert sample in space
  
      # Change the node_space or edge_space to a non-Box or discrete space.
      # This should not happen, test is primarily to increase coverage.
      with pytest.raises(
          TypeError,
          match=re.escape(
              "Expects base space to be Box and Discrete, actual space: <class 'str'>"
          ),
      ):
          space.node_space = "abc"
          space.sample()
  
imports: import re
  import numpy
  import pytest
  from gym.spaces import Discrete, Graph, GraphInstance
label_desc: Use image node_id 1 for calling a global function with example usage: test_node_space_sample() without return types