summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_syslog.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-10-07 17:17:08 (GMT)
committerGitHub <noreply@github.com>2022-10-07 17:17:08 (GMT)
commitcae7d1d7a713f8267daf5e4f2fff5cb1dad02c7c (patch)
tree22139067d2e742e9ea2b904b083f33d4d3baffe2 /Lib/test/test_syslog.py
parent80b3e32d6242c27094dd04c4c3d0c3d3b2889a01 (diff)
downloadcpython-cae7d1d7a713f8267daf5e4f2fff5cb1dad02c7c.zip
cpython-cae7d1d7a713f8267daf5e4f2fff5cb1dad02c7c.tar.gz
cpython-cae7d1d7a713f8267daf5e4f2fff5cb1dad02c7c.tar.bz2
Add more syslog tests (GH-97953)
Diffstat (limited to 'Lib/test/test_syslog.py')
-rw-r--r--Lib/test/test_syslog.py56
1 files changed, 50 insertions, 6 deletions
diff --git a/Lib/test/test_syslog.py b/Lib/test/test_syslog.py
index fe09bd3..2125ec5 100644
--- a/Lib/test/test_syslog.py
+++ b/Lib/test/test_syslog.py
@@ -1,5 +1,9 @@
-from test.support import import_helper
+from test.support import import_helper, threading_helper
syslog = import_helper.import_module("syslog") #skip if not supported
+from test import support
+import sys
+import threading
+import time
import unittest
# XXX(nnorwitz): This test sucks. I don't know of a platform independent way
@@ -8,6 +12,9 @@ import unittest
class Test(unittest.TestCase):
+ def tearDown(self):
+ syslog.closelog()
+
def test_openlog(self):
syslog.openlog('python')
# Issue #6697.
@@ -18,22 +25,59 @@ class Test(unittest.TestCase):
syslog.syslog('test message from python test_syslog')
syslog.syslog(syslog.LOG_ERR, 'test error from python test_syslog')
+ def test_syslog_implicit_open(self):
+ syslog.closelog() # Make sure log is closed
+ syslog.syslog('test message from python test_syslog')
+ syslog.syslog(syslog.LOG_ERR, 'test error from python test_syslog')
+
def test_closelog(self):
syslog.openlog('python')
syslog.closelog()
+ syslog.closelog() # idempotent operation
def test_setlogmask(self):
- syslog.setlogmask(syslog.LOG_DEBUG)
+ mask = syslog.LOG_UPTO(syslog.LOG_WARNING)
+ oldmask = syslog.setlogmask(mask)
+ self.assertEqual(syslog.setlogmask(0), mask)
+ self.assertEqual(syslog.setlogmask(oldmask), mask)
def test_log_mask(self):
- syslog.LOG_MASK(syslog.LOG_INFO)
-
- def test_log_upto(self):
- syslog.LOG_UPTO(syslog.LOG_INFO)
+ mask = syslog.LOG_UPTO(syslog.LOG_WARNING)
+ self.assertTrue(mask & syslog.LOG_MASK(syslog.LOG_WARNING))
+ self.assertTrue(mask & syslog.LOG_MASK(syslog.LOG_ERR))
+ self.assertFalse(mask & syslog.LOG_MASK(syslog.LOG_INFO))
def test_openlog_noargs(self):
syslog.openlog()
syslog.syslog('test message from python test_syslog')
+ @threading_helper.requires_working_threading()
+ def test_syslog_threaded(self):
+ start = threading.Event()
+ stop = False
+ def opener():
+ start.wait(10)
+ i = 1
+ while not stop:
+ syslog.openlog(f'python-test-{i}') # new string object
+ i += 1
+ def logger():
+ start.wait(10)
+ while not stop:
+ syslog.syslog('test message from python test_syslog')
+
+ orig_si = sys.getswitchinterval()
+ support.setswitchinterval(1e-9)
+ try:
+ threads = [threading.Thread(target=opener)]
+ threads += [threading.Thread(target=logger) for k in range(10)]
+ with threading_helper.start_threads(threads):
+ start.set()
+ time.sleep(0.1)
+ stop = True
+ finally:
+ sys.setswitchinterval(orig_si)
+
+
if __name__ == "__main__":
unittest.main()