code: def test_poison(
      art_warning,
      get_default_mnist_subset,
      image_dl_estimator,
      framework,
  ):
      try:
          (x_train, y_train), (_, _) = get_default_mnist_subset
          functional = True
          if framework == "huggingface":
              functional = False
          classifier, _ = image_dl_estimator(functional=functional)
  
          if isinstance(
              classifier,
              (PyTorchClassifier, HuggingFaceClassifierPyTorch),
          ):
  
              def mod(x):
                  original_dtype = x.dtype
                  x = np.transpose(x, (0, 2, 3, 1)).astype(np.float32)
                  x = add_pattern_bd(x)
                  x = np.transpose(x, (0, 3, 1, 2)).astype(np.float32)
                  return x.astype(original_dtype)
  
          else:
  
              def mod(x):
                  original_dtype = x.dtype
                  x = add_pattern_bd(x)
                  return x.astype(original_dtype)
  
          backdoor = PoisoningAttackBackdoor(mod)
          target = y_train[0]
          diff_index = list(
              set(np.arange(len(y_train)))
              - set(np.where(np.all(y_train == target, axis=1))[0])
          )[0]
          source = y_train[diff_index]
          attack = HiddenTriggerBackdoor(
              classifier,
              eps=0.3,
              target=target,
              source=source,
              feature_layer=len(classifier.layer_names) - 2,
              backdoor=backdoor,
              decay_coeff=0.95,
              decay_iter=1,
              max_iter=2,
              batch_size=1,
          )
          poison_data, poison_inds = attack.poison(x_train, y_train)
  
          with pytest.raises(AssertionError):
              np.testing.assert_equal(poison_data, x_train[poison_inds])
  
      except ARTTestException as e:
          art_warning(e)
  
file_path: adversarial-robustness-toolbox/tests/attacks/poison/test_hidden_trigger_backdoor.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import numpy
  import pytest
  from art.attacks.poisoning import HiddenTriggerBackdoor
  from art.attacks.poisoning import PoisoningAttackBackdoor
  from art.attacks.poisoning.perturbations import add_pattern_bd
  from art.estimators.classification.pytorch import PyTorchClassifier
  from art.estimators.classification.hugging_face import HuggingFaceClassifierPyTorch
  from tests.utils import ARTTestException
label_desc: Use image node_id 1 for calling a global function with example usage: test_poison(art_warning, get_default_mnist_subset, image_dl_estimator, framework) and returns: x, x