def test_timing(self):
        reader, writer = os.pipe()
        try:
            loop = EventLoop()
            
            data = [
                'Lorem ipsum\n',
                'dolor\nsit\namet, ',
                'consectetur',
                ' adipiscing ',
                'elit.\nAliquam magna dolor, ', # no newline character at the end
            ]
            # Reverse because list.pop() pops at the end.
            data = data[::-1]
            
            @loop.add_timer(.01, repeat=True)
            def slow_write():
                if data:
                    os.write(writer, data.pop())
                else:
                    loop.stop()
            
            lines = []
            @loop.line_reader(reader)
            def new_line(line):
                lines.append(line)
                expected_time = {
                    'L': .01, 'd': .02, 's': .02, 'a': .05}[line[0]]
                assert round(time.time() - start, 2) == expected_time

            time.sleep(.02)
            # Reset so that the timing is correct in spite of the sleep we
            # just did.
            slow_write.reset()
            start = time.time()
            loop.run()
            
            assert lines == [
                'Lorem ipsum\n',
                'dolor\n',
                'sit\n',
                'amet, consectetur adipiscing elit.\n'
            ]
        finally:
            os.close(reader)
            os.close(writer)
dataset/ETHPy150Open SimonSapin/snippets/event_loop/tests.py/TestLineReader.test_timing/original