MCPcopy Index your code
hub / github.com/python/cpython / Test

Class Test

Lib/test/test_syslog.py:14–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12# The only purpose of this test is to verify the code doesn't crash or leak.
13
14class Test(unittest.TestCase):
15
16 def tearDown(self):
17 syslog.closelog()
18
19 def test_openlog(self):
20 syslog.openlog('python')
21 # Issue #6697.
22 self.assertRaises(UnicodeEncodeError, syslog.openlog, '\uD800')
23
24 def test_syslog(self):
25 syslog.openlog('python')
26 syslog.syslog('test message from python test_syslog')
27 syslog.syslog(syslog.LOG_ERR, 'test error from python test_syslog')
28
29 def test_syslog_implicit_open(self):
30 syslog.closelog() # Make sure log is closed
31 syslog.syslog('test message from python test_syslog')
32 syslog.syslog(syslog.LOG_ERR, 'test error from python test_syslog')
33
34 def test_closelog(self):
35 syslog.openlog('python')
36 syslog.closelog()
37 syslog.closelog() # idempotent operation
38
39 def test_setlogmask(self):
40 mask = syslog.LOG_UPTO(syslog.LOG_WARNING)
41 oldmask = syslog.setlogmask(mask)
42 self.assertEqual(syslog.setlogmask(0), mask)
43 self.assertEqual(syslog.setlogmask(oldmask), mask)
44
45 def test_log_mask(self):
46 mask = syslog.LOG_UPTO(syslog.LOG_WARNING)
47 self.assertTrue(mask & syslog.LOG_MASK(syslog.LOG_WARNING))
48 self.assertTrue(mask & syslog.LOG_MASK(syslog.LOG_ERR))
49 self.assertFalse(mask & syslog.LOG_MASK(syslog.LOG_INFO))
50
51 def test_openlog_noargs(self):
52 syslog.openlog()
53 syslog.syslog('test message from python test_syslog')
54
55 @threading_helper.requires_working_threading()
56 def test_syslog_threaded(self):
57 start = threading.Event()
58 stop = False
59 def opener():
60 start.wait(10)
61 i = 1
62 while not stop:
63 syslog.openlog(f'python-test-{i}') # new string object
64 i += 1
65 def logger():
66 start.wait(10)
67 while not stop:
68 syslog.syslog('test message from python test_syslog')
69
70 orig_si = sys.getswitchinterval()
71 support.setswitchinterval(1e-9)

Callers 2

__init__Method · 0.70
test_type_genericMethod · 0.70

Calls

no outgoing calls

Tested by 2

__init__Method · 0.56
test_type_genericMethod · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…