code: def test_warning_handler_template(self):
      with catch_warnings(record=True) as ws:
          warn(DeprecationWarning("foo"))
          warn(RuntimeWarning("bar"))
  
      self.assertFalse(any(_warning_handler_template(w) for w in ws))
      handler = partial(
          _warning_handler_template,
          debug=lambda w: issubclass(w.category, DeprecationWarning),
          rethrow=lambda w: True,
      )
      with self.assertLogs(level="DEBUG") as logs, catch_warnings(
          record=True
      ) as _ws:
          self.assertTrue(all(handler(w) for w in ws))
          self.assertEqual(1, len(logs.output))
          self.assertTrue("foo" in logs.output[0])
          self.assertEqual(1, len(_ws))
          self.assertEqual("bar", str(_ws[0].message))
  
file_path: botorch/test/optim/utils/test_common.py
imports: from __future__ import annotations
  from functools import partial
  from warnings import catch_warnings, warn
  import numpy
  from botorch.optim.utils import _filter_kwargs, _handle_numerical_errors, _warning_handler_template
  from botorch.utils.testing import BotorchTestCase
  from linear_operator.utils.errors import NanError, NotPSDError
label_desc: Use image node_id 3 for calling the TestUtilsCommon obj's underlying member method code with example usage: obj.test_warning_handler_template() without return types