]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
adding max_amount to realistic.names generator
authorSteven Berler <steven.berler@dreamhost.com>
Fri, 22 Jul 2011 17:55:58 +0000 (10:55 -0700)
committerTommi Virtanen <tommi.virtanen@dreamhost.com>
Tue, 26 Jul 2011 21:20:28 +0000 (14:20 -0700)
Set max_amount to limit the number of names yeilded by the generator.

s3tests/realistic.py

index 325113656643eae7c6840b720876f0983b27385a..458fa08beb9b5503a6acc6a896f1405a7bc4ccb2 100644 (file)
@@ -137,12 +137,13 @@ def files(mean, stddev, seed=None):
                 break
         yield RandomContentFile(size=size, seed=rand.getrandbits(32))
 
-def names(mean, stddev, charset=None, seed=None):
+def names(mean, stddev, charset=None, seed=None, max_amount=None):
     """
     Yields strings that are somewhat plausible as file names, where
     the lenght of each filename follows the normal distribution with
     `mean` and `stddev`.
     """
+    count = 0
     if charset is None:
         charset = string.ascii_lowercase
     rand = random.Random(seed)
@@ -154,6 +155,11 @@ def names(mean, stddev, charset=None, seed=None):
         name = ''.join(rand.choice(charset) for _ in xrange(length))
         yield name
 
+        count += 1
+        if count == max_amount:
+            return
+
+
 def files_varied(groups, unlimited=False):
     """ Yields a weighted-random selection of file-like objects. """
     # Quick data type sanity.