class_docstr: Tests for sparse hamiltonian observable
class_docstr_tok: ["Tests","for","sparse","hamiltonian","observable"]
docstr: Test that a DeviceError is raised when the observable is SparseHamiltonian and finite
  shots is requested.
docstr_tok: ["Test","that","a","DeviceError","is","raised","when","the","observable","is","SparseHamiltonian","and","finite","shots","is","requested","."]
code: def test_sparse_expval_error(self):
      """Test that a DeviceError is raised when the observable is SparseHamiltonian and finite
      shots is requested."""
      hamiltonian = csr_matrix(np.array([[1.0, 0.0], [0.0, 1.0]]))
  
      dev = qml.device("default.qubit", wires=1)
      qs = qml.tape.QuantumScript(
          measurements=[
              qml.expval(qml.SparseHamiltonian(hamiltonian, [0]))
          ],
          shots=1,
      )
  
      with pytest.raises(qml.operation.DiagGatesUndefinedError):
          dev.execute(qs)
  
file_path: pennylane/tests/ops/qubit/test_sparse.py
imports: import pytest
  import numpy
  from scipy.sparse import coo_matrix, csr_matrix
  import pennylane
label_desc: Use image node_id 10 for calling the TestSparse obj's underlying member method code with example usage: obj.test_sparse_expval_error() without return types