|
8 | 8 | from math import log, exp, pi, fsum, sin |
9 | 9 | from test import support |
10 | 10 |
|
11 | | -class TestBasicOps(unittest.TestCase): |
| 11 | +class TestBasicOps: |
12 | 12 | # Superclass with tests common to all generators. |
13 | 13 | # Subclasses must arrange for self.gen to retrieve the Random instance |
14 | 14 | # to be tested. |
@@ -142,7 +142,15 @@ def test_bug_9025(self): |
142 | 142 | k = sum(randrange(6755399441055744) % 3 == 2 for i in range(n)) |
143 | 143 | self.assertTrue(0.30 < k/n < .37, (k/n)) |
144 | 144 |
|
145 | | -class SystemRandom_TestBasicOps(TestBasicOps): |
| 145 | +try: |
| 146 | + random.SystemRandom().random() |
| 147 | +except NotImplementedError: |
| 148 | + SystemRandom_available = False |
| 149 | +else: |
| 150 | + SystemRandom_available = True |
| 151 | + |
| 152 | +@unittest.skipUnless(SystemRandom_available, "random.SystemRandom not available") |
| 153 | +class SystemRandom_TestBasicOps(TestBasicOps, unittest.TestCase): |
146 | 154 | gen = random.SystemRandom() |
147 | 155 |
|
148 | 156 | def test_autoseed(self): |
@@ -239,7 +247,7 @@ def test_randbelow_logic(self, _log=log, int=int): |
239 | 247 | self.assertTrue(2**k > n > 2**(k-1)) # note the stronger assertion |
240 | 248 |
|
241 | 249 |
|
242 | | -class MersenneTwister_TestBasicOps(TestBasicOps): |
| 250 | +class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase): |
243 | 251 | gen = random.Random() |
244 | 252 |
|
245 | 253 | def test_guaranteed_stable(self): |
@@ -542,28 +550,5 @@ def __init__(self, newarg=None): |
542 | 550 | Subclass(newarg=1) |
543 | 551 |
|
544 | 552 |
|
545 | | -def test_main(verbose=None): |
546 | | - testclasses = [MersenneTwister_TestBasicOps, |
547 | | - TestDistributions, |
548 | | - TestModule] |
549 | | - |
550 | | - try: |
551 | | - random.SystemRandom().random() |
552 | | - except NotImplementedError: |
553 | | - pass |
554 | | - else: |
555 | | - testclasses.append(SystemRandom_TestBasicOps) |
556 | | - |
557 | | - support.run_unittest(*testclasses) |
558 | | - |
559 | | - # verify reference counting |
560 | | - import sys |
561 | | - if verbose and hasattr(sys, "gettotalrefcount"): |
562 | | - counts = [None] * 5 |
563 | | - for i in range(len(counts)): |
564 | | - support.run_unittest(*testclasses) |
565 | | - counts[i] = sys.gettotalrefcount() |
566 | | - print(counts) |
567 | | - |
568 | 553 | if __name__ == "__main__": |
569 | | - test_main(verbose=True) |
| 554 | + unittest.main() |
0 commit comments