code: def test_run():
      var0 = tf.Variable([1.0, 2.0])
      var1 = tf.Variable([3.0, 4.0])
  
      grads0 = tf.constant([0.1, 0.1])
      grads1 = tf.constant([0.01, 0.01])
  
      grads_and_vars = list(zip([grads0, grads1], [var0, var1]))
  
      if hasattr(tf.keras.optimizers, "legacy"):
          opt = MovingAverage(
              tf.keras.optimizers.legacy.SGD(lr=2.0), average_decay=0.5
          )
      else:
          opt = MovingAverage(
              tf.keras.optimizers.SGD(lr=2.0), average_decay=0.5
          )
  
      opt.apply_gradients(grads_and_vars)
      opt.apply_gradients(grads_and_vars)
  
      np.testing.assert_allclose(var0.read_value(), [0.6, 1.6])
      np.testing.assert_allclose(var1.read_value(), [2.96, 3.96])
  
      ema_var0 = opt.get_slot(var0, "average")
      ema_var1 = opt.get_slot(var1, "average")
  
      np.testing.assert_allclose(ema_var0.read_value(), [0.75, 1.75])
      np.testing.assert_allclose(ema_var1.read_value(), [2.975, 3.975])
  
      _ = opt.assign_average_vars([var0, var1])
  
      np.testing.assert_allclose(var0.read_value(), [0.75, 1.75])
      np.testing.assert_allclose(var1.read_value(), [2.975, 3.975])
  
      var0.assign_add([1.0, 1.0]),
      var1.assign_add([2.0, 2.0]),
      ema_var0.assign_add([3.0, 3.0]),
      ema_var1.assign_add([4.0, 4.0]),
  
      np.testing.assert_allclose(var0.read_value(), [1.75, 2.75])
      np.testing.assert_allclose(var1.read_value(), [4.975, 5.975])
      np.testing.assert_allclose(ema_var0.read_value(), [3.75, 4.75])
      np.testing.assert_allclose(ema_var1.read_value(), [6.975, 7.975])
  
imports: import numpy
  import pytest
  import tensorflow
  from packaging.version import Version
  from tensorflow_addons.optimizers import MovingAverage
label_desc: Use image node_id 1 for calling a global function with example usage: test_run() without return types