code: def test_generate_attacks_and_targeted(
      art_warning, fix_get_mnist_subset, image_dl_estimator
  ):
      try:
          classifier, _ = image_dl_estimator(from_logits=True)
  
          norm = np.inf
          eps = 0.3
          eps_step = 0.1
          batch_size = 32
  
          attacks = list()
          attacks.append(
              AutoProjectedGradientDescent(
                  estimator=classifier,
                  norm=norm,
                  eps=eps,
                  eps_step=eps_step,
                  max_iter=100,
                  targeted=True,
                  nb_random_init=5,
                  batch_size=batch_size,
                  loss_type="cross_entropy",
              )
          )
          attacks.append(
              AutoProjectedGradientDescent(
                  estimator=classifier,
                  norm=norm,
                  eps=eps,
                  eps_step=eps_step,
                  max_iter=100,
                  targeted=False,
                  nb_random_init=5,
                  batch_size=batch_size,
                  loss_type="difference_logits_ratio",
              )
          )
          attacks.append(
              DeepFool(
                  classifier=classifier,
                  max_iter=100,
                  epsilon=1e-6,
                  nb_grads=3,
                  batch_size=batch_size,
              )
          )
          attacks.append(
              SquareAttack(
                  estimator=classifier,
                  norm=norm,
                  max_iter=5000,
                  eps=eps,
                  p_init=0.8,
                  nb_restarts=5,
              )
          )
  
          (
              x_train_mnist,
              y_train_mnist,
              x_test_mnist,
              y_test_mnist,
          ) = fix_get_mnist_subset
  
          # First test with defined_attack_only=False
          attack = AutoAttack(
              estimator=classifier,
              norm=norm,
              eps=eps,
              eps_step=eps_step,
              attacks=attacks,
              batch_size=batch_size,
              estimator_orig=None,
              targeted=False,
          )
  
          x_train_mnist_adv = attack.generate(
              x=x_train_mnist, y=y_train_mnist
          )
  
          assert np.mean(
              np.abs(x_train_mnist_adv - x_train_mnist)
          ) == pytest.approx(0.0182, abs=0.105)
          assert np.max(
              np.abs(x_train_mnist_adv - x_train_mnist)
          ) == pytest.approx(0.3, abs=0.05)
  
          # Then test with defined_attack_only=True
          attack = AutoAttack(
              estimator=classifier,
              norm=norm,
              eps=eps,
              eps_step=eps_step,
              attacks=attacks,
              batch_size=batch_size,
              estimator_orig=None,
              targeted=True,
          )
  
          x_train_mnist_adv = attack.generate(
              x=x_train_mnist, y=y_train_mnist
          )
  
          assert np.mean(
              x_train_mnist_adv - x_train_mnist
          ) == pytest.approx(0.0179, abs=0.0075)
          assert np.max(
              np.abs(x_train_mnist_adv - x_train_mnist)
          ) == pytest.approx(eps, abs=0.005)
      except ARTTestException as e:
          art_warning(e)
  
file_path: adversarial-robustness-toolbox/tests/attacks/evasion/test_auto_attack.py
imports: import logging
  import pytest
  import numpy
  from art.attacks.evasion import AutoAttack
  from art.attacks.evasion.auto_projected_gradient_descent import AutoProjectedGradientDescent
  from art.attacks.evasion.deepfool import DeepFool
  from art.attacks.evasion.square_attack import SquareAttack
  from art.estimators.estimator import BaseEstimator
  from art.estimators.classification.classifier import ClassifierMixin
  from tests.attacks.utils import backend_test_classifier_type_check_fail
  from tests.utils import ARTTestException
label_desc: Use image node_id 3 for calling a global function with example usage: test_generate_attacks_and_targeted(art_warning, fix_get_mnist_subset, image_dl_estimator) without return types