Skip to content

Commit

Permalink
test: test_pep380.py: Update to pass on MicroPython.
Browse files Browse the repository at this point in the history
Various corner cases are not supported.
  • Loading branch information
Paul Sokolovsky committed Jul 7, 2015
1 parent e824805 commit dc9796a
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions test/test_pep380.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io
import sys
import inspect
import parser
#import parser

from test.support import captured_stderr, disable_gc, gc_collect

Expand Down Expand Up @@ -288,7 +288,8 @@ def g2():
g.close()
except ValueError as e:
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:
self.fail("subgenerator failed to raise ValueError")
self.assertEqual(trace,[
Expand Down Expand Up @@ -352,15 +353,16 @@ def pex(e):
pex(e)
e = StopIteration("spam")
pex(e)
e.value = "eggs"
pex(e)
# MicroPython doesn't support assignment to .value
# e.value = "eggs"
# pex(e)
self.assertEqual(trace,[
"StopIteration: ",
"value = None",
"StopIteration: spam",
"value = spam",
"StopIteration: spam",
"value = eggs",
# "StopIteration: spam",
# "value = eggs",
])


Expand Down Expand Up @@ -554,11 +556,13 @@ def g():
self.assertEqual(next(gi), 1)
gi.throw(AttributeError)

with captured_stderr() as output:
gi = g()
self.assertEqual(next(gi), 1)
gi.close()
self.assertIn('ZeroDivisionError', output.getvalue())
# In MicroPython, exceptions is .close() are not ignored/printed to sys.stderr,
# but propagated as usual.
# with captured_stderr() as output:
# gi = g()
# self.assertEqual(next(gi), 1)
# gi.close()
# self.assertIn('ZeroDivisionError', output.getvalue())

def test_exception_in_initial_next_call(self):
"""
Expand All @@ -579,6 +583,7 @@ def run():
"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):
"""
Test attempted yield-from loop
Expand Down Expand Up @@ -834,7 +839,7 @@ def g():
gi.throw(GeneratorExit)
except ValueError as e:
self.assertEqual(e.args[0], "Vorpal bunny encountered")
self.assertIsInstance(e.__context__, GeneratorExit)
# self.assertIsInstance(e.__context__, GeneratorExit)
else:
self.fail("subgenerator failed to raise ValueError")
self.assertEqual(trace,[
Expand All @@ -847,6 +852,7 @@ def g():
yield from ()
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):
# Check with basic iteration
def one():
Expand Down Expand Up @@ -919,6 +925,7 @@ def one():
next(g1)
g1.close()

@unittest.skip("MicroPython doesn't support inspect.stack()")
def test_delegator_is_visible_to_debugger(self):
def call_stack():
return [f[3] for f in inspect.stack()]
Expand Down

0 comments on commit dc9796a

Please sign in to comment.