def test_push_pop(self):
     """
     Covers Context.push(), Context.pop(), Context.top()
     """
     ctx = Context(self)
     Context.push(ctx)
     self.assertIs(ctx, Context.top())
     Context.pop(ctx)
    def test_raises_unbalanced_context(self):
        """
        Raises if context push and pop calls are not balanced.
        """
        ctx1 = Context(self)
        ctx2 = Context(self)

        Context.push(ctx1)
        Context.push(ctx2)
        self.assertRaises(AssertionError, Context.pop, ctx1)
    def test_contextmanager(self):
        """
        Covers context manager interface.
        """
        with Context(self) as ctx:
            self.assertIs(ctx, Context.top())

            with Context(self) as ctx2:
                self.assertIsNot(ctx2, ctx)
                self.assertIs(ctx2, Context.top())

            self.assertIs(ctx, Context.top())