code: def test_optimize():
      def test_grayscale(optimize):
          im = Image.new("L", (1, 1), 0)
          filename = BytesIO()
          im.save(filename, "GIF", optimize=optimize)
          return len(filename.getvalue())
  
      def test_bilevel(optimize):
          im = Image.new("1", (1, 1), 0)
          test_file = BytesIO()
          im.save(test_file, "GIF", optimize=optimize)
          return len(test_file.getvalue())
  
      assert test_grayscale(0) == 799
      assert test_grayscale(1) == 43
      assert test_bilevel(0) == 799
      assert test_bilevel(1) == 799
  
imports: from io import BytesIO
  import pytest
  from PIL import GifImagePlugin, Image, ImageDraw, ImagePalette, features
  from .helper import assert_image_equal, assert_image_equal_tofile, assert_image_similar, hopper, is_pypy, netpbm_available
label_desc: Use image node_id 6 for calling a global function with example usage: test_optimize() and returns: len, len