def test_dict_to_idict(): """verify dicts can be converted to IDictionaries""" load_iron_python_test() from IronPythonTest import DictConversion class MyDict(dict): pass class KOld: pass class KNew(object): pass class KOldDerived(KOld): pass class KNewDerived(KNew): pass test_dicts = [ {}, {1:100}, {None:None}, {object:object}, {1:100, 2:200}, {1:100, 2:200, 3:300, 4:400}, MyDict.__dict__, KOld.__dict__, KNew.__dict__, KOldDerived.__dict__, KNewDerived.__dict__, ] for temp_dict in test_dicts: expected = list(temp_dict.keys()) + list(temp_dict.values()) expected.sort() to_idict = list(DictConversion.ToIDictionary(temp_dict)) to_idict.sort() AreEqual(to_idict, expected) to_idict = list(DictConversion.ToIDictionary(MyDict(temp_dict))) to_idict.sort() AreEqual(to_idict, expected)
def test_dict_to_idict(self): """verify dicts can be converted to IDictionaries""" self.load_iron_python_test() from IronPythonTest import DictConversion class MyDict(dict): pass class K(object): pass class KDerived(K): pass test_dicts = [ {}, { 1: 100 }, { None: None }, { object: object }, { 1: 100, 2: 200 }, { 1: 100, 2: 200, 3: 300, 4: 400 }, MyDict.__dict__, K.__dict__, KDerived.__dict__, ] for temp_dict in test_dicts: expected = list((key, temp_dict[key]) for key in temp_dict.keys()) expected.sort() to_idict = list(DictConversion.ToIDictionary(temp_dict)) to_idict.sort() self.assertEqual(to_idict, expected) to_idict = list(DictConversion.ToIDictionary(MyDict(temp_dict))) to_idict.sort() self.assertEqual(to_idict, expected)