Commit 0e1e8803 authored by Stefan Behnel's avatar Stefan Behnel

make PEP492 test use new-style classes in Py2.x

parent 3b8f1fdc
...@@ -23,7 +23,7 @@ except ImportError: ...@@ -23,7 +23,7 @@ except ImportError:
def __init__(self, gen): def __init__(self, gen):
self._gen = gen self._gen = gen
class _GeneratorWrapper: class _GeneratorWrapper(object):
def __init__(self, gen): def __init__(self, gen):
self.__wrapped__ = gen self.__wrapped__ = gen
self.send = gen.send self.send = gen.send
...@@ -70,7 +70,7 @@ def exec(code_string, l, g): ...@@ -70,7 +70,7 @@ def exec(code_string, l, g):
g.update(ns) g.update(ns)
class AsyncYieldFrom: class AsyncYieldFrom(object):
def __init__(self, obj): def __init__(self, obj):
self.obj = obj self.obj = obj
...@@ -78,7 +78,7 @@ class AsyncYieldFrom: ...@@ -78,7 +78,7 @@ class AsyncYieldFrom:
yield from self.obj yield from self.obj
class AsyncYield: class AsyncYield(object):
def __init__(self, value): def __init__(self, value):
self.value = value self.value = value
...@@ -729,7 +729,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -729,7 +729,7 @@ class CoroutineTest(unittest.TestCase):
self.assertEqual(run_async(foo()), ([], 42)) self.assertEqual(run_async(foo()), ([], 42))
def test_await_5(self): def test_await_5(self):
class Awaitable: class Awaitable(object):
def __await__(self): def __await__(self):
return return
...@@ -742,7 +742,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -742,7 +742,7 @@ class CoroutineTest(unittest.TestCase):
run_async(foo()) run_async(foo())
def test_await_6(self): def test_await_6(self):
class Awaitable: class Awaitable(object):
def __await__(self): def __await__(self):
return iter([52]) return iter([52])
...@@ -752,7 +752,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -752,7 +752,7 @@ class CoroutineTest(unittest.TestCase):
self.assertEqual(run_async(foo()), ([52], None)) self.assertEqual(run_async(foo()), ([52], None))
def test_await_7(self): def test_await_7(self):
class Awaitable: class Awaitable(object):
def __await__(self): def __await__(self):
yield 42 yield 42
return 100 return 100
...@@ -763,7 +763,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -763,7 +763,7 @@ class CoroutineTest(unittest.TestCase):
self.assertEqual(run_async(foo()), ([42], 100)) self.assertEqual(run_async(foo()), ([42], 100))
def test_await_8(self): def test_await_8(self):
class Awaitable: class Awaitable(object):
pass pass
async def foo(): return (await Awaitable()) async def foo(): return (await Awaitable())
...@@ -828,7 +828,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -828,7 +828,7 @@ class CoroutineTest(unittest.TestCase):
async def coro(): async def coro():
return 'spam' return 'spam'
class Awaitable: class Awaitable(object):
def __await__(self): def __await__(self):
return coro() return coro()
...@@ -841,7 +841,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -841,7 +841,7 @@ class CoroutineTest(unittest.TestCase):
run_async(foo()) run_async(foo())
def test_await_13(self): def test_await_13(self):
class Awaitable: class Awaitable(object):
def __await__(self): def __await__(self):
return self return self
...@@ -854,14 +854,14 @@ class CoroutineTest(unittest.TestCase): ...@@ -854,14 +854,14 @@ class CoroutineTest(unittest.TestCase):
run_async(foo()) run_async(foo())
def test_await_14(self): def test_await_14(self):
class Wrapper: class Wrapper(object):
# Forces the interpreter to use CoroutineType.__await__ # Forces the interpreter to use CoroutineType.__await__
def __init__(self, coro): def __init__(self, coro):
self.coro = coro self.coro = coro
def __await__(self): def __await__(self):
return self.coro.__await__() return self.coro.__await__()
class FutureLike: class FutureLike(object):
def __await__(self): def __await__(self):
return (yield) return (yield)
...@@ -901,7 +901,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -901,7 +901,7 @@ class CoroutineTest(unittest.TestCase):
next(it) next(it)
def test_with_1(self): def test_with_1(self):
class Manager: class Manager(object):
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
...@@ -941,7 +941,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -941,7 +941,7 @@ class CoroutineTest(unittest.TestCase):
run_async(foo()) run_async(foo())
def test_with_2(self): def test_with_2(self):
class CM: class CM(object):
def __aenter__(self): def __aenter__(self):
pass pass
...@@ -953,7 +953,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -953,7 +953,7 @@ class CoroutineTest(unittest.TestCase):
run_async(foo()) run_async(foo())
def test_with_3(self): def test_with_3(self):
class CM: class CM(object):
def __aexit__(self): def __aexit__(self):
pass pass
...@@ -965,7 +965,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -965,7 +965,7 @@ class CoroutineTest(unittest.TestCase):
run_async(foo()) run_async(foo())
def test_with_4(self): def test_with_4(self):
class CM: class CM(object):
def __enter__(self): def __enter__(self):
pass pass
...@@ -984,7 +984,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -984,7 +984,7 @@ class CoroutineTest(unittest.TestCase):
# it's a regression test for an early bug with opcodes # it's a regression test for an early bug with opcodes
# generation # generation
class CM: class CM(object):
async def __aenter__(self): async def __aenter__(self):
return self return self
...@@ -999,7 +999,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -999,7 +999,7 @@ class CoroutineTest(unittest.TestCase):
run_async(func()) run_async(func())
def test_with_6(self): def test_with_6(self):
class CM: class CM(object):
def __aenter__(self): def __aenter__(self):
return 123 return 123
...@@ -1016,7 +1016,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1016,7 +1016,7 @@ class CoroutineTest(unittest.TestCase):
run_async(foo()) run_async(foo())
def test_with_7(self): def test_with_7(self):
class CM: class CM(object):
async def __aenter__(self): async def __aenter__(self):
return self return self
...@@ -1042,7 +1042,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1042,7 +1042,7 @@ class CoroutineTest(unittest.TestCase):
def test_with_8(self): def test_with_8(self):
CNT = 0 CNT = 0
class CM: class CM(object):
async def __aenter__(self): async def __aenter__(self):
return self return self
...@@ -1065,7 +1065,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1065,7 +1065,7 @@ class CoroutineTest(unittest.TestCase):
def test_with_9(self): def test_with_9(self):
CNT = 0 CNT = 0
class CM: class CM(object):
async def __aenter__(self): async def __aenter__(self):
return self return self
...@@ -1085,7 +1085,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1085,7 +1085,7 @@ class CoroutineTest(unittest.TestCase):
def test_with_10(self): def test_with_10(self):
CNT = 0 CNT = 0
class CM: class CM(object):
async def __aenter__(self): async def __aenter__(self):
return self return self
...@@ -1112,7 +1112,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1112,7 +1112,7 @@ class CoroutineTest(unittest.TestCase):
def test_with_11(self): def test_with_11(self):
CNT = 0 CNT = 0
class CM: class CM(object):
async def __aenter__(self): async def __aenter__(self):
raise NotImplementedError raise NotImplementedError
...@@ -1135,7 +1135,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1135,7 +1135,7 @@ class CoroutineTest(unittest.TestCase):
def test_with_12(self): def test_with_12(self):
CNT = 0 CNT = 0
class CM: class CM(object):
async def __aenter__(self): async def __aenter__(self):
return self return self
...@@ -1153,7 +1153,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1153,7 +1153,7 @@ class CoroutineTest(unittest.TestCase):
def test_with_13(self): def test_with_13(self):
CNT = 0 CNT = 0
class CM: class CM(object):
async def __aenter__(self): async def __aenter__(self):
1/0 1/0
...@@ -1174,7 +1174,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1174,7 +1174,7 @@ class CoroutineTest(unittest.TestCase):
def test_for_1(self): def test_for_1(self):
aiter_calls = 0 aiter_calls = 0
class AsyncIter: class AsyncIter(object):
def __init__(self): def __init__(self):
self.i = 0 self.i = 0
...@@ -1259,7 +1259,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1259,7 +1259,7 @@ class CoroutineTest(unittest.TestCase):
self.assertEqual(sys.getrefcount(tup), refs_before) self.assertEqual(sys.getrefcount(tup), refs_before)
def test_for_3(self): def test_for_3(self):
class I: class I(object):
def __aiter__(self): def __aiter__(self):
return self return self
...@@ -1279,7 +1279,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1279,7 +1279,7 @@ class CoroutineTest(unittest.TestCase):
self.assertEqual(sys.getrefcount(aiter), refs_before) self.assertEqual(sys.getrefcount(aiter), refs_before)
def test_for_4(self): def test_for_4(self):
class I: class I(object):
async def __aiter__(self): async def __aiter__(self):
return self return self
...@@ -1302,7 +1302,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1302,7 +1302,7 @@ class CoroutineTest(unittest.TestCase):
self.assertEqual(sys.getrefcount(aiter), refs_before) self.assertEqual(sys.getrefcount(aiter), refs_before)
def test_for_5(self): def test_for_5(self):
class I: class I(object):
async def __aiter__(self): async def __aiter__(self):
return self return self
...@@ -1322,7 +1322,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1322,7 +1322,7 @@ class CoroutineTest(unittest.TestCase):
def test_for_6(self): def test_for_6(self):
I = 0 I = 0
class Manager: class Manager(object):
async def __aenter__(self): async def __aenter__(self):
nonlocal I nonlocal I
I += 10000 I += 10000
...@@ -1331,7 +1331,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1331,7 +1331,7 @@ class CoroutineTest(unittest.TestCase):
nonlocal I nonlocal I
I += 100000 I += 100000
class Iterable: class Iterable(object):
def __init__(self): def __init__(self):
self.i = 0 self.i = 0
...@@ -1409,7 +1409,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -1409,7 +1409,7 @@ class CoroutineTest(unittest.TestCase):
def test_for_7(self): def test_for_7(self):
CNT = 0 CNT = 0
class AI: class AI(object):
async def __aiter__(self): async def __aiter__(self):
1/0 1/0
async def foo(): async def foo():
...@@ -1432,7 +1432,7 @@ class CoroAsyncIOCompatTest(unittest.TestCase): ...@@ -1432,7 +1432,7 @@ class CoroAsyncIOCompatTest(unittest.TestCase):
buffer = [] buffer = []
class CM: class CM(object):
async def __aenter__(self): async def __aenter__(self):
buffer.append(1) buffer.append(1)
await asyncio.sleep(0.01) await asyncio.sleep(0.01)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment