Ejemplo n.º 1
0
    def test_run(self):
        def threadfunc(wfd):
            wfd.write(u'hello 100\n')
            wfd.flush()
            wfd.write(u'hello 102\n')
            wfd.flush()
            time.sleep(0.11)
            wfd.write(u'hello 103\n')
            wfd.flush()
            wfd.close()

        r, w = os.pipe()
        rfd = os.fdopen(r, u'r')
        wfd = os.fdopen(w, u'w')

        thd = threading.Thread(target=threadfunc, args=(wfd,))
        thd.start()

        sio = StringIO()
        feed = delta.fd_feed(rfd, 0.1)
        parser = delta.Parser(flex=True, absolute=False, use_colors=False)
        printer = delta.Printer(sio, timestamps=False, separators=False, orig=False, skip_zeros=False)

        delta.run(feed, parser, printer)
        self.assertEqual(sio.getvalue(), u'''hello 100
hello  +2
hello  +1
''')

        thd.join()
        rfd.close()
Ejemplo n.º 2
0
    def test_fd_feed(self):
        def threadfunc(wfd):
            wfd.write(u'hello\n')
            wfd.flush()
            wfd.write(u'hello\n')
            wfd.flush()
            time.sleep(0.11)
            wfd.write(u'hello\n')
            wfd.flush()
            wfd.close()

        r, w = os.pipe()
        rfd = os.fdopen(r, u'r')
        wfd = os.fdopen(w, u'w')

        thd = threading.Thread(target=threadfunc, args=(wfd,))
        thd.start()

        feed = delta.fd_feed(rfd, 0.1)
        self.assertEqual(next(feed), u'hello\n')
        self.assertEqual(next(feed), u'hello\n')
        self.assertIs(next(feed), delta.separator)
        self.assertEqual(next(feed), u'hello\n')
        self.assertRaises(StopIteration, next, feed)

        thd.join()
        rfd.close()