class_docstr: Tests for the expval function
class_docstr_tok: ["Tests","for","the","expval","function"]
docstr: Tests that the expectation of a ``Projector`` object is computed correctly for both of
  its subclasses.
docstr_tok: ["Tests","that","the","expectation","of","a","``","Projector","``","object","is","computed","correctly","for","both","of","its","subclasses","."]
code: def test_projector_expval(self, state, shots, mocker):
      """Tests that the expectation of a ``Projector`` object is computed correctly for both of
      its subclasses."""
      dev = qml.device("default.qubit.legacy", wires=3, shots=shots)
      np.random.seed(42)
  
      @qml.qnode(dev)
      def circuit():
          qml.Hadamard(0)
          return qml.expval(qml.Projector(state, wires=range(3)))
  
      new_dev = circuit.device
      spy = mocker.spy(qml.QubitDevice, "expval")
  
      res = circuit()
      expected = [0.5, 0.5] if isinstance(shots, list) else 0.5
      assert np.allclose(res, expected, atol=0.02, rtol=0.02)
  
      custom_measurement_process(new_dev, spy)
  
file_path: pennylane/tests/measurements/legacy/test_expval_legacy.py
imports: import numpy
  import pytest
  import pennylane
  from pennylane.measurements import Expectation, Shots
  from pennylane.devices.qubit.measure import flatten_state
label_desc: Use image node_id 8 for calling the TestExpval obj's underlying member method code with example usage: obj.test_projector_expval(state, shots, mocker) and returns: qml