code: def test_write(self):
      # Test for write operations on mapping
      p = self._empty_mapping()
      # Indexing
      for key, value in self.reference.items():
          p[key] = value
          self.assertEqual(p[key], value)
      for key in self.reference.keys():
          del p[key]
          self.assertRaises(KeyError, lambda: p[key])
      p = self._empty_mapping()
      # update
      p.update(self.reference)
      self.assertEqual(dict(p), self.reference)
      items = list(p.items())
      p = self._empty_mapping()
      p.update(items)
      self.assertEqual(dict(p), self.reference)
      d = self._full_mapping(self.reference)
      # setdefault
      key, value = next(iter(d.items()))
      knownkey, knownvalue = next(iter(self.other.items()))
      self.assertEqual(d.setdefault(key, knownvalue), value)
      self.assertEqual(d[key], value)
      self.assertEqual(d.setdefault(knownkey, knownvalue), knownvalue)
      self.assertEqual(d[knownkey], knownvalue)
      # pop
      self.assertEqual(d.pop(knownkey), knownvalue)
      self.assertNotIn(knownkey, d)
      self.assertRaises(KeyError, d.pop, knownkey)
      default = 909
      d[knownkey] = knownvalue
      self.assertEqual(d.pop(knownkey, default), knownvalue)
      self.assertNotIn(knownkey, d)
      self.assertEqual(d.pop(knownkey, default), default)
      # popitem
      key, value = d.popitem()
      self.assertNotIn(key, d)
      self.assertEqual(value, self.reference[key])
      p = self._empty_mapping()
      self.assertRaises(KeyError, p.popitem)
  
imports: import copy
  import gc
  import random
  import threading
  import unittest
  import torch
  from torch.testing._internal.common_utils import find_library_location, IS_FBCODE, IS_MACOS, IS_SANDCASTLE, IS_WINDOWS, run_tests, TestCase
  from torch.utils.weak import _WeakHashRef, WeakIdKeyDictionary
label_desc: Use image node_id 7 for calling the WeakKeyDictionaryScriptObjectTestCase obj's underlying member method code with example usage: obj.test_write() without return types