未验证 提交 944f8ae0 编写于 作者: C chalsliu 提交者: GitHub

Upgrade coverage tool to python3

上级 753a0748
...@@ -90,12 +90,12 @@ def get_info_file_lines(info_file, diff_file): ...@@ -90,12 +90,12 @@ def get_info_file_lines(info_file, diff_file):
continue continue
elif line.startswith('LF:'): elif line.startswith('LF:'):
print 'LF:{}'.format(current_lf) print('LF:{}'.format(current_lf))
continue continue
elif line.startswith('LH:'): elif line.startswith('LH:'):
print 'LH:{}'.format(current_lh) print('LH:{}'.format(current_lh))
continue continue
......
...@@ -40,7 +40,7 @@ def filter_by(list_file, max_rate): ...@@ -40,7 +40,7 @@ def filter_by(list_file, max_rate):
except: except:
pass pass
print name, rate print(name, rate)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -33,7 +33,7 @@ def get_lines(info_file): ...@@ -33,7 +33,7 @@ def get_lines(info_file):
hits += 1 hits += 1
if total == 0: if total == 0:
print 'no data found' print('no data found')
exit() exit()
return hits / total return hits / total
...@@ -47,17 +47,17 @@ if __name__ == '__main__': ...@@ -47,17 +47,17 @@ if __name__ == '__main__':
expected = float(sys.argv[2]) expected = float(sys.argv[2])
if not os.path.isfile(info_file): if not os.path.isfile(info_file):
print 'info file {} is not exists, ignored'.format(info_file) print('info file {} is not exists, ignored'.format(info_file))
exit() exit()
actual = get_lines(info_file) actual = get_lines(info_file)
actual = round(actual, 3) actual = round(actual, 3)
if actual < expected: if actual < expected:
print 'expected >= {} %, actual {} %, failed'.format( print('expected >= {} %, actual {} %, failed'.format(
round(expected * 100, 1), round(actual * 100, 1)) round(expected * 100, 1), round(actual * 100, 1)))
exit(1) exit(1)
print 'expected >= {} %, actual {} %, passed'.format( print('expected >= {} %, actual {} %, passed'.format(
round(expected * 100, 1), round(actual * 100, 1)) round(expected * 100, 1), round(actual * 100, 1)))
...@@ -5,7 +5,7 @@ set -xe ...@@ -5,7 +5,7 @@ set -xe
PADDLE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../../" && pwd )" PADDLE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../../" && pwd )"
# install lcov # install lcov
curl -o /lcov-1.14.tar.gz -x "" -s https://paddle-ci.gz.bcebos.com/coverage/lcov-1.14.tar.gz curl -o /lcov-1.14.tar.gz -s https://paddle-ci.gz.bcebos.com/coverage%2Flcov-1.14.tar.gz
tar -xf /lcov-1.14.tar.gz -C / tar -xf /lcov-1.14.tar.gz -C /
cd /lcov-1.14 cd /lcov-1.14
make install make install
...@@ -14,7 +14,7 @@ make install ...@@ -14,7 +14,7 @@ make install
cd /paddle/build cd /paddle/build
python ${PADDLE_ROOT}/tools/coverage/gcda_clean.py ${GIT_PR_ID} python3 ${PADDLE_ROOT}/tools/coverage/gcda_clean.py ${GIT_PR_ID}
lcov --capture -d ./ -o coverage.info --rc lcov_branch_coverage=0 lcov --capture -d ./ -o coverage.info --rc lcov_branch_coverage=0
...@@ -53,9 +53,9 @@ gen_full_html_report || true ...@@ -53,9 +53,9 @@ gen_full_html_report || true
function gen_diff_html_report() { function gen_diff_html_report() {
if [ "${GIT_PR_ID}" != "" ]; then if [ "${GIT_PR_ID}" != "" ]; then
COVERAGE_DIFF_PATTERN="`python ${PADDLE_ROOT}/tools/coverage/pull_request.py files ${GIT_PR_ID}`" COVERAGE_DIFF_PATTERN="`python3 ${PADDLE_ROOT}/tools/coverage/pull_request.py files ${GIT_PR_ID}`"
python ${PADDLE_ROOT}/tools/coverage/pull_request.py diff ${GIT_PR_ID} > git-diff.out python3 ${PADDLE_ROOT}/tools/coverage/pull_request.py diff ${GIT_PR_ID} > git-diff.out
fi fi
lcov --extract coverage-full.info \ lcov --extract coverage-full.info \
...@@ -63,7 +63,7 @@ function gen_diff_html_report() { ...@@ -63,7 +63,7 @@ function gen_diff_html_report() {
-o coverage-diff.info \ -o coverage-diff.info \
--rc lcov_branch_coverage=0 --rc lcov_branch_coverage=0
python ${PADDLE_ROOT}/tools/coverage/coverage_diff.py coverage-diff.info git-diff.out > coverage-diff.tmp python3 ${PADDLE_ROOT}/tools/coverage/coverage_diff.py coverage-diff.info git-diff.out > coverage-diff.tmp
mv -f coverage-diff.tmp coverage-diff.info mv -f coverage-diff.tmp coverage-diff.info
...@@ -82,7 +82,7 @@ set -x ...@@ -82,7 +82,7 @@ set -x
coverage xml -i -o python-coverage.xml coverage xml -i -o python-coverage.xml
python ${PADDLE_ROOT}/tools/coverage/python_coverage.py > python-coverage.info python3 ${PADDLE_ROOT}/tools/coverage/python_coverage.py > python-coverage.info
# python full html report # python full html report
# #
...@@ -143,5 +143,6 @@ echo "Assert Python Diff Coverage" ...@@ -143,5 +143,6 @@ echo "Assert Python Diff Coverage"
python ${PADDLE_ROOT}/tools/coverage/coverage_lines.py python-coverage-diff.info 0.9 || PYTHON_COVERAGE_LINES_ASSERT=1 python ${PADDLE_ROOT}/tools/coverage/coverage_lines.py python-coverage-diff.info 0.9 || PYTHON_COVERAGE_LINES_ASSERT=1
if [ "$COVERAGE_LINES_ASSERT" = "1" ] || [ "$PYTHON_COVERAGE_LINES_ASSERT" = "1" ]; then if [ "$COVERAGE_LINES_ASSERT" = "1" ] || [ "$PYTHON_COVERAGE_LINES_ASSERT" = "1" ]; then
echo "exit 9" > /tmp/paddle_coverage.result
exit 9 exit 9
fi fi
...@@ -40,7 +40,7 @@ def get_files(args): ...@@ -40,7 +40,7 @@ def get_files(args):
pull = get_pull(args.pull_id) pull = get_pull(args.pull_id)
for file in pull.get_files(): for file in pull.get_files():
print '/paddle/{}'.format(file.filename) print('/paddle/{}'.format(file.filename))
def diff(args): def diff(args):
...@@ -55,8 +55,8 @@ def diff(args): ...@@ -55,8 +55,8 @@ def diff(args):
pull = get_pull(args.pull_id) pull = get_pull(args.pull_id)
for file in pull.get_files(): for file in pull.get_files():
print '+++ {}'.format(file.filename) print('+++ {}'.format(file.filename))
print file.patch print(file.patch)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -12,10 +12,7 @@ root = tree.getroot() ...@@ -12,10 +12,7 @@ root = tree.getroot()
sources = root.findall('sources/source') sources = root.findall('sources/source')
if len(sources) > 1: source = sources[-1].text
exit(1)
source = sources[0].text
for clazz in root.findall('packages/package/classes/class'): for clazz in root.findall('packages/package/classes/class'):
clazz_filename = clazz.attrib.get('filename') clazz_filename = clazz.attrib.get('filename')
...@@ -28,8 +25,8 @@ for clazz in root.findall('packages/package/classes/class'): ...@@ -28,8 +25,8 @@ for clazz in root.findall('packages/package/classes/class'):
if not path.exists(clazz_filename): if not path.exists(clazz_filename):
continue continue
print 'TN:' print('TN:')
print 'SF:{}'.format(clazz_filename) print('SF:{}'.format(clazz_filename))
branch_index = 0 branch_index = 0
...@@ -50,16 +47,16 @@ for clazz in root.findall('packages/package/classes/class'): ...@@ -50,16 +47,16 @@ for clazz in root.findall('packages/package/classes/class'):
taken = int(taken) taken = int(taken)
for _ in range(taken): for _ in range(taken):
print 'BRDA:{},{},{},{}'.format(line_number, 0, branch_index, print('BRDA:{},{},{},{}'.format(line_number, 0, branch_index,
line_hits) line_hits))
branch_index += 1 branch_index += 1
if line_missing_branches: if line_missing_branches:
for missing_branch in line_missing_branches.split(','): for missing_branch in line_missing_branches.split(','):
print 'BRDA:{},{},{},{}'.format(line_number, 0, print('BRDA:{},{},{},{}'.format(line_number, 0,
branch_index, 0) branch_index, 0))
branch_index += 1 branch_index += 1
print 'DA:{},{}'.format(line_number, line_hits) print('DA:{},{}'.format(line_number, line_hits))
print 'end_of_record' print('end_of_record')
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册