Beispiel #1
0
def main():
    """The main entry point. """

    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    handler = logging.FileHandler('shirow_test.log')
    logger.addHandler(handler)

    unittest.main()
Beispiel #2
0
        expected = [
            1010,
            1020,
            1030,  # first 3 calls on schedule
            1050,
            1070,  # next 2 delayed one cycle
            1100,
            1130,  # next 2 delayed 2 cycles
            1170,
            1210,  # next 2 delayed 3 cycles
            1220,
            1230,  # then back on schedule.
        ]
        calls = []

        def cb():
            calls.append(self.io_loop.time())
            if not sleep_durations:
                self.io_loop.stop()
                return
            self.io_loop.sleep(sleep_durations.pop(0))

        pc = PeriodicCallback(cb, 10000)
        pc.start()
        self.io_loop.start()
        self.assertEqual(calls, expected)


if __name__ == "__main__":
    unittest.main()
Beispiel #3
0
    @gen_test
    def test_yield_outside_with_exception_stack_context(self):
        cb = yield gen.Callback('k1')
        with ExceptionStackContext(lambda t, v, tb: False):
            self.io_loop.add_callback(cb)
        yield gen.Wait('k1')

    def test_run_with_stack_context(self):
        @gen.coroutine
        def f1():
            self.assertEqual(self.active_contexts, ['c1'])
            yield run_with_stack_context(
                StackContext(functools.partial(self.context, 'c2')),
                f2)
            self.assertEqual(self.active_contexts, ['c1'])

        @gen.coroutine
        def f2():
            self.assertEqual(self.active_contexts, ['c1', 'c2'])
            yield gen.Task(self.io_loop.add_callback)
            self.assertEqual(self.active_contexts, ['c1', 'c2'])

        self.assertEqual(self.active_contexts, [])
        run_with_stack_context(
            StackContext(functools.partial(self.context, 'c1')),
            f1)
        self.assertEqual(self.active_contexts, [])

if __name__ == '__main__':
    unittest.main()
Beispiel #4
0
            print(line3)
# 在line3中搜索样式LINE_RE2
            m = LogFormatterTest.LINE_RE2.match(line)
            #m = LogFormatterTest.LINE_RE2.search(line)
            print("匹配")
            print(m)
            print(m.group(1))
            print("匹配end")

            if m:
                return m.group(1)
            else:
                # 不匹配
                raise Exception("output didn't match regex: %r" % line)

    def test_basic_logging(self):
        self.logger.error("foo")
        #self.logger.warn("foo")

        self.assertEqual(self.get_output(), b"foo")

    def test_bytes_logging(self):
        with ignore_bytes_warning():
            # This will be "\xe9" on python 2 or "b'\xe9'" on python 3
            self.logger.error(b"\xe9")

            self.assertEqual(self.get_output(), utf8(repr(b"\xe9")))

if __name__ == "__main__":
    unittest.main(verbosity=2, exit=False)
Beispiel #5
0
            print(line3)
            # 在line3中搜索样式LINE_RE2
            m = LogFormatterTest.LINE_RE2.match(line)
            #m = LogFormatterTest.LINE_RE2.search(line)
            print("匹配")
            print(m)
            print(m.group(1))
            print("匹配end")

            if m:
                return m.group(1)
            else:
                # 不匹配
                raise Exception("output didn't match regex: %r" % line)

    def test_basic_logging(self):
        self.logger.error("foo")
        #self.logger.warn("foo")

        self.assertEqual(self.get_output(), b"foo")

    def test_bytes_logging(self):
        with ignore_bytes_warning():
            # This will be "\xe9" on python 2 or "b'\xe9'" on python 3
            self.logger.error(b"\xe9")

            self.assertEqual(self.get_output(), utf8(repr(b"\xe9")))

if __name__ == "__main__":
    unittest.main(verbosity=2, exit=False)