'Test that L{KeyFlattener.flatKey} returns the expected keys for format
fields.'

def test_keyFlattening(self):

    def keyFromFormat(format):
        for (literalText, fieldName, formatSpec, conversion) in aFormatter.parse(format):
            return KeyFlattener().flatKey(fieldName, formatSpec, conversion)
    try:
        self.assertEqual(keyFromFormat('{}'), '!:')
    except ValueError:
        raise
    self.assertEqual(keyFromFormat('{foo}'), 'foo!:')
    self.assertEqual(keyFromFormat('{foo!s}'), 'foo!s:')
    self.assertEqual(keyFromFormat('{foo!r}'), 'foo!r:')
    self.assertEqual(keyFromFormat('{foo:%s}'), 'foo!:%s')
    self.assertEqual(keyFromFormat('{foo:!}'), 'foo!:!')
    self.assertEqual(keyFromFormat('{foo::}'), 'foo!::')
    self.assertEqual(keyFromFormat('{foo!s:%s}'), 'foo!s:%s')
    self.assertEqual(keyFromFormat('{foo!s:!}'), 'foo!s:!')
    self.assertEqual(keyFromFormat('{foo!s::}'), 'foo!s::')
    [keyPlusLiteral] = aFormatter.parse('{x}')
    key = keyPlusLiteral[1:]
    sameFlattener = KeyFlattener()
    self.assertEqual(sameFlattener.flatKey(*key), 'x!:')
    self.assertEqual(sameFlattener.flatKey(*key), 'x!:/2')
