Esempio n. 1
0
def test_semaphore():
    filename = 'foo.txt'
    try:
        semaphore = Semaphore(time_limit=5)

        input_process = DummyInputProcess('foo', semaphore._input_queue,
                                          semaphore._logger)
        input_process.topic_filter = DummyTopicFilter()
        file_handler = FileHandler('barhandler', filename)

        semaphore.add_input_process(input_process)
        semaphore.replace_middleware_process(DummyMiddleProcess)
        semaphore.add_output_handler(file_handler)

        with pytest.raises(SemaphoreTimeLimitInterrupt):
            semaphore.run()
    finally:
        if os.path.isfile(filename):
            os.remove(filename)
Esempio n. 2
0
def test_semaphore():
    filename = 'foo.txt'
    try:
        semaphore = Semaphore(time_limit=10)

        log_handler = logging.StreamHandler(sys.stderr)
        log_handler.setLevel(logging.DEBUG)
        semaphore._logger.addHandler(log_handler)

        input_process = DummyInputProcess('foo', semaphore._input_queue,
                                          semaphore._logger)
        input_process.topic_filter = DummyTopicFilter()
        file_handler = FileHandler('barhandler', filename)

        semaphore.add_input_process(input_process)
        semaphore.replace_middleware_process(DummyMiddleProcess)
        semaphore.add_output_handler(file_handler)

        semaphore.run()
    finally:
        if os.path.isfile(filename):
            os.remove(filename)