summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/test/util.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-04-06 13:07:17 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-04-06 13:07:17 -0400
commit52c0f5691377e7846bf80ce6f25a4f3b11bf5a88 (patch)
tree5b09f74f56a54ad821303b5d8a61f9985a40c59b /lib/sqlalchemy/test/util.py
parent8ebc714f6b4c07a8540d228d6a35190c6cfe05c0 (diff)
downloadsqlalchemy-52c0f5691377e7846bf80ce6f25a4f3b11bf5a88.tar.gz
a RandomSet implementation useful for swapping into topological
Diffstat (limited to 'lib/sqlalchemy/test/util.py')
-rw-r--r--lib/sqlalchemy/test/util.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/sqlalchemy/test/util.py b/lib/sqlalchemy/test/util.py
index 8a3a0e745..cd73b44d0 100644
--- a/lib/sqlalchemy/test/util.py
+++ b/lib/sqlalchemy/test/util.py
@@ -2,6 +2,7 @@ from sqlalchemy.util import jython, function_named
import gc
import time
+import random
if jython:
def gc_collect(*args):
@@ -50,4 +51,17 @@ def round_decimal(value, prec):
# can also use shift() here but that is 2.6 only
return (value * decimal.Decimal("1" + "0" * prec)).to_integral(decimal.ROUND_FLOOR) / \
pow(10, prec)
- \ No newline at end of file
+
+class RandomSet(set):
+ def __iter__(self):
+ l = list(set.__iter__(self))
+ random.shuffle(l)
+ return iter(l)
+
+ def pop(self):
+ index = random.randint(0, len(self) - 1)
+ item = list(set.__iter__(self))[index]
+ self.remove(item)
+ return item
+
+ \ No newline at end of file