fix collection imports for python2.5
This commit is contained in:
parent
72a48d69cd
commit
cbbbfcd101
|
@ -4,7 +4,11 @@ import py
|
||||||
try:
|
try:
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
try:
|
||||||
from collections import Sequence
|
from collections import Sequence
|
||||||
|
except ImportError:
|
||||||
|
Sequence = list
|
||||||
|
|
||||||
|
|
||||||
BuiltinAssertionError = py.builtin.builtins.AssertionError
|
BuiltinAssertionError = py.builtin.builtins.AssertionError
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ def pytest_generate_tests(metafunc):
|
||||||
for val in l:
|
for val in l:
|
||||||
metafunc.addcall(funcargs={name: val})
|
metafunc.addcall(funcargs={name: val})
|
||||||
elif 'anypython' in metafunc.fixturenames:
|
elif 'anypython' in metafunc.fixturenames:
|
||||||
for name in ('python2.4', 'python2.5', 'python2.6',
|
for name in ('python2.5', 'python2.6',
|
||||||
'python2.7', 'python3.2', "python3.3",
|
'python2.7', 'python3.2', "python3.3",
|
||||||
'pypy', 'jython'):
|
'pypy', 'jython'):
|
||||||
metafunc.addcall(id=name, param=name)
|
metafunc.addcall(id=name, param=name)
|
||||||
|
|
|
@ -3,12 +3,6 @@ import sys
|
||||||
import py, pytest
|
import py, pytest
|
||||||
import _pytest.assertion as plugin
|
import _pytest.assertion as plugin
|
||||||
from _pytest.assertion import reinterpret, util
|
from _pytest.assertion import reinterpret, util
|
||||||
try:
|
|
||||||
from collections.abc import MutableSequence
|
|
||||||
except ImportError:
|
|
||||||
from collections import MutableSequence
|
|
||||||
|
|
||||||
|
|
||||||
needsnewassert = pytest.mark.skipif("sys.version_info < (2,6)")
|
needsnewassert = pytest.mark.skipif("sys.version_info < (2,6)")
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,6 +116,14 @@ class TestAssert_reprcompare:
|
||||||
assert len(expl) > 1
|
assert len(expl) > 1
|
||||||
|
|
||||||
def test_Sequence(self):
|
def test_Sequence(self):
|
||||||
|
col = py.builtin._tryimport(
|
||||||
|
"collections.abc",
|
||||||
|
"collections",
|
||||||
|
"sys")
|
||||||
|
if not hasattr(col, "MutableSequence"):
|
||||||
|
pytest.skip("cannot import MutableSequence")
|
||||||
|
MutableSequence = col.MutableSequence
|
||||||
|
|
||||||
class TestSequence(MutableSequence): # works with a Sequence subclass
|
class TestSequence(MutableSequence): # works with a Sequence subclass
|
||||||
def __init__(self, iterable):
|
def __init__(self, iterable):
|
||||||
self.elements = list(iterable)
|
self.elements = list(iterable)
|
||||||
|
|
Loading…
Reference in New Issue