code: def test_monitor_gets_expected_metric_values(self):
      patchers = [
          mock.patch.object(
              resources, "_get_host_name", return_value="hostname"
          ),
          mock.patch.object(
              resources, "_get_cpu_count", return_value=3
          ),
          mock.patch.object(
              resources, "_get_cpu_frequency", return_value=2312.4
          ),
          mock.patch.object(
              resources, "_get_total_memory", return_value=1234
          ),
          mock.patch.object(
              resources.resource,
              "getrusage",
              return_value=mock.Mock(
                  ru_utime=1.0,
                  ru_stime=2.0,
                  ru_maxrss=3 * 1024,  # 3 Megabytes
              ),
          ),
      ]
  
      process_mock = mock.Mock()
      process_mock.io_counters.return_value = mock.Mock(
          read_bytes=12, write_bytes=34
      )
      patchers.append(
          mock.patch.object(
              resources.psutil, "Process", return_value=process_mock
          )
      )
  
      with contextlib2.ExitStack() as stack:
          for ctx in patchers:
              stack.enter_context(ctx)
          with resources.ResourceMonitor() as monitor:
              metrics = monitor.metrics()
  
              # Environment metrics; all mocked out.
              self.assertEqual(metrics.host_name, "hostname")
              self.assertEqual(metrics.physical_core_count, 3)
              self.assertEqual(metrics.cpu_frequency_mhz, 2312.4)
              self.assertEqual(metrics.total_memory_mb, 1234)
  
              # Runtime metrics; they are all mocked out.
              self.assertEqual(metrics.cpu_user_time_seconds, 1.0)
              self.assertEqual(metrics.cpu_system_time_seconds, 2.0)
              self.assertEqual(metrics.memory_peak_rss_mb, 3)
              self.assertEqual(metrics.read_bytes, 12)
              self.assertEqual(metrics.write_bytes, 34)
  
file_path: deepvariant/deepvariant/resources_test.py
imports: import resource
  from unittest import mock
  from absl.testing import absltest
  import contextlib2
  from deepvariant import resources
label_desc: Use image node_id 2 for calling the ResourcesTest obj's underlying member method code with example usage: obj.test_monitor_gets_expected_metric_values() without return types