~ubuntu-branches/ubuntu/trusty/python3.3/trusty

« back to all changes in this revision

Viewing changes to Lib/test/test_contextlib.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-11-19 08:46:55 UTC
  • mfrom: (22.1.15 sid)
  • Revision ID: package-import@ubuntu.com-20131119084655-pueqfadzs5v1xf53
Tags: 3.3.3-1
* Python 3.3.3 release.
* Update to 20131119 from the 3.3 branch.
* Regenerate the patches.
* Update the symbols files.
* Fix test support when the running kernel doesn't handle port reuse.
* libpython3.3-minimal replaces libpython3.3-stdlib (<< 3.2.3-7).
  Closes: #725240.

Show diffs side-by-side

added added

removed removed

Lines of Context:
573
573
        self.assertIsInstance(inner_exc, ValueError)
574
574
        self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)
575
575
 
 
576
    def test_exit_exception_non_suppressing(self):
 
577
        # http://bugs.python.org/issue19092
 
578
        def raise_exc(exc):
 
579
            raise exc
 
580
 
 
581
        def suppress_exc(*exc_details):
 
582
            return True
 
583
 
 
584
        try:
 
585
            with ExitStack() as stack:
 
586
                stack.callback(lambda: None)
 
587
                stack.callback(raise_exc, IndexError)
 
588
        except Exception as exc:
 
589
            self.assertIsInstance(exc, IndexError)
 
590
        else:
 
591
            self.fail("Expected IndexError, but no exception was raised")
 
592
 
 
593
        try:
 
594
            with ExitStack() as stack:
 
595
                stack.callback(raise_exc, KeyError)
 
596
                stack.push(suppress_exc)
 
597
                stack.callback(raise_exc, IndexError)
 
598
        except Exception as exc:
 
599
            self.assertIsInstance(exc, KeyError)
 
600
        else:
 
601
            self.fail("Expected KeyError, but no exception was raised")
 
602
 
 
603
    def test_body_exception_suppress(self):
 
604
        def suppress_exc(*exc_details):
 
605
            return True
 
606
        try:
 
607
            with ExitStack() as stack:
 
608
                stack.push(suppress_exc)
 
609
                1/0
 
610
        except IndexError as exc:
 
611
            self.fail("Expected no exception, got IndexError")
 
612
 
576
613
    def test_exit_exception_chaining_suppress(self):
577
614
        with ExitStack() as stack:
578
615
            stack.push(lambda *exc: True)