code: def test_insert_audio_trigger(art_warning):
      file_path = os.path.join(
          os.getcwd(), "utils/data/backdoors/cough_trigger.wav"
      )
      try:
          # test single example
          trigger = CacheAudioTrigger(
              sampling_rate=16000, backdoor_path=file_path
          )
          audio = trigger.insert(x=np.zeros(32000))
          assert audio.shape == (32000,)
          assert np.max(audio) != 0
          assert np.max(np.abs(audio)) <= 1.0
  
          # test single example with differet duration and scale
          trigger = CacheAudioTrigger(
              sampling_rate=16000,
              backdoor_path=file_path,
              duration=0.8,
              scale=0.5,
          )
          audio = trigger.insert(x=np.zeros(32000))
          assert audio.shape == (32000,)
          assert np.max(audio) != 0
  
          # test a batch of examples
          trigger = CacheAudioTrigger(
              sampling_rate=16000, backdoor_path=file_path
          )
          audio = trigger.insert(x=np.zeros((10, 16000)))
  
          assert audio.shape == (10, 16000)
          assert np.max(audio) != 0
  
          # test single example with shift
          trigger = CacheAudioTrigger(
              sampling_rate=16000, backdoor_path=file_path, shift=10
          )
          audio = trigger.insert(x=np.zeros(32000))
          assert audio.shape == (32000,)
          assert np.max(audio) != 0
          assert np.sum(audio[:10]) == 0
  
          # test a batch of examples with random shift
          trigger = CacheAudioTrigger(
              sampling_rate=16000, backdoor_path=file_path, random=True
          )
          audio = trigger.insert(x=np.zeros((10, 32000)))
          assert audio.shape == (10, 32000)
          assert np.max(audio) != 0
  
          # test when length of backdoor is larger than that of audio signal
          with pytest.raises(ValueError):
              trigger = CacheAudioTrigger(
                  sampling_rate=16000, backdoor_path=file_path
              )
              _ = trigger.insert(x=np.zeros(15000))
  
          # test when shift + backdoor is larger than that of audio signal
          with pytest.raises(ValueError):
              trigger = CacheAudioTrigger(
                  sampling_rate=16000,
                  backdoor_path=file_path,
                  duration=1,
                  shift=5,
              )
              _ = trigger.insert(x=np.zeros(16000))
  
      except ARTTestException as e:
          art_warning(e)
  
file_path: adversarial-robustness-toolbox/tests/attacks/poison/test_audio_perturbations.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import numpy
  import pytest
  import os
  from art.attacks.poisoning.perturbations.audio_perturbations import CacheToneTrigger, CacheAudioTrigger
  from tests.utils import ARTTestException
label_desc: Use image node_id 2 for calling a global function with example usage: test_insert_audio_trigger(art_warning) without return types