def test_to_dict_copies_value_structure(self):
     v = [1, 2, 3]
     mapping_in = {"m": {"w": v}}
     mapping_out = data_structures.to_dict(mapping_in)
     self.assertEqual(mapping_in, mapping_out)
     self.assertIsNot(mapping_in["m"]["w"], mapping_out["m"]["w"])
     v.append(4)
     self.assertNotEqual(mapping_in, mapping_out)
Esempio n. 2
0
 def test_to_dict(self, cls):
   mapping_in = cls(
       {f"a{i}": cls({f"b{j}": 0 for j in range(2)}) for i in range(10)})
   mapping_out = data_structures.to_dict(mapping_in)
   self.assertEqual(mapping_in, mapping_out)
   self.assertIs(type(mapping_out), dict)
   self.assertIsNot(mapping_in, mapping_out)
   for key in mapping_in:
     self.assertIs(type(mapping_out[key]), dict)
     self.assertIsNot(mapping_in[key], mapping_out[key])
Esempio n. 3
0
 def test_to_dict_recursively_changes_leaf_types(self):
   mapping_in = {"m": {"w": FlatMap(a=FlatMap(b=0))}}
   mapping_out = data_structures.to_dict(mapping_in)
   self.assertEqual(type(mapping_out["m"]["w"]), dict)
   self.assertEqual(type(mapping_out["m"]["w"]["a"]), dict)