Exemplo n.º 1
0
def test_enter_mode():
    from mars.config import option_context, options

    @utils.enter_mode(kernel=True)
    def wrapped():
        return utils.is_eager_mode()

    assert not options.eager_mode
    assert not wrapped()

    with option_context({'eager_mode': True}):
        assert options.eager_mode
        assert not wrapped()

    @utils.enter_mode(kernel=True)
    def wrapped2():
        wrapped()
        with option_context({'eager_mode': True}):
            assert options.eager_mode
            assert not utils.is_eager_mode()
            with utils.enter_mode(kernel=False):
                assert not utils.is_kernel_mode()
            assert utils.is_kernel_mode()

    wrapped2()

    assert not utils.is_kernel_mode()
    assert not utils.is_build_mode()

    @utils.enter_mode(kernel=False)
    def wrapped3():
        wrapped()
        with option_context({'eager_mode': True}):
            assert options.eager_mode
            assert not utils.is_kernel_mode()
            with utils.enter_mode(kernel=True, build=True):
                assert utils.is_kernel_mode()
                assert utils.is_build_mode()
            assert not utils.is_kernel_mode()
            assert not utils.is_build_mode()
            with pytest.raises(ValueError):
                with utils.enter_mode(kernel=True, build=True):
                    raise ValueError('meant to raise error')
            assert not utils.is_kernel_mode()
            assert not utils.is_build_mode()

            @utils.enter_mode(kernel=True)
            def wrapped4():
                raise ValueError('meant to raise error')

            with pytest.raises(ValueError):
                wrapped4()
            assert not utils.is_kernel_mode()
            assert not utils.is_build_mode()

    wrapped3()
Exemplo n.º 2
0
    def testEnterMode(self):
        from mars.config import option_context, options

        @utils.enter_mode(kernel=True)
        def wrapped():
            return utils.is_eager_mode()

        self.assertFalse(options.eager_mode)
        self.assertFalse(wrapped())

        with option_context({'eager_mode': True}):
            self.assertTrue(options.eager_mode)
            self.assertFalse(wrapped())

        @utils.enter_mode(kernel=True)
        def wrapped2():
            wrapped()
            with option_context({'eager_mode': True}):
                self.assertTrue(options.eager_mode)
                self.assertFalse(utils.is_eager_mode())
                with utils.enter_mode(kernel=False):
                    self.assertFalse(utils.is_kernel_mode())
                self.assertTrue(utils.is_kernel_mode())

        wrapped2()

        self.assertFalse(utils.is_kernel_mode())
        self.assertFalse(utils.is_build_mode())

        @utils.enter_mode(kernel=False)
        def wrapped3():
            wrapped()
            with option_context({'eager_mode': True}):
                self.assertTrue(options.eager_mode)
                self.assertFalse(utils.is_kernel_mode())
                with utils.enter_mode(kernel=True, build=True):
                    self.assertTrue(utils.is_kernel_mode())
                    self.assertTrue(utils.is_build_mode())
                self.assertFalse(utils.is_kernel_mode())
                self.assertFalse(utils.is_build_mode())
                with self.assertRaises(ValueError):
                    with utils.enter_mode(kernel=True, build=True):
                        raise ValueError('meant to raise error')
                self.assertFalse(utils.is_kernel_mode())
                self.assertFalse(utils.is_build_mode())

                @utils.enter_mode(kernel=True)
                def wrapped4():
                    raise ValueError('meant to raise error')

                with self.assertRaises(ValueError):
                    wrapped4()
                self.assertFalse(utils.is_kernel_mode())
                self.assertFalse(utils.is_build_mode())

        wrapped3()
Exemplo n.º 3
0
    def wrapped3():
        wrapped()
        with option_context({'eager_mode': True}):
            assert options.eager_mode
            assert not utils.is_kernel_mode()
            with utils.enter_mode(kernel=True, build=True):
                assert utils.is_kernel_mode()
                assert utils.is_build_mode()
            assert not utils.is_kernel_mode()
            assert not utils.is_build_mode()
            with pytest.raises(ValueError):
                with utils.enter_mode(kernel=True, build=True):
                    raise ValueError('meant to raise error')
            assert not utils.is_kernel_mode()
            assert not utils.is_build_mode()

            @utils.enter_mode(kernel=True)
            def wrapped4():
                raise ValueError('meant to raise error')

            with pytest.raises(ValueError):
                wrapped4()
            assert not utils.is_kernel_mode()
            assert not utils.is_build_mode()
Exemplo n.º 4
0
        def wrapped3():
            wrapped()
            with option_context({'eager_mode': True}):
                self.assertTrue(options.eager_mode)
                self.assertFalse(utils.is_kernel_mode())
                with utils.enter_mode(kernel=True, build=True):
                    self.assertTrue(utils.is_kernel_mode())
                    self.assertTrue(utils.is_build_mode())
                self.assertFalse(utils.is_kernel_mode())
                self.assertFalse(utils.is_build_mode())
                with self.assertRaises(ValueError):
                    with utils.enter_mode(kernel=True, build=True):
                        raise ValueError('meant to raise error')
                self.assertFalse(utils.is_kernel_mode())
                self.assertFalse(utils.is_build_mode())

                @utils.enter_mode(kernel=True)
                def wrapped4():
                    raise ValueError('meant to raise error')

                with self.assertRaises(ValueError):
                    wrapped4()
                self.assertFalse(utils.is_kernel_mode())
                self.assertFalse(utils.is_build_mode())