docstr: Stats requests are returned in OpenMetrics protobuf format
  if the request's Content-Type header is protobuf.
docstr_tok: ["Stats","requests","are","returned","in","OpenMetrics","protobuf","format","if","the","request","'s","Content-Type","header","is","protobuf","."]
code: def test_protobuf_stats(self):
      """Stats requests are returned in OpenMetrics protobuf format
      if the request's Content-Type header is protobuf.
      """
      self.mock_stats = [
          CacheStat(
              category_name="st.singleton",
              cache_name="foo",
              byte_length=128,
          ),
          CacheStat(
              category_name="st.memo",
              cache_name="bar",
              byte_length=256,
          ),
      ]
  
      # Requests can have multiple Accept headers. Only one of them needs
      # to specify protobuf in order to get back protobuf.
      headers = HTTPHeaders()
      headers.add("Accept", "application/openmetrics-text")
      headers.add("Accept", "application/x-protobuf")
      headers.add("Accept", "text/html")
  
      response = self.fetch("/_stcore/metrics", headers=headers)
      self.assertEqual(200, response.code)
      self.assertEqual(
          "application/x-protobuf", response.headers.get("Content-Type")
      )
  
      metric_set = MetricSetProto()
      metric_set.ParseFromString(response.body)
  
      expected = {
          "metricFamilies": [
              {
                  "name": "cache_memory_bytes",
                  "type": "GAUGE",
                  "unit": "bytes",
                  "help": "Total memory consumed by a cache.",
                  "metrics": [
                      {
                          "labels": [
                              {
                                  "name": "cache_type",
                                  "value": "st.singleton",
                              },
                              {"name": "cache", "value": "foo"},
                          ],
                          "metricPoints": [
                              {"gaugeValue": {"intValue": "128"}}
                          ],
                      },
                      {
                          "labels": [
                              {
                                  "name": "cache_type",
                                  "value": "st.memo",
                              },
                              {"name": "cache", "value": "bar"},
                          ],
                          "metricPoints": [
                              {"gaugeValue": {"intValue": "256"}}
                          ],
                      },
                  ],
              }
          ]
      }
  
      self.assertEqual(expected, MessageToDict(metric_set))
  
file_path: streamlit/lib/tests/streamlit/web/server/stats_handler_test.py
imports: from unittest.mock import MagicMock
  import tornado.testing
  import tornado.web
  from google.protobuf.json_format import MessageToDict
  from tornado.httputil import HTTPHeaders
  from streamlit.proto.openmetrics_data_model_pb2 import MetricSet
  from streamlit.runtime.stats import CacheStat
  from streamlit.web.server.server import METRIC_ENDPOINT
  from streamlit.web.server.stats_request_handler import StatsRequestHandler
label_desc: Use image node_id 6 for calling the StatsHandlerTest obj's underlying member method code with example usage: obj.test_protobuf_stats() without return types