class_docstr: Tests ensuring that when a dataset or samples in a dataset are modified,
  those changes are passed on the the database and can be seen in different
  scopes (or processes!).
class_docstr_tok: ["Tests","ensuring","that","when","a","dataset","or","samples","in","a","dataset","are","modified",",","those","changes","are","passed","on","the","the","database","and","can","be","seen","in","different","scopes","(","or","processes","!",")","."]
code: def test_modify_sample(self):
      dataset_name = self.test_set_field_create.__name__
  
      def create_dataset():
          dataset = fo.Dataset(dataset_name)
          dataset.add_sample_field("bool_field", fo.BooleanField)
          dataset.add_sample_field("list_field", fo.ListField)
          return dataset.add_sample(fo.Sample(filepath="test.png"))
  
      sample_id = create_dataset()
  
      # check unset defaults
  
      def check_field_defaults(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
  
          self.assertIs(sample.bool_field, None)
          self.assertEqual(sample.list_field, None)
  
      check_field_defaults(sample_id)
  
      # modify simple field (boolean)
  
      def modify_simple_field(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          sample.bool_field = True
          sample.save()
  
      def check_modify_simple_field(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          self.assertIs(sample.bool_field, True)
  
      modify_simple_field(sample_id)
      check_modify_simple_field(sample_id)
  
      # clear simple field (boolean)
  
      def clear_simple_field(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          del sample.bool_field
          sample.save()
  
      def check_clear_simple_field(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          self.assertIs(sample.bool_field, None)
  
      clear_simple_field(sample_id)
      check_clear_simple_field(sample_id)
  
      # modify complex field (list)
  
      def modify_list_set(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          sample.list_field = [True, False, True]
          sample.save()
  
      def check_modify_list_set(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          self.assertListEqual(sample.list_field, [True, False, True])
  
      modify_list_set(sample_id)
      check_modify_list_set(sample_id)
  
      def clear_complex_field(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          sample.list_field = None
          sample.save()
  
      def check_clear_complex_field(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          self.assertEqual(sample.list_field, None)
  
      clear_complex_field(sample_id)
      check_clear_complex_field(sample_id)
  
      def modify_list_set_again(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          sample.list_field = [51]
          sample.save()
  
      def check_modify_list_set_agin(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          self.assertListEqual(sample.list_field, [51])
  
      modify_list_set_again(sample_id)
      check_modify_list_set_agin(sample_id)
  
      def modify_list_extend(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          sample.list_field.extend(["fiftyone"])
          sample.save()
  
      def check_modify_list_extend(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          self.assertListEqual(sample.list_field, [51, "fiftyone"])
  
      modify_list_extend(sample_id)
      check_modify_list_extend(sample_id)
  
      def modify_list_pop(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          sample.list_field.pop(0)
          sample.save()
  
      def check_modify_list_pop(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          self.assertListEqual(sample.list_field, ["fiftyone"])
  
      modify_list_pop(sample_id)
      check_modify_list_pop(sample_id)
  
      def modify_list_iadd(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          sample.list_field += [52]
          sample.save()
  
      def check_modify_list_iadd(sample_id):
          dataset = fo.load_dataset(dataset_name)
          sample = dataset[sample_id]
          self.assertListEqual(sample.list_field, ["fiftyone", 52])
  
      modify_list_iadd(sample_id)
      check_modify_list_iadd(sample_id)
  
file_path: fiftyone/tests/unittests/synchronization_tests.py
imports: import os
  import unittest
  import fiftyone
  from decorators import drop_datasets
label_desc: Use image node_id 5 for calling the ScopedObjectsSynchronizationTests obj's underlying member method code with example usage: obj.test_modify_sample() and returns: dataset