Author: Ronan Lamy <[email protected]>
Branch: py3.5
Changeset: r95493:61f4233c89ab
Date: 2018-12-14 16:51 +0000
http://bitbucket.org/pypy/pypy/changeset/61f4233c89ab/
Log: More py3 fixes in extra_tests/
diff --git a/extra_tests/test_cStringIO.py b/extra_tests/test_cStringIO.py
deleted file mode 100644
--- a/extra_tests/test_cStringIO.py
+++ /dev/null
@@ -1,23 +0,0 @@
-"""
-Tests for the PyPy cStringIO implementation.
-"""
-from io import StringIO
-
-data = b"some bytes"
-
-def test_reset():
- """
- Test that the reset method of cStringIO objects sets the position
- marker to the beginning of the stream.
- """
- stream = StringIO()
- stream.write(data)
- assert stream.read() == ''
- stream.reset()
- assert stream.read() == data
-
- stream = StringIO(data)
- assert stream.read() == data
- assert stream.read() == ''
- stream.reset()
- assert stream.read() == data
diff --git a/extra_tests/test_code.py b/extra_tests/test_code.py
--- a/extra_tests/test_code.py
+++ b/extra_tests/test_code.py
@@ -9,11 +9,8 @@
try:
mystdout = StringIO()
sys.stdout = mystdout
- runner.runcode(compile("print 5,;0/0", "<interactive>", "exec"))
+ runner.runcode(compile("print(5);0/0", "<interactive>", "exec"))
finally:
sys.stdout = old_stdout
- if '__pypy__' in sys.builtin_module_names:
- assert mystdout.getvalue() == "5\n"
- else:
- assert mystdout.getvalue() == "5"
+ assert mystdout.getvalue() == "5\n"
diff --git a/extra_tests/test_dbm.py b/extra_tests/test_dbm.py
--- a/extra_tests/test_dbm.py
+++ b/extra_tests/test_dbm.py
@@ -33,7 +33,7 @@
d[123]
with pytest.raises(TypeError):
123 in d
- with pytest.raises(TypeError):
+ with pytest.raises(AttributeError):
d.has_key(123)
with pytest.raises(TypeError):
d.setdefault(123, 'xyz')
@@ -43,7 +43,7 @@
d.get(123)
assert dict(d) == {}
d.setdefault('xyz', '123')
- assert dict(d) == {'xyz': '123'}
+ assert dict(d) == {b'xyz': b'123'}
d.close()
def test_multiple_sets(tmpdir):
@@ -52,15 +52,16 @@
d['xyz'] = '12'
d['xyz'] = '3'
d['xyz'] = '546'
- assert dict(d) == {'xyz': '546'}
- assert d['xyz'] == '546'
+ assert dict(d) == {b'xyz': b'546'}
+ assert d['xyz'] == b'546'
@pytest.mark.skipif("'__pypy__' not in sys.modules")
def test_extra():
+ import _dbm
with pytest.raises(TypeError):
- dbm.datum(123)
+ _dbm.datum(123)
with pytest.raises(TypeError):
- dbm.datum(False)
+ _dbm.datum(False)
def test_null():
db = dbm.open('test', 'c')
@@ -68,20 +69,19 @@
db.close()
db = dbm.open('test', 'r')
- assert db['1'] == 'a\x00b'
+ assert db['1'] == b'a\x00b'
db.close()
def test_key_with_empty_value(tmpdir):
# this test fails on CPython too (at least on tannit), and the
# case shows up when gdbm is not installed and test_anydbm.py
# falls back dbm.
- pytest.skip("test may fail on CPython too")
path = str(tmpdir.join('test_dbm_extra.test_key_with_empty_value'))
d = dbm.open(path, 'c')
assert 'key_with_empty_value' not in d
d['key_with_empty_value'] = ''
assert 'key_with_empty_value' in d
- assert d['key_with_empty_value'] == ''
+ assert d['key_with_empty_value'] == b''
d.close()
def test_unicode_filename(tmpdir):
diff --git a/extra_tests/test_sqlite3.py b/extra_tests/test_sqlite3.py
--- a/extra_tests/test_sqlite3.py
+++ b/extra_tests/test_sqlite3.py
@@ -213,19 +213,10 @@
def test_returning_blob_must_own_memory(con):
import gc
- con.create_function("returnblob", 0, lambda: buffer("blob"))
+ con.create_function("returnblob", 0, lambda: memoryview(b"blob"))
cur = con.execute("select returnblob()")
val = cur.fetchone()[0]
- for i in range(5):
- gc.collect()
- got = (val[0], val[1], val[2], val[3])
- assert got == ('b', 'l', 'o', 'b')
- # in theory 'val' should be a read-write buffer
- # but it's not right now
- if not hasattr(_sqlite3, '_ffi'):
- val[1] = 'X'
- got = (val[0], val[1], val[2], val[3])
- assert got == ('b', 'X', 'o', 'b')
+ assert isinstance(val, bytes)
def test_description_after_fetchall(con):
cur = con.cursor()
@@ -264,7 +255,7 @@
def test_issue1573(con):
cur = con.cursor()
cur.execute(u'SELECT 1 as méil')
- assert cur.description[0][0] == u"méil".encode('utf-8')
+ assert cur.description[0][0] == u"méil"
def test_adapter_exception(con):
def cast(obj):
diff --git a/extra_tests/test_string.py b/extra_tests/test_string.py
deleted file mode 100644
--- a/extra_tests/test_string.py
+++ /dev/null
@@ -1,46 +0,0 @@
-
-"""
-Test module for functions in string.py
-"""
-import pytest
-
-def test_maketrans():
- import string
- assert string.maketrans('', '') == (
-
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12'
- '\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f
!"#$%&\'()*+,-./0'
-
'123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu'
- 'vwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d'
- '\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e'
- '\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf'
- '\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0'
- '\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1'
- '\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2'
- '\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3'
- '\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff')
- assert string.maketrans('a', 'b') == (
-
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12'
- '\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f
!"#$%&\'()*+,-./0'
-
'123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`bbcdefghijklmnopqrstu'
- 'vwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d'
- '\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e'
- '\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf'
- '\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0'
- '\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1'
- '\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2'
- '\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3'
- '\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff')
- assert string.maketrans('ab', 'cd') == (
-
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12'
- '\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f
!"#$%&\'()*+,-./0'
-
'123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`cdcdefghijklmnopqrstu'
- 'vwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d'
- '\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e'
- '\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf'
- '\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0'
- '\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1'
- '\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2'
- '\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3'
- '\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff')
- with pytest.raises(ValueError):
- string.maketrans('aa', '')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit