1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
# -*- coding: utf-8 -*-
"""
Test for simple escape/unescape routine
"""
import unittest
from keyring.util import escape
class EscapeTestCase(unittest.TestCase):
def check_escape_unescape(self, initial):
escaped = escape.escape(initial)
self.assertTrue(all(c in (escape.LEGAL_CHARS + '_') for c in escaped))
unescaped = escape.unescape(escaped)
self.assertEqual(initial, unescaped)
def test_escape_unescape(self):
self.check_escape_unescape("aaaa")
self.check_escape_unescape("aaaa bbbb cccc")
self.check_escape_unescape(u"Zażółć gęślą jaźń")
self.check_escape_unescape("(((P{{{{'''---; ;; '\"|%^")
def test_low_byte(self):
"""
Ensure that encoding low bytes (ordinal less than hex F) encode as
as three bytes to avoid ambiguity. For example '\n' (hex A) should
encode as '_0A' and not '_A', the latter of which
isn't matched by the inverse operation.
"""
self.check_escape_unescape('\n')
self.check_escape_unescape('\x000')
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(EscapeTestCase))
return suite
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
|