code: def test_formats():
      g = dgl.rand_graph(10, 20)
      # in_degrees works if coo or csc available
      # out_degrees works if coo or csr available
      try:
          g.in_degrees()
          g.out_degrees()
          g.formats("coo").in_degrees()
          g.formats("coo").out_degrees()
          g.formats("csc").in_degrees()
          g.formats("csr").out_degrees()
          fail = False
      except DGLError:
          fail = True
      finally:
          assert not fail
      # in_degrees NOT works if csc available only
      try:
          g.formats("csc").out_degrees()
          fail = True
      except DGLError:
          fail = False
      finally:
          assert not fail
      # out_degrees NOT works if csr available only
      try:
          g.formats("csr").in_degrees()
          fail = True
      except DGLError:
          fail = False
      finally:
          assert not fail
  
      # If the intersection of created formats and allowed formats is
      # not empty, then retain the intersection.
      # Case1: intersection is not empty and intersected is equal to
      # created formats.
      g = g.formats(["coo", "csr"])
      g.create_formats_()
      g = g.formats(["coo", "csr", "csc"])
      assert sorted(g.formats()["created"]) == sorted(["coo", "csr"])
      assert sorted(g.formats()["not created"]) == sorted(["csc"])
  
      # Case2: intersection is not empty and intersected is not equal
      # to created formats.
      g = g.formats(["coo", "csr"])
      g.create_formats_()
      g = g.formats(["coo", "csc"])
      assert sorted(g.formats()["created"]) == sorted(["coo"])
      assert sorted(g.formats()["not created"]) == sorted(["csc"])
  
      # If the intersection of created formats and allowed formats is
      # empty, then create a format in the order of `coo` -> `csr` ->
      # `csc`.
      # Case1: intersection is empty and just one format is allowed.
      g = g.formats(["coo", "csr"])
      g.create_formats_()
      g = g.formats(["csc"])
      assert sorted(g.formats()["created"]) == sorted(["csc"])
      assert sorted(g.formats()["not created"]) == sorted([])
  
      # Case2: intersection is empty and more than one format is allowed.
      g = g.formats("csc")
      g.create_formats_()
      g = g.formats(["csr", "coo"])
      assert sorted(g.formats()["created"]) == sorted(["coo"])
      assert sorted(g.formats()["not created"]) == sorted(["csr"])
  
imports: import math
  import numbers
  import backend
  import dgl
  import networkx
  import numpy
  import pytest
  import scipy.sparse
  from dgl import DGLError
label_desc: Use image node_id 17 for calling a global function with example usage: test_formats() without return types