code: def test_versions():
      fake_name = "_a_fake_package"
      fake_pkg = types.ModuleType(fake_name)
      assert "fake_pkg" not in sys.modules
      # Not inserted yet
      assert_bad(fake_name)
      try:
          sys.modules[fake_name] = fake_pkg
          # No __version__ yet
          assert_good(fake_name)  # With no version check
          assert_bad(fake_name, "1.0")
          # We can make an arbitrary callable to check version
          assert_good(fake_name, lambda pkg: True)
          # Now add a version
          fake_pkg.__version__ = "2.0"
          # We have fake_pkg > 1.0
          for min_ver in (
              None,
              "1.0",
              Version("1.0"),
              lambda pkg: True,
          ):
              assert_good(fake_name, min_ver)
          # We never have fake_pkg > 100.0
          for min_ver in ("100.0", Version("100.0"), lambda pkg: False):
              assert_bad(fake_name, min_ver)
          # Check error string for bad version
          pkg, _, _ = optional_package(fake_name, min_version="3.0")
          try:
              pkg.some_method
          except TripWireError as err:
              assert (
                  str(err)
                  == "These functions need _a_fake_package version >= 3.0"
              )
      finally:
          del sys.modules[fake_name]
  
file_path: nibabel/nibabel/tests/test_optpkg.py
imports: import builtins
  import sys
  import types
  from unittest import SkipTest, mock
  import pytest
  from packaging.version import Version
  from nibabel.optpkg import optional_package
  from nibabel.tripwire import TripWire, TripWireError
label_desc: Use image node_id 4 for calling a global function with example usage: test_versions() without return types