Exemplo n.º 1
0
    def test_PrefixAliaser(self):
        # An aliaser that simply prefixes all keys
        pa = PrefixAliaser('prefix-')
        self.assertEqual(pa.alias('foo'), 'prefix-foo')
        self.assertEqual(pa.unalias('prefix-foo'), 'foo')

        err = self.expect_error(KeyError, pa.unalias, 'foo')
        expected = '"key \'foo\' does not match prefix \'prefix-\'"'
        self.assertTrue(str(err).find(expected) > -1)
Exemplo n.º 2
0
    def test_PrefixAliaser(self):
        # An aliaser that simply prefixes all keys
        pa = PrefixAliaser('prefix-')
        self.assertEqual(pa.alias('foo'), 'prefix-foo')
        self.assertEqual(pa.unalias('prefix-foo'), 'foo')

        err = self.expectError(KeyError, pa.unalias, 'foo')
        expected = '"key \'foo\' does not match prefix \'prefix-\'"'
        self.assertTrue(str(err).find(expected) > -1)
Exemplo n.º 3
0
    def test_AliaserChain(self):
        # A chain of aliasers
        aliaser = AliaserChain()

        pa = PrefixAliaser('prefix-')
        pa2 = PrefixAliaser('pre2-')

        aliaser.chain = [pa, pa2]
        self.assertEqual(aliaser.alias('foo'), 'pre2-prefix-foo')
        self.assertEqual(aliaser.unalias(aliaser.alias('foo')), 'foo')

        aliaser.chain = [pa2, pa]
        self.assertEqual(aliaser.unalias(aliaser.alias('foo')), 'foo')
Exemplo n.º 4
0
 class AliasDict(dict):
     aliaser = PrefixAliaser(prefix="pre-")
Exemplo n.º 5
0
 class FailDict(FakeDict):
     aliaser = PrefixAliaser(prefix="pre-")