code: def test_targeted_attacks(
      fmodel_and_data_ext_for_attacks: ModeAndDataAndDescription,
      attack_test_target: AttackTestTarget,
  ) -> None:
      (
          (fmodel, x, y),
          real,
          low_dimensional_input,
      ) = fmodel_and_data_ext_for_attacks
      if attack_test_target.requires_real_model and not real:
          pytest.skip()
      if (
          attack_test_target.requires_low_dimensional_input
          and not low_dimensional_input
      ):
          pytest.skip()
  
      if isinstance(x, ep.NumPyTensor) and attack_test_target.uses_grad:
          pytest.skip()
  
      x = (x - fmodel.bounds.lower) / (
          fmodel.bounds.upper - fmodel.bounds.lower
      )
      fmodel = fmodel.transform_bounds((0, 1))
  
      num_classes = fmodel(x).shape[-1]
      target_classes = (y + 1) % num_classes
      criterion = fbn.TargetedMisclassification(target_classes)
      adv_before_attack = criterion(x, fmodel(x))
      assert not adv_before_attack.all()
  
      asr = adv_before_attack.sum().item()
  
      # repeat stochastic attacks three times before we mark them as failed
      attack_repetitions = (
          3 if attack_test_target.stochastic_attack else 1
      )
  
      for _ in range(attack_repetitions):
          advs, _, _ = attack_test_target.attack(
              fmodel, x, criterion, epsilons=attack_test_target.epsilon
          )
          adv_after_attack = criterion(advs, fmodel(advs))
          adv_asr = adv_after_attack.sum().item()
          if adv_asr > asr:
              break
      assert adv_asr > asr
  
file_path: foolbox/tests/test_attacks.py
imports: from typing import List, Optional, NamedTuple
  import pytest
  import eagerpy
  import foolbox
  import foolbox.attacks
  from foolbox.gradient_estimators import es_gradient_estimator
  from conftest import ModeAndDataAndDescription
label_desc: Use image node_id 3 for calling a global function with example usage: test_targeted_attacks(fmodel_and_data_ext_for_attacks, attack_test_target) without return types