Commit 3e4a98bd authored by Ezio Melotti's avatar Ezio Melotti

#17789: test_random now works with unittest test discovery. Patch by Zachary Ware.

parent aaa5d1c5
...@@ -8,7 +8,7 @@ import warnings ...@@ -8,7 +8,7 @@ import warnings
from math import log, exp, pi, fsum, sin from math import log, exp, pi, fsum, sin
from test import support from test import support
class TestBasicOps(unittest.TestCase): class TestBasicOps:
# Superclass with tests common to all generators. # Superclass with tests common to all generators.
# Subclasses must arrange for self.gen to retrieve the Random instance # Subclasses must arrange for self.gen to retrieve the Random instance
# to be tested. # to be tested.
...@@ -142,7 +142,15 @@ class TestBasicOps(unittest.TestCase): ...@@ -142,7 +142,15 @@ class TestBasicOps(unittest.TestCase):
k = sum(randrange(6755399441055744) % 3 == 2 for i in range(n)) k = sum(randrange(6755399441055744) % 3 == 2 for i in range(n))
self.assertTrue(0.30 < k/n < .37, (k/n)) self.assertTrue(0.30 < k/n < .37, (k/n))
class SystemRandom_TestBasicOps(TestBasicOps): try:
random.SystemRandom().random()
except NotImplementedError:
SystemRandom_available = False
else:
SystemRandom_available = True
@unittest.skipUnless(SystemRandom_available, "random.SystemRandom not available")
class SystemRandom_TestBasicOps(TestBasicOps, unittest.TestCase):
gen = random.SystemRandom() gen = random.SystemRandom()
def test_autoseed(self): def test_autoseed(self):
...@@ -239,7 +247,7 @@ class SystemRandom_TestBasicOps(TestBasicOps): ...@@ -239,7 +247,7 @@ class SystemRandom_TestBasicOps(TestBasicOps):
self.assertTrue(2**k > n > 2**(k-1)) # note the stronger assertion self.assertTrue(2**k > n > 2**(k-1)) # note the stronger assertion
class MersenneTwister_TestBasicOps(TestBasicOps): class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase):
gen = random.Random() gen = random.Random()
def test_guaranteed_stable(self): def test_guaranteed_stable(self):
...@@ -542,28 +550,5 @@ class TestModule(unittest.TestCase): ...@@ -542,28 +550,5 @@ class TestModule(unittest.TestCase):
Subclass(newarg=1) Subclass(newarg=1)
def test_main(verbose=None):
testclasses = [MersenneTwister_TestBasicOps,
TestDistributions,
TestModule]
try:
random.SystemRandom().random()
except NotImplementedError:
pass
else:
testclasses.append(SystemRandom_TestBasicOps)
support.run_unittest(*testclasses)
# verify reference counting
import sys
if verbose and hasattr(sys, "gettotalrefcount"):
counts = [None] * 5
for i in range(len(counts)):
support.run_unittest(*testclasses)
counts[i] = sys.gettotalrefcount()
print(counts)
if __name__ == "__main__": if __name__ == "__main__":
test_main(verbose=True) unittest.main()
...@@ -120,6 +120,9 @@ Tests ...@@ -120,6 +120,9 @@ Tests
- Issue #12820: add tests for the xml.dom.minicompat module. - Issue #12820: add tests for the xml.dom.minicompat module.
Patch by John Chandler and Phil Connell. Patch by John Chandler and Phil Connell.
- Issue #17789: test_random now works with unittest test discovery.
Patch by Zachary Ware.
- Issue #17779: test_osx_env now works with unittest test discovery. - Issue #17779: test_osx_env now works with unittest test discovery.
Patch by Zachary Ware. Patch by Zachary Ware.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment