提交框架
This commit is contained in:
parent
2d7d232af0
commit
a1f389f255
|
@ -0,0 +1,10 @@
|
|||
changes log
|
||||
======================================
|
||||
|
||||
------------------------------
|
||||
0.0.1 2023-10-25
|
||||
|
||||
1.开始规划,先调研一下怎么做
|
||||
2.提交基础框架
|
||||
|
||||
[mh]
|
|
@ -0,0 +1,5 @@
|
|||
include README.txt
|
||||
include requirements.txt tox.ini
|
||||
recursive-include test *.txt *.py
|
||||
recursive-include *.txt *.py *.tmpl
|
||||
recursive-include bin *.*
|
|
@ -0,0 +1,27 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import sys
|
||||
import site
|
||||
|
||||
# set path
|
||||
py_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
parent_dir = os.path.dirname(py_dir)
|
||||
|
||||
# print parent_dir
|
||||
# if os.path.isdir(os.path.join(parent_dir, "delegate")):
|
||||
# sys.path.append(parent_dir)
|
||||
|
||||
libdir = os.path.join(parent_dir, "lib")
|
||||
# print libdir
|
||||
if os.path.isdir(libdir):
|
||||
old_len = len(sys.path)
|
||||
new_sys_path = []
|
||||
site.addsitedir(libdir) # @UndefinedVariable
|
||||
for item in sys.path[old_len:]:
|
||||
new_sys_path.append(item)
|
||||
sys.path.remove(item)
|
||||
sys.path[:0] = new_sys_path
|
||||
|
||||
# set cwd
|
||||
os.chdir(parent_dir)
|
|
@ -0,0 +1,180 @@
|
|||
# -*- coding:utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
import io
|
||||
import _load
|
||||
import shutil
|
||||
import time
|
||||
import xlrd
|
||||
|
||||
from fnmatch import fnmatch
|
||||
from jinja2 import Environment, PackageLoader
|
||||
#处理py2的编码和字典顺序的问题
|
||||
#from __future__ import unicode_literals --必须放在第一个
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
class xl2fe:
|
||||
|
||||
def __init__(self):
|
||||
HERE = os.path.dirname(__file__)
|
||||
TOP = os.path.join(HERE, "..")
|
||||
self.templates_dir = os.path.join(TOP, "templates")
|
||||
self.output_dir = os.path.join(TOP, "output")
|
||||
if os.path.exists(self.output_dir):
|
||||
shutil.rmtree(self.output_dir)
|
||||
time.sleep(2)
|
||||
os.mkdir(self.output_dir)
|
||||
self.excel_files_dir = os.path.join(TOP, "excel_files")
|
||||
self.xlsx_sheets = {"封面": "00_home_index.feature",
|
||||
"统计表": "01_statistics.feature",
|
||||
"基础功能测试用例": "02_function.feature",
|
||||
"异常测试": "03_abnormality_test.feature",
|
||||
"性能测试": "04_performance.feature"
|
||||
}
|
||||
|
||||
def read_xlsx(self):
|
||||
"""
|
||||
指定的sheet页,对内容进行处理
|
||||
"""
|
||||
#获取所有的数据
|
||||
work_book = xlrd.open_workbook(self.xlsx_file_path)
|
||||
#为了让py2字典的顺序与py3一致
|
||||
all_data = OrderedDict()
|
||||
for i, sheet_obj in enumerate(work_book.sheets()):
|
||||
all_data[sheet_obj.name] = [sheet_obj.row_values(row)
|
||||
for row in range(sheet_obj.nrows)]
|
||||
#按sheet页处理
|
||||
for sheet_name, self.feature_name in self.xlsx_sheets.items():
|
||||
datas = all_data[sheet_name]
|
||||
# 处理数据
|
||||
self.context = OrderedDict()
|
||||
self.context = xl2fe.get_feature_data(self, datas, sheet_name)
|
||||
# 渲染模板
|
||||
xl2fe.feature_tpl(self)
|
||||
|
||||
def get_feature_data(self, datas, sheet_name):
|
||||
"""
|
||||
根据sheet_name 处理数据
|
||||
"""
|
||||
context_temp = OrderedDict()
|
||||
|
||||
if sheet_name == "封面":
|
||||
context_temp['project'] = self.project
|
||||
context_temp['sheet_name'] = sheet_name
|
||||
# 处理更新记录
|
||||
Scenario_table = []
|
||||
lines = datas[4:]
|
||||
for line in lines:
|
||||
cells = line
|
||||
# 处理换行
|
||||
for index, cell in enumerate(cells):
|
||||
#因为py2的编码问题,不能判断str
|
||||
#isinstance(cell,str)
|
||||
if not isinstance(cell,(int,float)):
|
||||
cells[index] = cell.replace('\n', '\\n')
|
||||
Scenario_table.append(cells)
|
||||
context_temp['Scenario_table'] = Scenario_table
|
||||
|
||||
elif sheet_name == "统计表":
|
||||
context_temp['project'] = self.project
|
||||
context_temp['sheet_name'] = sheet_name
|
||||
|
||||
elif sheet_name == "基础功能测试用例":
|
||||
context_temp['project'] = self.project
|
||||
context_temp['sheet_name'] = sheet_name
|
||||
# 处理基础测试用例中的数据
|
||||
Scenario_table = OrderedDict()
|
||||
lines = datas[2:]
|
||||
for line in lines:
|
||||
cells = line[0:9]
|
||||
#补全合并单元格的信息
|
||||
#模块
|
||||
if cells[0]:
|
||||
model = cells[0]
|
||||
else:
|
||||
cells[0] = model
|
||||
#子模块
|
||||
if cells[1]:
|
||||
sub_model = cells[1]
|
||||
else:
|
||||
cells[1] = sub_model
|
||||
#处理编号
|
||||
if '-ST-' in cells[2]:
|
||||
cells[2] = 'NUM'
|
||||
# 处理换行
|
||||
for index, cell in enumerate(cells):
|
||||
if not isinstance(cell,(int,float)):
|
||||
cells[index] = cell.replace('\n', '\\n')
|
||||
#以模块为单位存储
|
||||
if model not in list(Scenario_table.keys()):
|
||||
Scenario_table[model] = []
|
||||
Scenario_table[model].append(cells)
|
||||
context_temp['Scenario_table'] = Scenario_table
|
||||
|
||||
elif sheet_name == "异常测试":
|
||||
context_temp['project'] = self.project
|
||||
context_temp['sheet_name'] = sheet_name
|
||||
# 处理更新记录
|
||||
Scenario_table = []
|
||||
lines = datas[4:]
|
||||
for line in lines:
|
||||
cells = line[0:8]
|
||||
cells[0] = 'NUM'
|
||||
# 处理换行
|
||||
for index, cell in enumerate(cells):
|
||||
if not isinstance(cell,(int,float)):
|
||||
cells[index] = cell.replace('\n', '\\n')
|
||||
Scenario_table.append(cells)
|
||||
context_temp['Scenario_table'] = Scenario_table
|
||||
|
||||
elif sheet_name == "性能测试":
|
||||
context_temp['project'] = self.project
|
||||
context_temp['sheet_name'] = sheet_name
|
||||
|
||||
return context_temp
|
||||
|
||||
def feature_tpl(self):
|
||||
"""
|
||||
拿处理后的数据来渲染指定的模板
|
||||
"""
|
||||
# 读取模板
|
||||
tpl = os.path.join(self.templates_dir, self.feature_name + ".j2")
|
||||
tpl_data = io.open(tpl, encoding="utf-8").read()
|
||||
# 渲染模板
|
||||
env = Environment()
|
||||
text = env.from_string(tpl_data).render(self.context)
|
||||
# 保存文件
|
||||
xl2fe.save_feature(self, text)
|
||||
|
||||
def save_feature(self, text):
|
||||
"""
|
||||
保存渲染好的模板为feature文件
|
||||
"""
|
||||
#为了解决windows换行符的问题转为二进制,主要是由于py2中open不支持newline参数
|
||||
#py2没有bytes()函数
|
||||
#text_bytes = bytes(text,'utf-8')
|
||||
text_bytes = text.encode('utf-8')
|
||||
feature_path = os.path.join(self.project_dir, self.feature_name)
|
||||
# 写入文件
|
||||
with open(feature_path, 'wb+') as fp:
|
||||
fp.write(text_bytes)
|
||||
|
||||
def main(self):
|
||||
xlsx_files = os.listdir(self.excel_files_dir)
|
||||
for xlsx_file in xlsx_files:
|
||||
# 排除掉非xlsx结尾的文件
|
||||
if not fnmatch(xlsx_file, "*.xlsx"):
|
||||
continue
|
||||
self.project = xlsx_file.split('_')[0]
|
||||
self.xlsx_file_path = os.path.join(self.excel_files_dir, xlsx_file)
|
||||
# 按项目存放
|
||||
self.project_dir = os.path.join(self.output_dir, self.project)
|
||||
os.mkdir(self.project_dir)
|
||||
|
||||
xl2fe.read_xlsx(self)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_env = xl2fe()
|
||||
test_env.main()
|
|
@ -0,0 +1,101 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
create zip 安装包
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os.path
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
|
||||
def _copytree(src, dst, ignore=None):
|
||||
|
||||
names = os.listdir(src)
|
||||
if ignore is not None:
|
||||
ignored_names = ignore(src, names)
|
||||
else:
|
||||
ignored_names = set()
|
||||
try:
|
||||
os.makedirs(dst)
|
||||
except Exception:
|
||||
pass
|
||||
errors = []
|
||||
for name in names:
|
||||
if name in ignored_names:
|
||||
continue
|
||||
srcname = os.path.join(src, name)
|
||||
dstname = os.path.join(dst, name)
|
||||
try:
|
||||
if os.path.isdir(srcname):
|
||||
shutil.copytree(srcname, dstname, ignore=ignore)
|
||||
else:
|
||||
# Will raise a SpecialFileError for unsupported file types
|
||||
shutil.copy2(srcname, dstname)
|
||||
# catch the Error from the recursive copytree so that we can
|
||||
# continue with other files
|
||||
except shutil.Error as err:
|
||||
errors.extend(err.args[0])
|
||||
except EnvironmentError as why:
|
||||
errors.append((srcname, dstname, str(why)))
|
||||
try:
|
||||
shutil.copystat(src, dst)
|
||||
except OSError as why:
|
||||
if WindowsError is not None and isinstance(why, WindowsError):
|
||||
# Copying file access times may fail on Windows
|
||||
pass
|
||||
else:
|
||||
errors.extend((src, dst, str(why)))
|
||||
if errors:
|
||||
raise shutil.Error(errors)
|
||||
|
||||
|
||||
def _zip_file(target_dir):
|
||||
root_dir = os.path.dirname(target_dir)
|
||||
os.chdir(root_dir)
|
||||
shutil.make_archive(os.path.basename(target_dir), format="gztar",
|
||||
base_dir=os.path.basename(target_dir))
|
||||
|
||||
|
||||
def _strip_py(py_dir):
|
||||
for base, dirs, files in os.walk(py_dir):
|
||||
for name in files:
|
||||
if name.endswith('.py'):
|
||||
path = os.path.join(base, name)
|
||||
logging.debug("Deleting %s", path)
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
def main():
|
||||
# src_dir = sys.argv[1]
|
||||
site_pacakge_dir = sys.argv[2]
|
||||
target_dir = sys.argv[3]
|
||||
|
||||
top_dir = sys.argv[4]
|
||||
|
||||
shutil.rmtree(target_dir, ignore_errors=True)
|
||||
os.makedirs(target_dir)
|
||||
|
||||
for dir in ("bin", "etc"):
|
||||
_copytree(os.path.join(top_dir, dir),
|
||||
os.path.join(target_dir, dir))
|
||||
|
||||
shutil.copy2(os.path.join(top_dir, "README.txt"),
|
||||
os.path.join(target_dir, "README.txt"))
|
||||
|
||||
target_lib_dir = os.path.join(target_dir, "lib")
|
||||
_copytree(site_pacakge_dir, target_lib_dir)
|
||||
|
||||
_zip_file(target_dir)
|
||||
|
||||
print("")
|
||||
print("output dir %s" %(target_dir))
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except Exception:
|
||||
logging.exception("main except")
|
||||
sys.exit(1)
|
|
@ -0,0 +1,2 @@
|
|||
faker
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
install_requires=[]
|
||||
|
||||
for line in open('requirements.txt'):
|
||||
install_requires.append(line.strip())
|
||||
|
||||
setup(name='dataCreating',
|
||||
version='0.0.1',
|
||||
description='',
|
||||
long_description="""\
|
||||
""",
|
||||
# Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers # nopep8
|
||||
classifiers=[
|
||||
"Programming Language :: Python",
|
||||
],
|
||||
keywords='',
|
||||
author='mh',
|
||||
author_email='menghan@unary.com.cn',
|
||||
url='',
|
||||
license='GPL',
|
||||
packages=find_packages(exclude=["ez_setup","test.*", "test"]),
|
||||
namespace_packages=[],
|
||||
include_package_data=True,
|
||||
test_suite='nose.collector',
|
||||
zip_safe=False,
|
||||
install_requires=install_requires,
|
||||
entry_points="""
|
||||
# -*- Entry points: -*-
|
||||
""",
|
||||
)
|
|
@ -0,0 +1,44 @@
|
|||
[tox]
|
||||
envlist = devenv
|
||||
minversion = 1.6
|
||||
skipsdist = False
|
||||
|
||||
[testenv]
|
||||
install_command = pip install --force-reinstall -U {opts} {packages}
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
NOSE_WITH_COVERAGE=1
|
||||
NOSE_COVER_BRANCHES=1
|
||||
deps =
|
||||
-r{toxinidir}/requirements.txt
|
||||
|
||||
|
||||
[testenv:devenv]
|
||||
envdir = devenv
|
||||
basepython = python3
|
||||
usedevelop = True
|
||||
commands =
|
||||
{envpython} {toxinidir}/bin/e2f.py
|
||||
|
||||
[testenv:devenv2]
|
||||
envdir = devenv2
|
||||
basepython = python2.7
|
||||
usedevelop = True
|
||||
|
||||
|
||||
[testenv:py3-release]
|
||||
basepython = python3
|
||||
deps =
|
||||
-r{toxinidir}/requirements.txt
|
||||
|
||||
commands =
|
||||
{envpython} {toxinidir}/release.py {envdir} {envsitepackagesdir} {toxinidir}/build/excel2feature {toxinidir}
|
||||
|
||||
|
||||
[testenv:py27-release]
|
||||
basepython = python2.7
|
||||
deps =
|
||||
-r{toxinidir}/requirements.txt
|
||||
|
||||
commands =
|
||||
{envpython} {toxinidir}/release.py {envdir} {envsitepackagesdir} {toxinidir}/build/excel2feature {toxinidir}
|
||||
|
Loading…
Reference in New Issue