Changeset: 03fee8706d03 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=03fee8706d03
Added Files:
clients/python2/test/test_pythonize.py
clients/python3/test/test_pythonize.py
Modified Files:
clients/python2/monetdb/mapi.py
clients/python2/monetdb/sql/cursors.py
clients/python2/monetdb/sql/pythonize.py
clients/python2/test/runtests.py
clients/python3/monetdb/mapi.py
clients/python3/monetdb/sql/connections.py
clients/python3/monetdb/sql/cursors.py
clients/python3/monetdb/sql/pythonize.py
clients/python3/test/runtests.py
sql/test/mapi/Tests/python2_test_monetdb_sql.stable.err
sql/test/mapi/Tests/python3_test_monetdb_sql.stable.err
Branch: default
Log Message:
Merge with Feb2013 branch.
diffs (154 lines):
diff --git a/clients/python2/monetdb/sql/pythonize.py
b/clients/python2/monetdb/sql/pythonize.py
--- a/clients/python2/monetdb/sql/pythonize.py
+++ b/clients/python2/monetdb/sql/pythonize.py
@@ -119,7 +119,7 @@ def convert(data, type_code):
def Binary(data):
"""returns binary encoding of data"""
- return ''.join([hex(ord(i))[2:] for i in data]).upper()
+ return ''.join(["%02X" % ord(i) for i in data])
def DateFromTicks(ticks):
"""Convert ticks to python Date"""
diff --git a/clients/python2/test/runtests.py b/clients/python2/test/runtests.py
--- a/clients/python2/test/runtests.py
+++ b/clients/python2/test/runtests.py
@@ -36,6 +36,7 @@ except ImportError:
import capabilities
import dbapi20
+import test_pythonize
warnings.filterwarnings('error')
@@ -93,6 +94,7 @@ if __name__ == '__main__':
suites = [
Test_Capabilities,
Test_DBAPI20,
+ test_pythonize.TestPythonize,
]
for suite in suites:
diff --git a/clients/python2/test/test_pythonize.py
b/clients/python2/test/test_pythonize.py
new file mode 100644
--- /dev/null
+++ b/clients/python2/test/test_pythonize.py
@@ -0,0 +1,15 @@
+import unittest
+import monetdb.sql.pythonize
+
+class TestPythonize(unittest.TestCase):
+ def test_Binary(self):
+ input1 = ''.join([chr(i) for i in range(256)])
+ output1 = ''.join(["%02X" % i for i in range(256)])
+ result1 = monetdb.sql.pythonize.Binary(input1)
+ self.assertEqual(output1, result1)
+
+ input2 = '\tdharma'
+ output2 = '09646861726D61'
+ result2 = monetdb.sql.pythonize.Binary(input2)
+ self.assertEqual(output2, result2)
+
diff --git a/clients/python3/monetdb/sql/pythonize.py
b/clients/python3/monetdb/sql/pythonize.py
--- a/clients/python3/monetdb/sql/pythonize.py
+++ b/clients/python3/monetdb/sql/pythonize.py
@@ -27,8 +27,8 @@ from monetdb.exceptions import Programmi
import re
def strip(data):
- """ returns a python string, chops off quotes,
- replaces escape characters"""
+ """ returns a python string, with chopped off quotes,
+ and replaced escape characters"""
return ''.join([w.encode('utf-8').decode('unicode_escape') if '\\' in w
else w for w in re.split('([\000-\200]+)', data[1:-1])])
def py_bool(data):
@@ -120,7 +120,7 @@ def convert(data, type_code):
def Binary(data):
"""returns binary encoding of data"""
- return ''.join([hex(ord(i))[2:] for i in data]).upper()
+ return ''.join(["%02X" % ord(i) for i in data])
def DateFromTicks(ticks):
"""Convert ticks to python Date"""
diff --git a/clients/python3/test/runtests.py b/clients/python3/test/runtests.py
--- a/clients/python3/test/runtests.py
+++ b/clients/python3/test/runtests.py
@@ -36,6 +36,7 @@ except ImportError:
import capabilities
import dbapi20
+import test_pythonize
warnings.filterwarnings('error')
@@ -100,6 +101,16 @@ if __name__ == '__main__':
TextTestRunnerNoTime(verbosity=3).run(tests)
+if __name__ == '__main__':
+ suites = [
+ Test_Capabilities,
+ Test_DBAPI20,
+ test_pythonize.TestPythonize,
+ ]
+ for suite in suites:
+ tests = unittest.TestLoader().loadTestsFromTestCase(suite)
+ TextTestRunnerNoTime(verbosity=3).run(tests)
+
diff --git a/clients/python3/test/test_pythonize.py
b/clients/python3/test/test_pythonize.py
new file mode 100644
--- /dev/null
+++ b/clients/python3/test/test_pythonize.py
@@ -0,0 +1,15 @@
+import unittest
+import monetdb.sql.pythonize
+
+class TestPythonize(unittest.TestCase):
+ def test_Binary(self):
+ input1 = ''.join([chr(i) for i in range(256)])
+ output1 = ''.join(["%02X" % i for i in range(256)])
+ result1 = monetdb.sql.pythonize.Binary(input1)
+ self.assertEqual(output1, result1)
+
+ input2 = '\tdharma'
+ output2 = '09646861726D61'
+ result2 = monetdb.sql.pythonize.Binary(input2)
+ self.assertEqual(output2, result2)
+
diff --git a/sql/test/mapi/Tests/python2_test_monetdb_sql.stable.err
b/sql/test/mapi/Tests/python2_test_monetdb_sql.stable.err
--- a/sql/test/mapi/Tests/python2_test_monetdb_sql.stable.err
+++ b/sql/test/mapi/Tests/python2_test_monetdb_sql.stable.err
@@ -149,6 +149,12 @@ test_utf8 (__main__.Test_DBAPI20) ... ok
Ran 38 tests
OK
+test_Binary (test_pythonize.TestPythonize) ... ok
+
+----------------------------------------------------------------------
+Ran 1 test
+
+OK
# 11:54:48 >
# 11:54:48 > Done.
diff --git a/sql/test/mapi/Tests/python3_test_monetdb_sql.stable.err
b/sql/test/mapi/Tests/python3_test_monetdb_sql.stable.err
--- a/sql/test/mapi/Tests/python3_test_monetdb_sql.stable.err
+++ b/sql/test/mapi/Tests/python3_test_monetdb_sql.stable.err
@@ -149,6 +149,12 @@ test_utf8 (__main__.Test_DBAPI20) ... ok
Ran 38 tests
OK
+test_Binary (test_pythonize.TestPythonize) ... ok
+
+----------------------------------------------------------------------
+Ran 1 test
+
+OK
# 11:54:48 >
# 11:54:48 > Done.
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list