code: def test_discrete_color_palettes():
      def _assert_all_colors(colors, n, m=0):
          """
          Make sure the first n elements of colors
          are rgb hex strings. And that the last
          m elements are None
          """
          assert len(colors) == n + m
          assert all(c.startswith("#") for c in colors[:n])
          if m > 0:
              assert all(c is None for c in colors[-m:])
  
      sc = scale_color
  
      s = sc.scale_color_hue()
      colors = s.palette(5)
      _assert_all_colors(colors, 5)
  
      s = sc.scale_color_grey()
      colors = s.palette(5)
      _assert_all_colors(colors, 5)
  
      # sequential palettes have a maximum of 9 colors
      s = sc.scale_color_brewer(type="seq")
      colors = s.palette(5)
      _assert_all_colors(colors, 5)
  
      s = sc.scale_color_brewer(type="seq")
      colors = s.palette(9)
      _assert_all_colors(colors, 9)
  
      s = sc.scale_color_brewer(type="seq")
      with pytest.warns(UserWarning):  # upstream warning
          colors = s.palette(15)
      _assert_all_colors(colors, 9, 6)
  
      # diverging palettes have a maximum of 11 colors
      s = sc.scale_color_brewer(type="div")
      colors = s.palette(5)
      _assert_all_colors(colors, 5)
  
      s = sc.scale_color_brewer(type="div")
      colors = s.palette(11)
      _assert_all_colors(colors, 11)
  
      s = sc.scale_color_brewer(type="div")
      with pytest.warns(UserWarning):  # upstream warning
          colors = s.palette(21)
      _assert_all_colors(colors, 11, 10)
  
      # qualitative have varying maximum colors
      s = sc.scale_color_brewer(type="qual")
      colors = s.palette(5)
      _assert_all_colors(colors, 5)
  
      s = sc.scale_color_brewer(type="qual", palette="Accent")
      with pytest.warns(UserWarning):  # upstream warning
          colors = s.palette(12)
      _assert_all_colors(colors, 8, 4)
  
      s = sc.scale_color_brewer(type="qual", palette="Set3")
      with pytest.warns(UserWarning):  # upstream warning
          colors = s.palette(15)
      _assert_all_colors(colors, 12, 3)
  
imports: import warnings
  from datetime import datetime
  import numpy
  import numpy.testing
  import pandas
  import pytest
  import plotnine
  from plotnine import aes, annotate, element_text, expand_limits, facet_wrap, geom_bar, geom_col, geom_point, ggplot, lims, theme
  from plotnine.exceptions import PlotnineError, PlotnineWarning
  from plotnine.scales import scale_color, scale_color_manual, scale_identity, scale_manual, scale_xy
  from plotnine.scales.scale_alpha import scale_alpha_continuous, scale_alpha_discrete
  from plotnine.scales.scale_linetype import scale_linetype_continuous, scale_linetype_discrete
  from plotnine.scales.scale_manual import _scale_manual
  from plotnine.scales.scale_shape import scale_shape_continuous, scale_shape_discrete
  from plotnine.scales.scale_size import scale_size_area, scale_size_continuous, scale_size_discrete, scale_size_radius
  from plotnine.scales.scale_xy import scale_x_continuous, scale_x_discrete, scale_x_log10, scale_y_continuous
  from plotnine.scales.scales import make_scale
label_desc: Use image node_id 1 for calling a global function with example usage: test_discrete_color_palettes() without return types