code: def test_dump(self):
      data = np.random.randn(100, 2)
      target = np.array([0, 1] * 50)
      features = ["Feature1", "Feature2"]
  
      dm = xgb.DMatrix(data, label=target, feature_names=features)
      params = {
          "objective": "binary:logistic",
          "eval_metric": "logloss",
          "eta": 0.3,
          "max_depth": 1,
      }
  
      bst = xgb.train(params, dm, num_boost_round=1)
  
      # number of feature importances should == number of features
      dump1 = bst.get_dump()
      assert len(dump1) == 1, "Expected only 1 tree to be dumped."
      len(
          dump1[0].splitlines()
      ) == 3, "Expected 1 root and 2 leaves - 3 lines in dump."
  
      dump2 = bst.get_dump(with_stats=True)
      assert (
          dump2[0].count("\n") == 3
      ), "Expected 1 root and 2 leaves - 3 lines in dump."
      msg = "Expected more info when with_stats=True is given."
      assert dump2[0].find("\n") > dump1[0].find("\n"), msg
  
      dump3 = bst.get_dump(dump_format="json")
      dump3j = json.loads(dump3[0])
      assert dump3j["nodeid"] == 0, "Expected the root node on top."
  
      dump4 = bst.get_dump(dump_format="json", with_stats=True)
      dump4j = json.loads(dump4[0])
      assert "gain" in dump4j, "Expected 'gain' to be dumped in JSON."
  
      with pytest.raises(ValueError):
          bst.get_dump(fmap="foo")
  
imports: import json
  import os
  import pathlib
  import tempfile
  from pathlib import Path
  import numpy
  import pytest
  import xgboost
  from xgboost import testing
label_desc: Use image node_id 5 for calling the TestBasic obj's underlying member method code with example usage: obj.test_dump() without return types