def testInitEquivPairs(self): otherEp = utilitytypes.EquivalencePairs({1: 'foo', 2: 'bar'}) ep = utilitytypes.EquivalencePairs(otherEp) self.assertEqual(ep[1], 'foo') self.assertEqual(ep[2], 'bar') self.assertEqual(ep['foo'], 1) self.assertEqual(ep['bar'], 2)
def testOverwritePairs(self): ep = utilitytypes.EquivalencePairs({1: 'a', 2: 'b'}) self.assertEqual(ep[1], 'a') self.assertEqual(ep[2], 'b') self.assertEqual(ep['a'], 1) self.assertEqual(ep['b'], 2) ep[1] = 2 self.assertRaises(KeyError, self._getIndex, ep, 'a') self.assertRaises(KeyError, self._getIndex, ep, 'b') self.assertEqual(ep[1], 2) self.assertEqual(ep[2], 1)
def testInitDict(self): ep = utilitytypes.EquivalencePairs({1: 'foo', 2: 'bar'}) self.assertEqual(ep[1], 'foo') self.assertEqual(ep[2], 'bar') self.assertEqual(ep['foo'], 1) self.assertEqual(ep['bar'], 2)
def testInitPairs(self): ep = utilitytypes.EquivalencePairs(((1, 'foo'), (2, 'bar'))) self.assertEqual(ep[1], 'foo') self.assertEqual(ep[2], 'bar') self.assertEqual(ep['foo'], 1) self.assertEqual(ep['bar'], 2)