]> granicus.if.org Git - python/commitdiff
Silence getcheckinterval()-related warnings in the test suite
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 13 Nov 2009 22:19:19 +0000 (22:19 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 13 Nov 2009 22:19:19 +0000 (22:19 +0000)
Lib/test/test_sys.py
Lib/test/test_threading.py

index 4a08ba8acfde92382623954515435504fa327d2d..585b6ec50af864291c706a3c0ccc5ec2a722d465 100644 (file)
@@ -4,6 +4,7 @@ import sys, io, os
 import struct
 import subprocess
 import textwrap
+import warnings
 
 # count the number of test runs, used to create unique
 # strings to intern in test_intern()
@@ -148,11 +149,13 @@ class SysModuleTest(unittest.TestCase):
     # testing sys.setprofile() is done in test_profile.py
 
     def test_setcheckinterval(self):
-        self.assertRaises(TypeError, sys.setcheckinterval)
-        orig = sys.getcheckinterval()
-        for n in 0, 100, 120, orig: # orig last to restore starting state
-            sys.setcheckinterval(n)
-            self.assertEquals(sys.getcheckinterval(), n)
+        with warnings.catch_warnings():
+            warnings.simplefilter("ignore")
+            self.assertRaises(TypeError, sys.setcheckinterval)
+            orig = sys.getcheckinterval()
+            for n in 0, 100, 120, orig: # orig last to restore starting state
+                sys.setcheckinterval(n)
+                self.assertEquals(sys.getcheckinterval(), n)
 
     def test_switchinterval(self):
         self.assertRaises(TypeError, sys.setswitchinterval)
index c5d8d79e35445a362f99830b22df9e8851fc86db..0b370591a4e75f13ebb3dbc1bb42a537309e24f3 100644 (file)
@@ -342,12 +342,10 @@ class ThreadTests(BaseTestCase):
         # Try hard to trigger #1703448: a thread is still returned in
         # threading.enumerate() after it has been join()ed.
         enum = threading.enumerate
-        old_interval = sys.getcheckinterval()
+        old_interval = sys.getswitchinterval()
         try:
             for i in range(1, 100):
-                # Try a couple times at each thread-switching interval
-                # to get more interleavings.
-                sys.setcheckinterval(i // 5)
+                sys.setswitchinterval(i * 0.0002)
                 t = threading.Thread(target=lambda: None)
                 t.start()
                 t.join()
@@ -355,7 +353,7 @@ class ThreadTests(BaseTestCase):
                 self.assertFalse(t in l,
                     "#1703448 triggered after %d trials: %s" % (i, l))
         finally:
-            sys.setcheckinterval(old_interval)
+            sys.setswitchinterval(old_interval)
 
     def test_no_refcycle_through_target(self):
         class RunSelfFunction(object):