From 861468e8a11b6269c1a4446f331857795d598e4b Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Thu, 18 Jun 2020 09:11:16 -0700 Subject: [PATCH] further improve entropy coverage --- dns/entropy.py | 2 +- tests/test_entropy.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/dns/entropy.py b/dns/entropy.py index fd848418..086bba78 100644 --- a/dns/entropy.py +++ b/dns/entropy.py @@ -113,7 +113,7 @@ pool = EntropyPool() try: system_random = random.SystemRandom() -except Exception: +except Exception: # pragma: no cover system_random = None def random_16(): diff --git a/tests/test_entropy.py b/tests/test_entropy.py index 061f0770..828bb685 100644 --- a/tests/test_entropy.py +++ b/tests/test_entropy.py @@ -37,3 +37,19 @@ class EntropyTestCase(unittest.TestCase): self.assertTrue(0 <= v <= 65535) v = dns.entropy.between(10, 50) self.assertTrue(10 <= v <= 50) + + +class EntropyForcePoolTestCase(unittest.TestCase): + + def setUp(self): + self.saved_system_random = dns.entropy.system_random + dns.entropy.system_random = None + + def tearDown(self): + dns.entropy.system_random = self.saved_system_random + + def test_functions(self): + v = dns.entropy.random_16() + self.assertTrue(0 <= v <= 65535) + v = dns.entropy.between(10, 50) + self.assertTrue(10 <= v <= 50) -- 2.47.3