code: def assert_diagnostic(
      test_suite: unittest.TestCase,
      sarif_log_builder: _SarifLogBuilder,
      rule: infra.Rule,
      level: infra.Level,
  ):
      """Context manager to assert that a diagnostic is emitted.
  
      Usage:
          with assert_diagnostic(
              self,
              diagnostics.engine,
              rule,
              infra.Level.Error,
          ):
              torch.onnx.export(...)
  
      Args:
          test_suite: The test suite instance.
          sarif_log_builder: The SARIF log builder.
          rule: The rule to assert.
          level: The level to assert.
  
      Returns:
          A context manager.
  
      Raises:
          AssertionError: If the diagnostic is not emitted.
      """
  
      return assert_all_diagnostics(
          test_suite, sarif_log_builder, {(rule, level)}
      )
  
imports: from __future__ import annotations
  import contextlib
  import dataclasses
  import io
  import logging
  import typing
  import unittest
  from typing import AbstractSet, Protocol, Tuple
  import torch
  from torch.onnx import errors
  from torch.onnx._internal import diagnostics
  from torch.onnx._internal.diagnostics import infra
  from torch.onnx._internal.diagnostics.infra import formatter, sarif
  from torch.onnx._internal.fx import diagnostics
  from torch.testing._internal import common_utils, logging_utils
label_desc: Use image node_id 3 for calling a global function with example usage: assert_diagnostic(test_suite, sarif_log_builder, rule, level) and returns: assert_all_diagnostics