code: def test_compressionlevel():
      # Check default and set compression level
      with open(__file__, "rb") as fobj:
          my_self = fobj.read()
      # bzip2 needs a fairly large file to show differences in compression level
      many_selves = my_self * 50
      # Test we can set default compression at class level
  
      class MyOpener(Opener):
          default_compresslevel = 5
  
      with InTemporaryDirectory():
          for ext in ("gz", "bz2", "GZ", "gZ", "BZ2", "Bz2"):
              for opener, default_val in ((Opener, 1), (MyOpener, 5)):
                  sizes = {}
                  for compresslevel in ("default", 1, 5):
                      fname = "test." + ext
                      kwargs = {"mode": "wb"}
                      if compresslevel != "default":
                          kwargs["compresslevel"] = compresslevel
                      with opener(fname, **kwargs) as fobj:
                          fobj.write(many_selves)
                      with open(fname, "rb") as fobj:
                          my_selves_smaller = fobj.read()
                      sizes[compresslevel] = len(my_selves_smaller)
                  assert sizes["default"] == sizes[default_val]
                  assert sizes[1] > sizes[5]
  
imports: import contextlib
  import hashlib
  import os
  import time
  import unittest
  from gzip import GzipFile
  from io import BytesIO, UnsupportedOperation
  from unittest import mock
  import pytest
  from packaging.version import Version
  from ..deprecator import ExpiredDeprecationError
  from ..openers import HAVE_INDEXED_GZIP, BZ2File, DeterministicGzipFile, ImageOpener, Opener
  from ..optpkg import optional_package
  from ..tmpdirs import InTemporaryDirectory
label_desc: Use image node_id 6 for calling a global function with example usage: test_compressionlevel() without return types