old_contents: from os import path
  import json
  import persistent_dict
  import shutil
  import tempfile
  import unittest
  
  class TestPersistentDict(unittest.TestCase):
  
    def setUp(self):
      self._test_dir = tempfile.mkdtemp()
  
    def tearDown(self):
      shutil.rmtree(self._test_dir)
  
    def test_non_existing_file(self):
      filename = path.join(self._test_dir, 'not_existant_file')
      pdict = persistent_dict.PersistentDict(filename)
      self.assertEqual(pdict, {})
  
    def test_load_from_existing_file(self):
      filename = path.join(self._test_dir, 'my_file')
      with open(filename, 'w') as handle:
        handle.write('{"a": 10}')
      pdict = persistent_dict.PersistentDict(filename)
      self.assertEqual(pdict, {'a': 10})
  
    def test_automatically_save_added_fields(self):
      filename = path.join(self._test_dir, 'new_file')
      pdict = persistent_dict.PersistentDict(filename)
      pdict['a'] = 10
      self.assertEqual(json.load(open(filename)), {'a': 10})
  
  
    def test_automatically_save_deleted_fields(self):
      filename = path.join(self._test_dir, 'my_file')
      with open(filename, 'w') as handle:
        handle.write('{"a": 10, "b": 20}')
      pdict = persistent_dict.PersistentDict(filename)
      del pdict['a']
      self.assertEqual(json.load(open(filename)), {'b': 20})
  
  if __name__ == '__main__':
    unittest.main()
  
new_contents: from os import path
  import json
  from parameterized import parameterized
  import persistent_dict
  import shutil
  import tempfile
  import unittest
  
  
  class TestPersistentDict(unittest.TestCase):
  
    def setUp(self):
      self._test_dir = tempfile.mkdtemp()
  
    def tearDown(self):
      shutil.rmtree(self._test_dir)
  
    def test_non_existing_file(self):
      filename = path.join(self._test_dir, 'not_existant_file')
      pdict = persistent_dict.PersistentDict(filename)
      self.assertEqual(pdict, {})
  
    def test_file_not_created_unless_needed(self):
      filename = path.join(self._test_dir, 'not_existant_file')
      pdict = persistent_dict.PersistentDict(filename)
      self.assertFalse(path.isfile(filename))
  
      pdict.get('key', 123)
      self.assertFalse(path.isfile(filename))
  
      pdict['key'] = 123
      self.assertTrue(path.isfile(filename))
  
    def test_load_from_existing_file(self):
      filename = path.join(self._test_dir, 'my_file')
      with open(filename, 'w') as handle:
        handle.write('{"a": 10}')
      pdict = persistent_dict.PersistentDict(filename)
      self.assertEqual(pdict, {'a': 10})
  
    @parameterized.expand([
      ('int', 10, 10),
      ('str', 'foo', 'foo'),
      ('str-utf-8', '\xc3\xaf', u'\xef'),
      ('Unicode', u'\xef', u'\xef'),
      ('list', [1, 2], [1, 2]),
      ('tuple', (1, 2), [1, 2]),
      ('dict', {'foo': 1, 'bar': 2}, {'foo': 1, 'bar': 2}),
      ('complex_list', [1, {'foo': (3, 4)}], [1, {'foo': [3, 4]}]),
      ('complex_dict', {'foo': 1, 'bar': [2, 3]}, {'foo': 1, 'bar': [2, 3]})])
    def test_automatically_save_added_fields(self, test_name, value, result):
      filename = path.join(self._test_dir, 'new_file')
      pdict = persistent_dict.PersistentDict(filename)
      pdict['a'] = value
      self.assertEqual(json.load(open(filename)), {'a': result})
  
    def test_automatically_save_modified_sub_fields(self):
      filename = path.join(self._test_dir, 'new_file')
      pdict = persistent_dict.PersistentDict(filename)
      pdict['a'] = {'foo': 1, 'bar': [2, 3]}
      pdict['a']['bar'][1] = 4
      del pdict['a']['foo']
      self.assertEqual(json.load(open(filename)), {'a': {'bar': [2, 4]}})
  
    def test_automatically_save_deleted_fields(self):
      filename = path.join(self._test_dir, 'my_file')
      with open(filename, 'w') as handle:
        handle.write('{"a": 10, "b": 20}')
      pdict = persistent_dict.PersistentDict(filename)
      del pdict['a']
      self.assertEqual(json.load(open(filename)), {'b': 20})
  
  
  if __name__ == '__main__':
    unittest.main()
  
subject: Add unit tests in persisten_dict_test.py