code: def com_google_fonts_check_metadata_os2_weightclass(ttFont,
                                                      font_metadata):
    
    # Weight name to value mapping:
    GF_API_WEIGHT_NAMES = {250: "Thin",
                           275: "ExtraLight",
                           300: "Light",
                           400: "Regular",
                           500: "Medium",
                           600: "SemiBold",
                           700: "Bold",
                           800: "ExtraBold",
                           900: "Black"}
    CSS_WEIGHT_NAMES = {
      100: "Thin",
      200: "ExtraLight",
      300: "Light",
      400: "Regular",
      500: "Medium",
      600: "SemiBold",
      700: "Bold",
      800: "ExtraBold",
      900: "Black"
    }
    gf_weight = GF_API_WEIGHT_NAMES.get(ttFont["OS/2"].usWeightClass,
                                        "bad Google Fonts API weight value")
    css_weight = CSS_WEIGHT_NAMES.get(font_metadata.weight,
                                      "bad CSS weight value")
    if gf_weight != css_weight:
      yield FAIL, ("OS/2 usWeightClass ({}:\"{}\") does not match"
                   " weight specified at METADATA.pb ({}:\"{}\")."
                   "").format(ttFont["OS/2"].usWeightClass,
                              gf_weight,
                              font_metadata.weight,
                              css_weight)
    else:
      yield PASS, ("OS/2 usWeightClass matches"
                   " weight specified at METADATA.pb")
docs: Checking OS/2 usWeightClass matches weight specified at METADATA.pb.