code: def test_ensure_frozen(caplog):
      assert ensure_frozen(Categorical([1, 2, 3]), strict=False) == 1
      assert (
          ensure_frozen(
              Categorical([1, 2, 3], label="a"),
              sample={"a": 2},
              strict=False,
          )
          == 2
      )
      assert ensure_frozen("anything", strict=False) == "anything"
  
      with pytest.raises(RuntimeError, match="context"):
          ensure_frozen(Categorical([1, 2, 3], label="a"))
  
      with frozen_context({"a": 1, "b": 2}):
          assert ensure_frozen(Categorical([1, 2], label="a")) == 1
          assert ensure_frozen(Categorical([1, 2], label="b")) == 2
          assert (
              ensure_frozen(
                  Categorical([1, 2], label="a")
                  + Categorical([1, 2], label="b")
              )
              == 3
          )
          with pytest.raises(
              SampleValidationError, match="missing from"
          ):
              ensure_frozen(Categorical([1, 2], label="c"))
          assert "add_mutable" in caplog.text
  
          with frozen_context.bypass():
              assert (
                  ensure_frozen(
                      Categorical([1, 2], label="a", default=2),
                      strict=False,
                  )
                  == 2
              )
              with pytest.raises(RuntimeError, match="context"):
                  ensure_frozen(
                      Categorical([1, 2], label="a"), retries=-1
                  )
  
file_path: nni/test/ut/sdk/mutable/test_frozen.py
imports: import pytest
  from nni.mutable import *
label_desc: Use image node_id 5 for calling a global function with example usage: test_ensure_frozen(caplog) without return types