code: def test_tensor_init_context(device, precision, dtype):
      """Test that tensors under the init-tensor-context get moved to the right device and dtype."""
      device = torch.device(device)
      strategy = SingleDeviceStrategy(
          device=device, precision=precision
      )  # surrogate class to test base class
      with strategy.tensor_init_context():
          tensor0 = torch.tensor(42.0)
          tensor1 = torch.tensor(42)
          tensor2 = torch.tensor(42.0, dtype=torch.half)
  
      expected_device = (
          device if _TORCH_GREATER_EQUAL_2_0 else torch.device("cpu")
      )
      assert (
          tensor0.device
          == tensor1.device
          == tensor2.device
          == expected_device
      )
      assert tensor0.dtype == dtype
      assert (
          tensor1.dtype == torch.long
      )  # `.init_tensor()` only affects floating point dtypes
      assert tensor2.dtype == torch.half
  
imports: from unittest import mock
  from unittest.mock import Mock, PropertyMock
  import pytest
  import torch
  from lightning.fabric.plugins import DoublePrecision, HalfPrecision, Precision
  from lightning.fabric.strategies import SingleDeviceStrategy
  from lightning.fabric.utilities.imports import _TORCH_GREATER_EQUAL_2_0
  from lightning.fabric.utilities.types import _Stateful
  from tests_fabric.helpers.runif import RunIf
label_desc: Use image node_id 12 for calling a global function with example usage: test_tensor_init_context(device, precision, dtype) without return types