mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Make the sqlite tests pass.
This commit is contained in:
parent
bd4a63e091
commit
6d21456137
7 changed files with 28 additions and 31 deletions
|
|
@ -139,32 +139,32 @@ class TextFactoryTests(unittest.TestCase):
|
|||
self.con = sqlite.connect(":memory:")
|
||||
|
||||
def CheckUnicode(self):
|
||||
austria = str("Österreich", "latin1")
|
||||
austria = "Österreich"
|
||||
row = self.con.execute("select ?", (austria,)).fetchone()
|
||||
self.failUnless(type(row[0]) == str, "type of row[0] must be unicode")
|
||||
|
||||
def CheckString(self):
|
||||
self.con.text_factory = str
|
||||
austria = str("Österreich", "latin1")
|
||||
self.con.text_factory = bytes
|
||||
austria = "Österreich"
|
||||
row = self.con.execute("select ?", (austria,)).fetchone()
|
||||
self.failUnless(type(row[0]) == str, "type of row[0] must be str")
|
||||
self.failUnless(type(row[0]) == bytes, "type of row[0] must be bytes")
|
||||
self.failUnless(row[0] == austria.encode("utf-8"), "column must equal original data in UTF-8")
|
||||
|
||||
def CheckCustom(self):
|
||||
self.con.text_factory = lambda x: str(x, "utf-8", "ignore")
|
||||
austria = str("Österreich", "latin1")
|
||||
row = self.con.execute("select ?", (austria.encode("latin1"),)).fetchone()
|
||||
austria = "Österreich"
|
||||
row = self.con.execute("select ?", (austria,)).fetchone()
|
||||
self.failUnless(type(row[0]) == str, "type of row[0] must be unicode")
|
||||
self.failUnless(row[0].endswith("reich"), "column must contain original data")
|
||||
|
||||
def CheckOptimizedUnicode(self):
|
||||
self.con.text_factory = sqlite.OptimizedUnicode
|
||||
austria = str("Österreich", "latin1")
|
||||
germany = str("Deutchland")
|
||||
austria = "Österreich"
|
||||
germany = "Deutchland"
|
||||
a_row = self.con.execute("select ?", (austria,)).fetchone()
|
||||
d_row = self.con.execute("select ?", (germany,)).fetchone()
|
||||
self.failUnless(type(a_row[0]) == str, "type of non-ASCII row must be unicode")
|
||||
self.failUnless(type(d_row[0]) == str, "type of ASCII-only row must be str")
|
||||
self.failUnless(type(d_row[0]) == str8, "type of ASCII-only row must be str8")
|
||||
|
||||
def tearDown(self):
|
||||
self.con.close()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue