docstr: Tests that the tensorboard writer calls SummaryWriter with the model
  iff is_primary() is True.
docstr_tok: ["Tests","that","the","tensorboard","writer","calls","SummaryWriter","with","the","model","iff","is_primary","(",")","is","True","."]
code: def test_writer(self, mock_is_primary_func: mock.MagicMock) -> None:
      """
      Tests that the tensorboard writer calls SummaryWriter with the model
      iff is_primary() is True.
      """
      mock_summary_writer = mock.create_autospec(
          SummaryWriter, instance=True
      )
  
      task = get_test_classy_task()
      task.prepare()
  
      for primary in [False, True]:
          mock_is_primary_func.return_value = primary
          model_configs = get_test_model_configs()
  
          for model_config in model_configs:
              model = build_model(model_config)
              task.base_model = model
  
              # create a model tensorboard hook
              model_tensorboard_hook = ModelTensorboardHook(
                  mock_summary_writer
              )
  
              model_tensorboard_hook.on_start(task)
  
              if primary:
                  # SummaryWriter should have been init-ed with the correct
                  # add_graph should be called once with model as the first arg
                  mock_summary_writer.add_graph.assert_called_once()
                  self.assertEqual(
                      mock_summary_writer.add_graph.call_args[0][0],
                      model,
                  )
              else:
                  # add_graph shouldn't be called since is_primary() is False
                  mock_summary_writer.add_graph.assert_not_called()
              mock_summary_writer.reset_mock()
  
file_path: ClassyVision/test/manual/hooks_model_tensorboard_hook_test.py
imports: import unittest
  import unittest.mock
  from classy_vision.hooks import ModelTensorboardHook
  from classy_vision.models import build_model
  from test.generic.config_utils import get_test_classy_task, get_test_model_configs
  from test.generic.hook_test_utils import HookTestBase
  from torch.utils.tensorboard import SummaryWriter
label_desc: Use image node_id 2 for calling the TestModelTensorboardHook obj's underlying member method code with example usage: obj.test_writer(mock_is_primary_func) without return types