def test_cls(self): x = {"a": "A"} y = mappify(x) self.assertEqual(x, y) self.assertTrue(x is y) x["a"] = "B" self.assertEqual(x, y) x = {"a": "A"} y = mappify(x, cls=None) self.assertEqual(x, y) self.assertTrue(x is y) x["a"] = "B" self.assertEqual(x, y) class subdict(dict): pass x = {"a": "A"} y = mappify(x, cls=subdict) self.assertEqual(x, y) self.assertFalse(x is y) x["a"] = "B" self.assertNotEqual(x, y) x = {"a": "A"} y = mappify(x, cls=lambda x: defaultdict(list, x)) self.assertEqual(x, y) self.assertFalse(x is y) x["a"] = "B" self.assertNotEqual(x, y)
def test_cls(self): x = {'a': 'A'} y = mappify(x) assert x == y assert x is y x['a'] = 'B' assert x == y x = {'a': 'A'} y = mappify(x, cls=None) assert x == y assert x is y x['a'] = 'B' assert x == y class subdict(dict): pass x = {'a': 'A'} y = mappify(x, cls=subdict) assert isinstance(y, subdict) assert x == y assert x is not y x['a'] = 'B' assert x != y x = {'a': 'A'} y = mappify(x, cls=lambda x: defaultdict(list, x)) assert isinstance(y, defaultdict) assert x == y assert x is not y x['a'] = 'B' assert x != y
def test_ordered_dict(self): try: from collections import OrderedDict except ImportError: pass else: self.assertEqual({}, mappify(OrderedDict())) self.assertEqual({"a": "A"}, mappify(OrderedDict({"a": "A"})))
def test_ordered_dict(self): try: from collections import OrderedDict except ImportError: pass else: assert {} == mappify(OrderedDict()) assert {'a': 'A'} == mappify(OrderedDict({'a': 'A'}))
def test_default(self): self.assertEqual({"a": None}, mappify(["a"], default=None)) self.assertEqual({"a": None, "b": None}, mappify(["a", "b"], default=None)) self.assertEqual({"a": "XXX"}, mappify(["a"], default="XXX")) self.assertEqual({"a": "XXX", "b": "XXX"}, mappify(["a", "b"], default="XXX"))
def test_dict_identity(self): x = {"a": "A"} y = mappify(x) self.assertEqual(x, y) self.assertTrue(x is y) x["a"] = "B" self.assertEqual(x, y) class subdict(dict): pass x = subdict(a="B") y = mappify(x) self.assertEqual(x, y) self.assertTrue(x is y) x["a"] = "B" self.assertEqual(x, y) x = subdict(a="B") y = mappify(x, cls=dict) self.assertEqual(x, y) self.assertTrue(x is y) x["a"] = "B" self.assertEqual(x, y)
def test_dict_identity(self): x = {'a': 'A'} y = mappify(x) assert x == y assert x is y x['a'] = 'B' assert x == y class subdict(dict): pass x = subdict(a='B') y = mappify(x) assert x == y assert x is y x['a'] = 'B' assert x == y x = subdict(a='B') y = mappify(x, cls=dict) assert x == y assert x is y x['a'] = 'B' assert x == y
def test_frozenset(self): self.assertEqual({}, mappify(frozenset())) self.assertEqual({"a": True}, mappify(frozenset("a"))) self.assertEqual({"a": True, "b": True}, mappify(frozenset(["a", "b"])))
def test_list(self): assert {} == mappify([]) assert {'a': True} == mappify(['a']) assert {'a': True, 'b': True} == mappify(['a', 'b'])
def test_dict(self): assert {} == mappify({}) assert {'a': 'A'} == mappify({'a': 'A'}) assert {'a': 'A', 'b': 'B'} == mappify({'a': 'A', 'b': 'B'})
def test_string(self): assert {'': True} == mappify('') assert {'a': True} == mappify('a') assert {'ab': True} == mappify('ab')
def test_tuple(self): assert {} == mappify(tuple()) assert {'a': True} == mappify(tuple('a')) assert {'a': True, 'b': True} == mappify(tuple(['a', 'b']))
def test_set(self): assert {} == mappify(set()) assert {'a': True} == mappify(set('a')) assert {'a': True, 'b': True} == mappify(set(['a', 'b']))
def test_string(self): self.assertEqual({"": True}, mappify("")) self.assertEqual({"a": True}, mappify("a")) self.assertEqual({"ab": True}, mappify("ab"))
def test_tuple(self): self.assertEqual({}, mappify(tuple())) self.assertEqual({"a": True}, mappify(tuple("a"))) self.assertEqual({"a": True, "b": True}, mappify(tuple(["a", "b"])))
def test_list(self): self.assertEqual({}, mappify([])) self.assertEqual({"a": True}, mappify(["a"])) self.assertEqual({"a": True, "b": True}, mappify(["a", "b"]))
def test_dict(self): self.assertEqual({}, mappify({})) self.assertEqual({"a": "A"}, mappify({"a": "A"})) self.assertEqual({"a": "A", "b": "B"}, mappify({"a": "A", "b": "B"}))
def test_frozenset(self): assert {} == mappify(frozenset()) assert {'a': True} == mappify(frozenset('a')) assert {'a': True, 'b': True}, mappify(frozenset(['a', 'b']))
def test_default(self): assert {'a': None} == mappify(['a'], default=None) assert {'a': None, 'b': None} == mappify(['a', 'b'], default=None) assert {'a': 'XXX'} == mappify(['a'], default='XXX') assert {'a': 'XXX', 'b': 'XXX'} == mappify(['a', 'b'], default='XXX')