From 44cb2f256e643784f393404820f8985f04876678 Mon Sep 17 00:00:00 2001 From: Wesley Spikes Date: Mon, 18 Jul 2011 15:26:03 -0700 Subject: [PATCH] Adding unlimited=bool to files_varied -- if set to true, it will never issue StopIteration --- s3tests/realistic.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/s3tests/realistic.py b/s3tests/realistic.py index f4a3ddf..64c406c 100644 --- a/s3tests/realistic.py +++ b/s3tests/realistic.py @@ -160,7 +160,7 @@ def names(mean, stddev, charset=None, seed=None): name = ''.join(rand.choice(charset) for _ in xrange(length)) yield name -def files_varied(groups): +def files_varied(groups, unlimited=False): """ Yields a weighted-random selection of file-like objects. """ # Quick data type sanity. assert groups and isinstance(groups, (list, tuple)) @@ -193,12 +193,13 @@ def files_varied(groups): num -= file_set.num continue - total_num -= 1 - file_set.num -= 1 + if not unlimited: + total_num -= 1 + file_set.num -= 1 - # None left in this set! - if file_set.num == 0: - file_sets.remove(file_set) + # None left in this set! + if file_set.num == 0: + file_sets.remove(file_set) ok = 1 yield next(file_set.files)