code: def test_filter_by_rule():
      labels = numpy.zeros((10, 20), int)
      labels[3:5, 4:9] = 1
      labels[7:9, 6:12] = 2
      labels[4:9, 14:18] = 3
      workspace, module = make_workspace({"MyObjects": labels})
      assert isinstance(
          module,
          cellprofiler.modules.filterobjects.FilterByObjectMeasurement,
      )
      m = workspace.measurements
      m.add_measurement(
          "MyObjects", "MyMeasurement", numpy.array([1.5, 2.3, 1.8])
      )
      rules_file_contents = (
          "IF (MyObjects_MyMeasurement > 2.0, [1.0,-1.0], [-1.0,1.0])\n"
      )
      rules_path = tempfile.mktemp()
      fd = open(rules_path, "wt")
      try:
          fd.write(rules_file_contents)
          fd.close()
          rules_dir, rules_file = os.path.split(rules_path)
          module.x_name.value = "MyObjects"
          module.mode.value = (
              cellprofiler.modules.filterobjects.MODE_RULES
          )
          module.rules_file_name.value = rules_file
          module.rules_directory.dir_choice = (
              cellprofiler_core.preferences.ABSOLUTE_FOLDER_NAME
          )
          module.rules_directory.custom_path = rules_dir
          module.y_name.value = "MyTargetObjects"
          module.run(workspace)
          target_objects = workspace.object_set.get_objects(
              "MyTargetObjects"
          )
          target_labels = target_objects.segmented
          assert numpy.all(target_labels[labels == 2] > 0)
          assert numpy.all(target_labels[labels != 2] == 0)
      finally:
          os.remove(rules_path)
  
imports: import contextlib
  import io
  import os
  import pickle
  import tempfile
  import numpy
  import pytest
  import cellprofiler_core.image
  import cellprofiler_core.measurement
  import cellprofiler_core.modules
  from cellprofiler_core.constants.measurement import FF_PARENT, FF_COUNT, FF_CHILDREN_COUNT, M_LOCATION_CENTER_X, M_LOCATION_CENTER_Y, M_LOCATION_CENTER_Z, M_NUMBER_OBJECT_NUMBER
  import cellprofiler.modules.filterobjects
  import cellprofiler_core.object
  import cellprofiler_core.pipeline
  import cellprofiler_core.preferences
  import cellprofiler_core.workspace
  import tests.frontend.modules
label_desc: Use image node_id 22 for calling a global function with example usage: test_filter_by_rule() without return types