def test_save_load_variable(self):
    file_path = os.path.join(self._output_dir, 'test_output_data.pkl')

    # Case 1: Nested dictionary.
    data = {'zz': 1, 'b': 234, 123: 'asdfa', 'dict': {'a': 123, 't': 123}}
    file_util.save_variable(file_path, data)
    actual_variable = file_util.load_variable(file_path)
    self.assertEqual(data, actual_variable)
    self.assertIsInstance(actual_variable, dict)

    # Case 2: 2-level nested dictionary.
    data = collections.defaultdict(
        lambda: collections.defaultdict(list))
    data['first']['A'] = [1, 2, 3]
    data['first']['B'] = [1, 2, 3]
    data['second']['B'] = [1, 2, 3]
    data['second']['C'] = [1, 2, 3]
    data['third']['C'] = [1, 2, 3]
    data['third']['D'] = [1, 2, 3]
    data['path'] = 'asdfas/asdf/asdfasdf/'
    file_util.save_variable(file_path, data)
    actual_variable = file_util.load_variable(file_path)
    self.assertEqual(data, actual_variable)
    self.assertIsInstance(actual_variable, dict)

    # Case 3: Large array. If the size is too large, the test will timeout.
    data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] * 10000
    file_util.save_variable(file_path, data)
    actual_variable = file_util.load_variable(file_path)
    self.assertListEqual(data, actual_variable)
    self.assertIsInstance(actual_variable, list)

    # Case 4: numpy array.
    data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] * 10
    data = np.array(data)
    file_util.save_variable(file_path, data)
    actual_variable = file_util.load_variable(file_path)
    np.testing.assert_array_equal(data, actual_variable)
    self.assertIsInstance(actual_variable, np.ndarray)

    # Case 5: A list of tuples.
    x = [1, 2, 3]
    y = ['a', 'b', 'c']
    data = zip(x, y)
    # Saving zip variable does not affect the iterative variable.
    file_util.save_variable(file_path, data)
    actual_variable = file_util.load_variable(file_path)
    # python2 treats `actual_variable` as a list, however, python3 treats it as
    # an iterative object.
    self.assertListEqual(list(actual_variable), list(data))

    # Case 6: In python2, the itertools.tee cannot be saved by cPickle. However,
    # in python3, it can be saved.
    x = [1, 2, 3]
    y = ['a', 'b', 'c']
    data = zip(x, y)
    data_tee, _ = itertools.tee(data)
    python_version = sys.version_info[0]
    try:
      file_util.save_variable(file_path, data_tee)
      pickle_save_correctly = True
    except cPickle.PicklingError:
      pickle_save_correctly = False
    self.assertTrue((pickle_save_correctly and python_version == 3) or
                    (not pickle_save_correctly and python_version == 2))