def number(self, chance=None, optional_state=None, mandatory=None): """ optionally return a random number from chance if option is dismissed return value is 0 if option is mandatory return value is either 1 or highest value :param chance: tuple of int pair: (1, 2) -> 1:2 :type chance: (int, int) :param optional_state: boolean :param mandatory: boolean :rtype: int """ if mandatory is None: mandatory = self.mandatory if optional_state is None: optional_state = self.optional_state elif optional_state is False: if mandatory is True: optional_state = True else: return 0 if chance is None: chance = self.chance if chance[1] == 0: if mandatory is True: return 1 else: return 0 if optional_state is True: if mandatory is True: return chance[1] else: return random_number(*chance) return 0
def __call__(self): user = { "name": create_random.string(length=random_number(3, 30)), "email": create_random.string(length=random_number(3, 30)), "username": create_random.string(length=random_number(3, 30)), "password": create_random.string(length=random_number(3, 30)), "re_password": create_random.string(length=random_number(3, 30)), } self.register_name().send_keys(user['name']) self.register_email().send_keys(user['email']) self.register_username().send_keys(user['username']) self.register_password().send_keys(user['password']) self.register_re_password().send_keys(user['re_password']) self.register_submit().click() self.wait_until_page_loads() return user
def get(name): for i in range(Dependencies.max_read_tries): try: with open(Dependencies.path + s + name) as f: return f.read() except Exception as e: if i + 1 == Dependencies.max_read_tries: raise e time.sleep(random_number(1, 1000) * 0.0001)
def set(name, status): for i in range(Dependencies.max_read_tries): try: with open(Dependencies.path + s + name, 'w+') as f: f.write(str(status)) return except Exception as e: if i + 1 == Dependencies.max_read_tries: raise e time.sleep(random_number(1, 1000) * 0.0001)
def test_random_utils(n): n = random_number(1, 100) assert 0 < n < 101 s = " goGOgoRangers " r = random_string(s, n) assert condition.any_in_any(s, r)