code: def test_to_sparse_tensor_basic(layout):
      transform = ToSparseTensor(layout=layout)
      assert str(transform) == (
          f"ToSparseTensor(attr=edge_weight, " f"layout={layout})"
      )
  
      edge_index = torch.tensor([[0, 1, 1, 2], [1, 0, 2, 1]])
      edge_weight = torch.randn(edge_index.size(1))
      edge_attr = torch.randn(edge_index.size(1), 8)
  
      perm = torch.tensor([1, 0, 3, 2])
  
      data = Data(
          edge_index=edge_index,
          edge_weight=edge_weight,
          edge_attr=edge_attr,
          num_nodes=3,
      )
      data = transform(data)
  
      assert len(data) == 3
      assert data.num_nodes == 3
      assert torch.equal(data.edge_attr, edge_attr[perm])
      assert "adj_t" in data
  
      if layout is None and torch_geometric.typing.WITH_TORCH_SPARSE:
          row, col, value = data.adj_t.coo()
          assert row.tolist() == [0, 1, 1, 2]
          assert col.tolist() == [1, 0, 2, 1]
          assert torch.equal(value, edge_weight[perm])
      else:
          adj_t = data.adj_t
          assert adj_t.layout == layout or torch.sparse_csr
          if layout != torch.sparse_coo:
              adj_t = adj_t.to_sparse_coo()
          assert adj_t.coalesce().indices().tolist() == [
              [0, 1, 1, 2],
              [1, 0, 2, 1],
          ]
          assert torch.equal(
              adj_t.coalesce().values(), edge_weight[perm]
          )
  
file_path: pytorch_geometric/test/transforms/test_to_sparse_tensor.py
imports: import pytest
  import torch
  import torch_geometric.typing
  from torch_geometric.data import Data, HeteroData
  from torch_geometric.transforms import ToSparseTensor
label_desc: Use image node_id 1 for calling a global function with example usage: test_to_sparse_tensor_basic(layout) without return types