Fixed test to work on Windows.

This commit is contained in:
Vinay Sajip 2012-04-25 10:47:00 +01:00
parent 66b8b08752
commit c2ad0aa9f1
1 changed files with 17 additions and 17 deletions

View File

@ -2342,28 +2342,28 @@ def remove_loop(fname, tries):
pass pass
time.sleep(0.004 * random.randint(0, 4)) time.sleep(0.004 * random.randint(0, 4))
def cleanup(remover, fn, handler): del_count = 500
handler.close() log_count = 500
remover.join()
if os.path.exists(fn):
os.unlink(fn)
for delay in (False, True):
fd, fn = tempfile.mkstemp('.log', 'test_logging-3-') fd, fn = tempfile.mkstemp('.log', 'test_logging-3-')
os.close(fd) os.close(fd)
del_count = 1000
log_count = 1000
remover = threading.Thread(target=remove_loop, args=(fn, del_count)) remover = threading.Thread(target=remove_loop, args=(fn, del_count))
remover.daemon = True remover.daemon = True
remover.start() remover.start()
for delay in (False, True):
h = logging.handlers.WatchedFileHandler(fn, delay=delay) h = logging.handlers.WatchedFileHandler(fn, delay=delay)
self.addCleanup(cleanup, remover, fn, h)
f = logging.Formatter('%(asctime)s: %(levelname)s: %(message)s') f = logging.Formatter('%(asctime)s: %(levelname)s: %(message)s')
h.setFormatter(f) h.setFormatter(f)
try:
for _ in range(log_count): for _ in range(log_count):
time.sleep(0.005) time.sleep(0.005)
r = logging.makeLogRecord({'msg': 'testing' }) r = logging.makeLogRecord({'msg': 'testing' })
h.handle(r) h.handle(r)
finally:
h.close()
remover.join()
if os.path.exists(fn):
os.unlink(fn)
# Set the locale to the platform-dependent default. I have no idea # Set the locale to the platform-dependent default. I have no idea