예제 #1
0
    def test_es_hash(self):
        from _testcapi import getargs_es_hash
        self.assertEqual(getargs_es_hash('abc\xe9'), b'abc\xc3\xa9')
        self.assertEqual(getargs_es_hash('abc\xe9', 'latin1'), b'abc\xe9')
        self.assertRaises(UnicodeEncodeError, getargs_es_hash, 'abc\xe9',
                          'ascii')
        self.assertRaises(LookupError, getargs_es_hash, 'abc\xe9', 'spam')
        self.assertRaises(TypeError, getargs_es_hash, b'bytes', 'latin1')
        self.assertRaises(TypeError, getargs_es_hash, bytearray(b'bytearray'),
                          'latin1')
        self.assertRaises(TypeError, getargs_es_hash,
                          memoryview(b'memoryview'), 'latin1')
        self.assertRaises(TypeError, getargs_es_hash, None, 'latin1')
        self.assertEqual(getargs_es_hash('nul:\0', 'latin1'), b'nul:\0')

        buf = bytearray(b'x' * 8)
        self.assertEqual(getargs_es_hash('abc\xe9', 'latin1', buf), b'abc\xe9')
        self.assertEqual(buf, bytearray(b'abc\xe9\x00xxx'))
        buf = bytearray(b'x' * 5)
        self.assertEqual(getargs_es_hash('abc\xe9', 'latin1', buf), b'abc\xe9')
        self.assertEqual(buf, bytearray(b'abc\xe9\x00'))
        buf = bytearray(b'x' * 4)
        self.assertRaises(ValueError, getargs_es_hash, 'abc\xe9', 'latin1',
                          buf)
        self.assertEqual(buf, bytearray(b'x' * 4))
        buf = bytearray()
        self.assertRaises(ValueError, getargs_es_hash, 'abc\xe9', 'latin1',
                          buf)
예제 #2
0
    def test_es_hash(self):
        from _testcapi import getargs_es_hash
        self.assertEqual(getargs_es_hash('abc'), 'abc')
        self.assertEqual(getargs_es_hash(u'abc'), 'abc')
        self.assertEqual(getargs_es_hash(u'abc\xe9', 'latin1'), 'abc\xe9')
        self.assertRaises(UnicodeEncodeError, getargs_es_hash, u'abc\xe9',
                          'ascii')
        self.assertRaises(LookupError, getargs_es_hash, u'abc', 'spam')
        self.assertRaises(TypeError, getargs_es_hash, bytearray('bytearray'),
                          'latin1')
        self.assertRaises(TypeError, getargs_es_hash, memoryview('memoryview'),
                          'latin1')
        with test_support.check_py3k_warnings():
            self.assertEqual(getargs_es_hash(buffer('abc'), 'ascii'), 'abc')
            self.assertEqual(getargs_es_hash(buffer(u'abc'), 'ascii'), 'abc')
        self.assertRaises(TypeError, getargs_es_hash, None, 'latin1')
        self.assertEqual(getargs_es_hash('nul:\0', 'latin1'), 'nul:\0')
        self.assertEqual(getargs_es_hash(u'nul:\0', 'latin1'), 'nul:\0')

        buf = bytearray('x' * 8)
        self.assertEqual(getargs_es_hash(u'abc\xe9', 'latin1', buf), 'abc\xe9')
        self.assertEqual(buf, bytearray('abc\xe9\x00xxx'))
        buf = bytearray('x' * 5)
        self.assertEqual(getargs_es_hash(u'abc\xe9', 'latin1', buf), 'abc\xe9')
        self.assertEqual(buf, bytearray('abc\xe9\x00'))
        buf = bytearray('x' * 4)
        self.assertRaises(TypeError, getargs_es_hash, u'abc\xe9', 'latin1',
                          buf)
        self.assertEqual(buf, bytearray('x' * 4))
        buf = bytearray()
        self.assertRaises(TypeError, getargs_es_hash, u'abc\xe9', 'latin1',
                          buf)
예제 #3
0
    def test_es_hash(self):
        from _testcapi import getargs_es_hash
        self.assertEqual(getargs_es_hash('abc'), 'abc')
        self.assertEqual(getargs_es_hash(u'abc'), 'abc')
        self.assertEqual(getargs_es_hash(u'abc\xe9', 'latin1'), 'abc\xe9')
        self.assertRaises(UnicodeEncodeError, getargs_es_hash, u'abc\xe9', 'ascii')
        self.assertRaises(LookupError, getargs_es_hash, u'abc', 'spam')
        self.assertRaises(TypeError, getargs_es_hash,
                          bytearray('bytearray'), 'latin1')
        self.assertRaises(TypeError, getargs_es_hash,
                          memoryview('memoryview'), 'latin1')
        with test_support.check_py3k_warnings():
            self.assertEqual(getargs_es_hash(buffer('abc'), 'ascii'), 'abc')
            self.assertEqual(getargs_es_hash(buffer(u'abc'), 'ascii'), 'abc')
        self.assertRaises(TypeError, getargs_es_hash, None, 'latin1')
        self.assertEqual(getargs_es_hash('nul:\0', 'latin1'), 'nul:\0')
        self.assertEqual(getargs_es_hash(u'nul:\0', 'latin1'), 'nul:\0')

        buf = bytearray('x'*8)
        self.assertEqual(getargs_es_hash(u'abc\xe9', 'latin1', buf), 'abc\xe9')
        self.assertEqual(buf, bytearray('abc\xe9\x00xxx'))
        buf = bytearray('x'*5)
        self.assertEqual(getargs_es_hash(u'abc\xe9', 'latin1', buf), 'abc\xe9')
        self.assertEqual(buf, bytearray('abc\xe9\x00'))
        buf = bytearray('x'*4)
        self.assertRaises(TypeError, getargs_es_hash, u'abc\xe9', 'latin1', buf)
        self.assertEqual(buf, bytearray('x'*4))
        buf = bytearray()
        self.assertRaises(TypeError, getargs_es_hash, u'abc\xe9', 'latin1', buf)
예제 #4
0
    def test_es_hash(self):
        from _testcapi import getargs_es_hash
        self.assertEqual(getargs_es_hash('abc\xe9'), b'abc\xc3\xa9')
        self.assertEqual(getargs_es_hash('abc\xe9', 'latin1'), b'abc\xe9')
        self.assertRaises(UnicodeEncodeError, getargs_es_hash, 'abc\xe9', 'ascii')
        self.assertRaises(LookupError, getargs_es_hash, 'abc\xe9', 'spam')
        self.assertRaises(TypeError, getargs_es_hash, b'bytes', 'latin1')
        self.assertRaises(TypeError, getargs_es_hash, bytearray(b'bytearray'), 'latin1')
        self.assertRaises(TypeError, getargs_es_hash, memoryview(b'memoryview'), 'latin1')
        self.assertRaises(TypeError, getargs_es_hash, None, 'latin1')
        self.assertEqual(getargs_es_hash('nul:\0', 'latin1'), b'nul:\0')

        buf = bytearray(b'x'*8)
        self.assertEqual(getargs_es_hash('abc\xe9', 'latin1', buf), b'abc\xe9')
        self.assertEqual(buf, bytearray(b'abc\xe9\x00xxx'))
        buf = bytearray(b'x'*5)
        self.assertEqual(getargs_es_hash('abc\xe9', 'latin1', buf), b'abc\xe9')
        self.assertEqual(buf, bytearray(b'abc\xe9\x00'))
        buf = bytearray(b'x'*4)
        self.assertRaises(ValueError, getargs_es_hash, 'abc\xe9', 'latin1', buf)
        self.assertEqual(buf, bytearray(b'x'*4))
        buf = bytearray()
        self.assertRaises(ValueError, getargs_es_hash, 'abc\xe9', 'latin1', buf)
예제 #5
0
    def test_es_hash(self):
        from _testcapi import getargs_es_hash

        self.assertEqual(getargs_es_hash("abc\xe9"), b"abc\xc3\xa9")
        self.assertEqual(getargs_es_hash("abc\xe9", "latin1"), b"abc\xe9")
        self.assertRaises(UnicodeEncodeError, getargs_es_hash, "abc\xe9", "ascii")
        self.assertRaises(LookupError, getargs_es_hash, "abc\xe9", "spam")
        self.assertRaises(TypeError, getargs_es_hash, b"bytes", "latin1")
        self.assertRaises(TypeError, getargs_es_hash, bytearray(b"bytearray"), "latin1")
        self.assertRaises(TypeError, getargs_es_hash, memoryview(b"memoryview"), "latin1")
        self.assertRaises(TypeError, getargs_es_hash, None, "latin1")
        self.assertEqual(getargs_es_hash("nul:\0", "latin1"), b"nul:\0")

        buf = bytearray(b"x" * 8)
        self.assertEqual(getargs_es_hash("abc\xe9", "latin1", buf), b"abc\xe9")
        self.assertEqual(buf, bytearray(b"abc\xe9\x00xxx"))
        buf = bytearray(b"x" * 5)
        self.assertEqual(getargs_es_hash("abc\xe9", "latin1", buf), b"abc\xe9")
        self.assertEqual(buf, bytearray(b"abc\xe9\x00"))
        buf = bytearray(b"x" * 4)
        self.assertRaises(TypeError, getargs_es_hash, "abc\xe9", "latin1", buf)
        self.assertEqual(buf, bytearray(b"x" * 4))
        buf = bytearray()
        self.assertRaises(TypeError, getargs_es_hash, "abc\xe9", "latin1", buf)