-1
我使用简单的测试框架将* .xlsx文件的内容转换为硒浏览器测试。这允许高层次的抽象,但是由于它是一个二进制文件,所以很讨厌在git中工作。是否有办法强制自动生成的文件与触发其生成的其余提交一起提交?
excel的测试文件的格式是:
Column A -> Action
Column B -> Identity (which text field, etc)
Column C onwards -> Value
我写了下面的代码,成功地转换Excel文件到一个文本文件(*以.json),本质上只是一个列表的列表(使订单保持不变,并且不会引入额外的关键字)。
#!/usr/bin/env python
"""
This script takes a GUI test in xlsx format and outputs a text interpretation.
"""
import argparse
import json
from openpyxl import load_workbook
from openpyxl.cell import get_column_letter
def main(xlsx_test):
ws = load_workbook(filename=xlsx_test, data_only=True).active
col_size = len(ws.column_dimensions)
row_size = len(ws.row_dimensions)
full_document = []
for col in xrange(2, col_size):
col_letter = get_column_letter(col + 1)
test_document = []
for row in xrange(row_size):
cell_reference = col_letter + str(row + 1)
cell_value = ws[cell_reference].value
if cell_value:
action = ws['A' + str(row + 1)].value
identity = ws['B' + str(row + 1)].value
if not action:
action = ""
if not identity:
identity = ""
test_item = [action, identity, cell_value]
test_document.append(test_item)
if test_document:
full_document.append(test_document)
with open(xlsx_test + '.json', 'w') as outfile:
json.dump(full_document, outfile, indent=4)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate text verion of tests')
test_file = parser.add_argument(
'--input',
type=str,
nargs='?',
help='the file to generate text version of tests from'
)
args = parser.parse_args()
if args.input is None:
print '''No file selected'''
else:
main(args.input)
要运行它,我将执行在bash脚本如下:
python /path/to/this/script.py --input='/path/to/test.xlsx'
我想的文本文件,其产生与XLSX二进制只是让我们得到了一个一起被提交git改变历史。
我一直在阅读预先提交的钩子(我很乐意在每个贡献者的机器上设置,但我很努力确定它是否将一个额外的生成文件包含到提交中。将是伟大的,因为我不知道该怎么试试此刻
我还必须弄清楚我是否可以遍历提交文件列表中的扩展名为* .xlsx,并将路径作为上面的python脚本的参数,在一个循环中,我问的是这样做的吗?