Last active
August 7, 2018 23:09
-
-
Save jasimmonsv/0139fa24ceabe2d06a25f8abe9dfb98c to your computer and use it in GitHub Desktop.
randomization artifacts for unittests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import string | |
def rand_string(rrange=25): | |
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(rrange)) | |
def rand_email(): | |
return '{}@{}.{}'.format(rand_string(10), rand_string(7), rand_string(3)) | |
def rand_int(rmin=30000, rmax=70000): | |
return random.randint(rmin, rmax) | |
def rand_datetime(c=None): | |
if c is None: | |
c = datetime.datetime.utcnow() | |
else: | |
c = datetime.datetime.strptime(c, '%Y-%m-%d %H:%M:%S.%f') | |
return str(c + datetime.timedelta(minutes=random.randrange(60), | |
hours=random.randrange(24), | |
days=random.randrange(1000))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment