test: test_pep380.py: Update to pass on MicroPython.

Various corner cases are not supported.
pull/35/head
Paul Sokolovsky 2015-07-08 00:07:48 +03:00
rodzic e8248056d4
commit dc9796a0d2
1 zmienionych plików z 19 dodań i 12 usunięć

Wyświetl plik

@ -11,7 +11,7 @@ import unittest
import io import io
import sys import sys
import inspect import inspect
import parser #import parser
from test.support import captured_stderr, disable_gc, gc_collect from test.support import captured_stderr, disable_gc, gc_collect
@ -288,7 +288,8 @@ class TestPEP380Operation(unittest.TestCase):
g.close() g.close()
except ValueError as e: except ValueError as e:
self.assertEqual(e.args[0], "nybbles have exploded with delight") self.assertEqual(e.args[0], "nybbles have exploded with delight")
self.assertIsInstance(e.__context__, GeneratorExit) # MicroPython doesn't support nested exceptions
# self.assertIsInstance(e.__context__, GeneratorExit)
else: else:
self.fail("subgenerator failed to raise ValueError") self.fail("subgenerator failed to raise ValueError")
self.assertEqual(trace,[ self.assertEqual(trace,[
@ -352,15 +353,16 @@ class TestPEP380Operation(unittest.TestCase):
pex(e) pex(e)
e = StopIteration("spam") e = StopIteration("spam")
pex(e) pex(e)
e.value = "eggs" # MicroPython doesn't support assignment to .value
pex(e) # e.value = "eggs"
# pex(e)
self.assertEqual(trace,[ self.assertEqual(trace,[
"StopIteration: ", "StopIteration: ",
"value = None", "value = None",
"StopIteration: spam", "StopIteration: spam",
"value = spam", "value = spam",
"StopIteration: spam", # "StopIteration: spam",
"value = eggs", # "value = eggs",
]) ])
@ -554,11 +556,13 @@ class TestPEP380Operation(unittest.TestCase):
self.assertEqual(next(gi), 1) self.assertEqual(next(gi), 1)
gi.throw(AttributeError) gi.throw(AttributeError)
with captured_stderr() as output: # In MicroPython, exceptions is .close() are not ignored/printed to sys.stderr,
gi = g() # but propagated as usual.
self.assertEqual(next(gi), 1) # with captured_stderr() as output:
gi.close() # gi = g()
self.assertIn('ZeroDivisionError', output.getvalue()) # self.assertEqual(next(gi), 1)
# gi.close()
# self.assertIn('ZeroDivisionError', output.getvalue())
def test_exception_in_initial_next_call(self): def test_exception_in_initial_next_call(self):
""" """
@ -579,6 +583,7 @@ class TestPEP380Operation(unittest.TestCase):
"g1 about to yield from g2" "g1 about to yield from g2"
]) ])
@unittest.skip("MicroPython doesn't check for already active generator when resuming it")
def test_attempted_yield_from_loop(self): def test_attempted_yield_from_loop(self):
""" """
Test attempted yield-from loop Test attempted yield-from loop
@ -834,7 +839,7 @@ class TestPEP380Operation(unittest.TestCase):
gi.throw(GeneratorExit) gi.throw(GeneratorExit)
except ValueError as e: except ValueError as e:
self.assertEqual(e.args[0], "Vorpal bunny encountered") self.assertEqual(e.args[0], "Vorpal bunny encountered")
self.assertIsInstance(e.__context__, GeneratorExit) # self.assertIsInstance(e.__context__, GeneratorExit)
else: else:
self.fail("subgenerator failed to raise ValueError") self.fail("subgenerator failed to raise ValueError")
self.assertEqual(trace,[ self.assertEqual(trace,[
@ -847,6 +852,7 @@ class TestPEP380Operation(unittest.TestCase):
yield from () yield from ()
self.assertRaises(StopIteration, next, g()) self.assertRaises(StopIteration, next, g())
@unittest.skip("MicroPython doesn't check for already active generator when resuming it")
def test_delegating_generators_claim_to_be_running(self): def test_delegating_generators_claim_to_be_running(self):
# Check with basic iteration # Check with basic iteration
def one(): def one():
@ -919,6 +925,7 @@ class TestPEP380Operation(unittest.TestCase):
next(g1) next(g1)
g1.close() g1.close()
@unittest.skip("MicroPython doesn't support inspect.stack()")
def test_delegator_is_visible_to_debugger(self): def test_delegator_is_visible_to_debugger(self):
def call_stack(): def call_stack():
return [f[3] for f in inspect.stack()] return [f[3] for f in inspect.stack()]