简体   繁体   English

如何为我的 Python 脚本生成测试数据?

[英]How do I generate test data for my Python script?

A equation takes values in the following form:等式采用以下形式的值:

   x = [0x02,0x00]  # which is later internally converted to in the called function to  0x300
   y = [0x01, 0xFF]
   z = [0x01, 0x0F]

How do I generate a series of test values for this function?如何为这个 function 生成一系列测试值? for instance I want to send a 100 odd values from a for loop例如,我想从 for 循环中发送 100 个奇数值

for i in range(0,300):
   # where a,b are derived for a range
   x = [a,b]

My question was a bit unclear so please let my clarify.我的问题有点不清楚,所以请让我澄清一下。 what I wanted to ask how I can do x =[a,b] generate different values for a,b我想问我怎么做x =[a,b]a,b生成不同的值

use generators:使用生成器:

def gen_xyz( max_iteration ):
    for i in xrange( 0, max_iteration ):
       # code which will generate next ( x, y, z )
       yield ( x, y, z ) 

for x, y, z in gen_xyz( 1000 ):
  f( x, y, z )

The hex() function?十六进制()function?

import random
for i in range(10):
    a1, a2 = random.randint(1,100), random.randint(1,100)
    x = [hex(a1), hex(a2)]
    print x

..outputs something similar to.. ..输出类似于..的东西

['0x21', '0x4f']
['0x59', '0x5c']
['0x61', '0x40']
['0x57', '0x45']
['0x1a', '0x11']
['0x4c', '0x49']
['0x40', '0x1b']
['0x1f', '0x7']
['0x8', '0x2b']
['0x1e', '0x13']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为我的 python 脚本创建自动化测试? - How do I create an automated test for my python script? 如何运行 python 脚本来测试我自己的 shell? - How do I run a python script to test my own shell? 如何在单个python脚本中设置测试数据和测试用例 - How do I set up the test data and the test cases in a single python script 如何使用python为Web元素生成Xpath(在脚本运行时)? - How do I generate Xpath (at run time in my script) for a web element using python? 在 PowerBI 中,如何使用 Python 脚本从数据库中获取最新数据? - In PowerBI how do I fetch the most recent data from my database with my Python script? 如何通过Python机器学习模型运行测试数据? - How do I run test data through my Python Machine Learning Model? Python-我如何编码我的Python脚本 - Python - how do i encode my python script Python:如何在我的测试套件中制作临时文件? - Python: How do I make temporary files in my test suite? ModuleNotFoundError - 如何安装 Python3 包以便执行我的用户数据脚本? - ModuleNotFoundError - How do I install Python3 packages so my my user-data script get's executed? 如何从我的 Python Spark 脚本登录 - How do I log from my Python Spark script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM