GRAYBYTE WORDPRESS FILE MANAGER9738

Server IP : 198.54.121.189 / Your IP : 216.73.216.140
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /opt/hc_python/lib/python3.12/site-packages/greenlet/tests/
Upload Files :
Current_dir [ Not Writeable ] Document_root [ Writeable ]

Command :


Current File : /opt/hc_python/lib/python3.12/site-packages/greenlet/tests//test_throw.py
import sys


from greenlet import greenlet
from . import TestCase

def switch(*args):
    return greenlet.getcurrent().parent.switch(*args)


class ThrowTests(TestCase):
    def test_class(self):
        def f():
            try:
                switch("ok")
            except RuntimeError:
                switch("ok")
                return
            switch("fail")
        g = greenlet(f)
        res = g.switch()
        self.assertEqual(res, "ok")
        res = g.throw(RuntimeError)
        self.assertEqual(res, "ok")

    def test_val(self):
        def f():
            try:
                switch("ok")
            except RuntimeError:
                val = sys.exc_info()[1]
                if str(val) == "ciao":
                    switch("ok")
                    return
            switch("fail")

        g = greenlet(f)
        res = g.switch()
        self.assertEqual(res, "ok")
        res = g.throw(RuntimeError("ciao"))
        self.assertEqual(res, "ok")

        g = greenlet(f)
        res = g.switch()
        self.assertEqual(res, "ok")
        res = g.throw(RuntimeError, "ciao")
        self.assertEqual(res, "ok")

    def test_kill(self):
        def f():
            switch("ok")
            switch("fail")
        g = greenlet(f)
        res = g.switch()
        self.assertEqual(res, "ok")
        res = g.throw()
        self.assertTrue(isinstance(res, greenlet.GreenletExit))
        self.assertTrue(g.dead)
        res = g.throw()    # immediately eaten by the already-dead greenlet
        self.assertTrue(isinstance(res, greenlet.GreenletExit))

    def test_throw_goes_to_original_parent(self):
        main = greenlet.getcurrent()

        def f1():
            try:
                main.switch("f1 ready to catch")
            except IndexError:
                return "caught"
            return "normal exit"

        def f2():
            main.switch("from f2")

        g1 = greenlet(f1)
        g2 = greenlet(f2, parent=g1)
        with self.assertRaises(IndexError):
            g2.throw(IndexError)
        self.assertTrue(g2.dead)
        self.assertTrue(g1.dead)

        g1 = greenlet(f1)
        g2 = greenlet(f2, parent=g1)
        res = g1.switch()
        self.assertEqual(res, "f1 ready to catch")
        res = g2.throw(IndexError)
        self.assertEqual(res, "caught")
        self.assertTrue(g2.dead)
        self.assertTrue(g1.dead)

        g1 = greenlet(f1)
        g2 = greenlet(f2, parent=g1)
        res = g1.switch()
        self.assertEqual(res, "f1 ready to catch")
        res = g2.switch()
        self.assertEqual(res, "from f2")
        res = g2.throw(IndexError)
        self.assertEqual(res, "caught")
        self.assertTrue(g2.dead)
        self.assertTrue(g1.dead)

    def test_non_traceback_param(self):
        with self.assertRaises(TypeError) as exc:
            greenlet.getcurrent().throw(
                Exception,
                Exception(),
                self
            )
        self.assertEqual(str(exc.exception),
                         "throw() third argument must be a traceback object")

    def test_instance_of_wrong_type(self):
        with self.assertRaises(TypeError) as exc:
            greenlet.getcurrent().throw(
                Exception(),
                BaseException()
            )

        self.assertEqual(str(exc.exception),
                         "instance exception may not have a separate value")

    def test_not_throwable(self):
        with self.assertRaises(TypeError) as exc:
            greenlet.getcurrent().throw(
                "abc"
            )
        self.assertEqual(str(exc.exception),
                         "exceptions must be classes, or instances, not str")

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
May 23 2025 08:31:29
root / root
0755
__pycache__
--
May 23 2025 08:31:29
root / root
0755
__init__.py
9.142 KB
May 23 2025 08:31:29
root / root
0644
_test_extension.c
5.638 KB
May 23 2025 08:31:29
root / root
0644
_test_extension.cpython-312-x86_64-linux-gnu.so
16.852 KB
May 23 2025 08:31:29
root / root
0755
_test_extension_cpp.cpp
6.411 KB
May 23 2025 08:31:29
root / root
0644
_test_extension_cpp.cpython-312-x86_64-linux-gnu.so
57.016 KB
May 23 2025 08:31:29
root / root
0755
fail_clearing_run_switches.py
1.233 KB
May 23 2025 08:31:29
root / root
0644
fail_cpp_exception.py
0.962 KB
May 23 2025 08:31:29
root / root
0644
fail_initialstub_already_started.py
1.915 KB
May 23 2025 08:31:29
root / root
0644
fail_slp_switch.py
0.512 KB
May 23 2025 08:31:29
root / root
0644
fail_switch_three_greenlets.py
0.934 KB
May 23 2025 08:31:29
root / root
0644
fail_switch_three_greenlets2.py
1.255 KB
May 23 2025 08:31:29
root / root
0644
fail_switch_two_greenlets.py
0.798 KB
May 23 2025 08:31:29
root / root
0644
leakcheck.py
11.684 KB
May 23 2025 08:31:29
root / root
0644
test_contextvars.py
10.294 KB
May 23 2025 08:31:29
root / root
0644
test_cpp.py
2.672 KB
May 23 2025 08:31:29
root / root
0644
test_extension_interface.py
3.739 KB
May 23 2025 08:31:29
root / root
0644
test_gc.py
2.854 KB
May 23 2025 08:31:29
root / root
0644
test_generator.py
1.211 KB
May 23 2025 08:31:29
root / root
0644
test_generator_nested.py
3.631 KB
May 23 2025 08:31:29
root / root
0644
test_greenlet.py
45.167 KB
May 23 2025 08:31:29
root / root
0644
test_greenlet_trash.py
7.761 KB
May 23 2025 08:31:29
root / root
0644
test_leaks.py
17.299 KB
May 23 2025 08:31:29
root / root
0644
test_stack_saved.py
0.436 KB
May 23 2025 08:31:29
root / root
0644
test_throw.py
3.625 KB
May 23 2025 08:31:29
root / root
0644
test_tracing.py
8.057 KB
May 23 2025 08:31:29
root / root
0644
test_version.py
1.308 KB
May 23 2025 08:31:29
root / root
0644
test_weakref.py
0.862 KB
May 23 2025 08:31:29
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF