code: def test_filter_by_3class_rule():
      f = "_".join(("Image", image_measurement_name(0)))
      rules_file_contents = (
          "IF (%(f)s > 2.0, [1.0,-1.0,-1.0], [-0.5,0.5,0.5])\n"
          "IF (%(f)s > 1.6, [0.5,0.5,-0.5], [-1.0,-1.0,1.0])\n"
      ) % locals()
      measurement_values = [1.5, 2.3, 1.8]
      expected_classes = ["3", "1", "2"]
      rules_path = tempfile.mktemp()
      rules_dir, rules_file = os.path.split(rules_path)
      fd = open(rules_path, "wt")
      fd.write(rules_file_contents)
      fd.close()
      try:
          for rules_classes in (
              ["1"],
              ["2"],
              ["3"],
              ["1", "2"],
              ["1", "3"],
              ["2", "3"],
          ):
              for expected_class, measurement_value in zip(
                  expected_classes, measurement_values
              ):
                  module, workspace = make_workspace(
                      [measurement_value], []
                  )
                  flag = module.flags[0]
                  assert isinstance(
                      flag, cellprofiler_core.setting.SettingsGroup
                  )
                  flag.wants_skip.value = False
                  measurement = flag.measurement_settings[0]
                  assert isinstance(
                      measurement,
                      cellprofiler_core.setting.SettingsGroup,
                  )
                  measurement.source_choice.value = (
                      cellprofiler.modules.flagimage.S_RULES
                  )
                  measurement.rules_file_name.value = rules_file
                  measurement.rules_directory.dir_choice = (
                      cellprofiler_core.preferences.ABSOLUTE_FOLDER_NAME
                  )
                  measurement.rules_directory.custom_path = rules_dir
                  measurement.rules_class.set_value(rules_classes)
  
                  m = workspace.measurements
                  assert isinstance(
                      m, cellprofiler_core.measurement.Measurements
                  )
                  module.run(workspace)
                  assert MEASUREMENT_NAME in m.get_feature_names(
                      "Image"
                  )
                  value = m.get_current_image_measurement(
                      MEASUREMENT_NAME
                  )
                  expected_value = (
                      1 if expected_class in rules_classes else 0
                  )
                  assert value == expected_value
      finally:
          os.remove(rules_path)
  
imports: import contextlib
  import os
  import tempfile
  import numpy
  import pytest
  import six.moves
  from cellprofiler_core.constants.measurement import COLTYPE_INTEGER
  from cellprofiler_core.constants.workspace import DISPOSITION_CONTINUE, DISPOSITION_SKIP
  import tests.frontend.modules
  import cellprofiler_core.image
  import cellprofiler_core.measurement
  import cellprofiler.modules.flagimage
  import cellprofiler_core.object
  import cellprofiler_core.pipeline
  import cellprofiler_core.preferences
  import cellprofiler_core.setting
  import cellprofiler_core.workspace
  from .None import test_filterobjects
label_desc: Use image node_id 22 for calling a global function with example usage: test_filter_by_3class_rule() without return types