Source

green380 / test.py

from unittest import TestCase
import threading
import os
import select
import time
import gc

class TestEpoll(TestCase):

    def test_close_hups(self):
        r, w = os.pipe()
        po = select.epoll()
        po.register(r, -1)
        #~ po.register(w, select.EPOLLOUT)
        def do_close():
            time.sleep(0.01)
            #~ os.close(r)
            time.sleep(0.01)
            os.close(w)
        threading.Thread(target=do_close).start()
        #~ print(po.poll())
        #~ time.sleep(0.01)
        #~ os.write(w, b'1')
        #~ print(po.poll())

class TestGenerator(TestCase):

    def gen(self):
        try:
            yield
        except GeneratorExit as exc:
            print('yep', exc)

    def test_generator_exit(self):
        def gen():
            try:
                yield
            except GeneratorExit as exc:
                print('yep', exc)
                raise
        a = gen()
        a.__next__()
        del a
        gc.collect()
        #~ next(a)
        #~ del a
        #~ gc.collect()

    def test_yield_from_non_generator(self):
        print('yield from non gen')
        def non_gen():
            return 3
        print((yield from non_gen()))
        def gen_pump():
            print('before yield from')
            self.assertEqual(3, (yield from non_gen()))
            print('after yield from')
        for a in gen_pump():
            pass
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.