← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~mbp/launchpad/less-randomness into lp:launchpad

 

Martin Pool has proposed merging lp:~mbp/launchpad/less-randomness into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~mbp/launchpad/less-randomness/+merge/82613

As an update to https://code.launchpad.net/~bac/launchpad/bug-891641/+merge/82544 this actually saves and restores the prng state, rather than randomizing it, when Test_create_token runs.
-- 
https://code.launchpad.net/~mbp/launchpad/less-randomness/+merge/82613
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~mbp/launchpad/less-randomness into lp:launchpad.
=== modified file 'lib/canonical/launchpad/tests/test_token_creation.py'
--- lib/canonical/launchpad/tests/test_token_creation.py	2011-11-17 14:42:51 +0000
+++ lib/canonical/launchpad/tests/test_token_creation.py	2011-11-17 23:24:25 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009, 2011 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -27,10 +27,8 @@
     layer = DatabaseFunctionalLayer
 
     def test_token_uniqueness(self):
-        # Since the prng will be seeded in this test it is important we clean
-        # up by calling seed with no parameters, which will use OS-provided
-        # entropy if available or use the system clock.
-        self.addCleanup(random.seed)
+        orig_state = random.getstate()
+        self.addCleanup(lambda: random.setstate(orig_state))
         # Calling create_unique_token_for_table() twice with the same
         # random.seed() will generate two identical tokens, as the token was
         # never inserted in the table.