class_docstr: Tests dp_optimizer_keras_sparse optimizers.
class_docstr_tok: ["Tests","dp_optimizer_keras_sparse","optimizers","."]
docstr: Tests that assertion fails when DP gradients are not computed.
docstr_tok: ["Tests","that","assertion","fails","when","DP","gradients","are","not","computed","."]
code: def testAssertOnNoCallOfComputeGradients(self, cls):
      """Tests that assertion fails when DP gradients are not computed."""
      opt = cls(
          l2_norm_clip=100.0,
          noise_multiplier=0.0,
          num_microbatches=1,
          learning_rate=2.0,
      )
  
      with self.assertRaises(AssertionError):
          grads_and_vars = tf.Variable([0.0])
          opt.apply_gradients(grads_and_vars)
  
      # Expect no exception if _compute_gradients is called.
      var0 = tf.Variable([0.0])
      data0 = tf.Variable([[0.0]])
      loss = lambda: self._loss(data0, var0)
      grads_and_vars = opt._compute_gradients(loss, [var0])
      opt.apply_gradients(grads_and_vars)
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow_privacy.privacy.optimizers import dp_optimizer_keras_sparse
label_desc: Use image node_id 7 for calling the DPOptimizerTest obj's underlying member method code with example usage: obj.testAssertOnNoCallOfComputeGradients(cls) without return types