Some random data is needed during the test, and a string module in Python is used to record
#!/usr/bin/python#Coding:utf-8"""@author: bingo.he @file: data_factory.py @time: 2017/12/21"""ImportSocketImportstructImportstringImportRandomdefRandom_phoneno ():"""get random numbers""" return '1'+"'. Join (Random.choice (string.digits) forIinchRange (10))defrandom_upper_code (length):"""get the random code of uppercase and digital""" return "'. Join (Random.choice (string.ascii_uppercase + string.digits) forIinchrange (length))defrandom_lower_code (length):"""get a random code for lowercase letters and numbers""" return "'. Join (Random.choice (string.ascii_lowercase + string.digits) forIinchrange (length))defrandom_ip ():"""get random IP"""Random_ip_pool= ['202.69.19.222/0'] Str_ip= Random_ip_pool[random.randint (0, Len (random_ip_pool)-1)] Str_ip_addr= Str_ip.split ('/') [0] Str_ip_mask= Str_ip.split ('/') [1] Ip_addr= Struct.unpack ('>i', Socket.inet_aton (STR_IP_ADDR)) [0] Mask= 0x0 forIinchRange (31-int, str_ip_mask), 1): Mask= Mask | (1 <<i) ip_addr_min= Ip_addr & (Mask & 0xFFFFFFFF) Ip_addr_max= Ip_addr | (~mask & 0xFFFFFFFF) returnSocket.inet_ntoa (Struct.pack ('>i', Random.randint (Ip_addr_min, Ip_addr_max)))
PS: Bo Main company Use the mobile phone number check rule is 1, 11 digits can pass the calibration
Python module learns the test data of string