Skip to content

Commit f3ea958

Browse files
committed
Python 3 compatibility
1 parent ef7c83c commit f3ea958

2 files changed

Lines changed: 30 additions & 36 deletions

File tree

cpp_coveralls/coverage.py

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright 2015 (c) Lei Xu <eddyxu@gmail.com>
44

55
from __future__ import absolute_import
6+
from builtins import str
67

78
import argparse
89
import hashlib
@@ -292,21 +293,17 @@ def parse_lcov_file_info(args, filepath, line_iter, line_coverage_re, file_end_s
292293
"""
293294
coverage = []
294295
lines_covered = []
295-
while True:
296-
try:
297-
line = line_iter.next()
298-
if line != "end_of_record":
299-
line_coverage_match = line_coverage_re.match(line)
300-
if line_coverage_match:
301-
line_no = line_coverage_match.group(1)
302-
cov_count = int(line_coverage_match.group(2))
303-
if args.max_cov_count:
304-
if cov_count > args.max_cov_count:
305-
cov_count = args.max_cov_count + 1
306-
lines_covered.append((line_no, cov_count))
307-
else:
308-
break
309-
except StopIteration:
296+
for line in line_iter:
297+
if line != "end_of_record":
298+
line_coverage_match = line_coverage_re.match(line)
299+
if line_coverage_match:
300+
line_no = line_coverage_match.group(1)
301+
cov_count = int(line_coverage_match.group(2))
302+
if args.max_cov_count:
303+
if cov_count > args.max_cov_count:
304+
cov_count = args.max_cov_count + 1
305+
lines_covered.append((line_no, cov_count))
306+
else:
310307
break
311308

312309
num_code_lines = len([line.rstrip('\n') for line in open(filepath, 'r')])
@@ -394,27 +391,23 @@ def collect(args):
394391
line_iter = iter(info_lines)
395392
new_file_re = re.compile('SF:(.*)')
396393
line_coverage_re = re.compile('DA:(\d+),(\d+)');
397-
while True:
398-
try:
399-
line = line_iter.next()
400-
new_file_match = new_file_re.match(line)
401-
if new_file_match:
402-
src_report = {}
403-
filepath = new_file_match.group(1)
404-
if args.build_root:
405-
filepath = os.path.relpath(filepath, args.build_root)
406-
abs_filepath = os.path.join(abs_root, filepath)
407-
src_report['name'] = unicode(posix_path(filepath))
408-
with io.open(abs_filepath, mode='rb') as src_file:
409-
src_report['source_digest'] = hashlib.md5(src_file.read()).hexdigest()
410-
src_report['coverage'] = parse_lcov_file_info(args, abs_filepath, line_iter, line_coverage_re, "end_of_record")
411-
src_files[filepath] = src_report
412-
elif line != "TN:":
413-
print('Invalid info file')
414-
print('line: ' + line)
415-
sys.exit(0)
416-
except StopIteration:
417-
break
394+
for line in line_iter:
395+
new_file_match = new_file_re.match(line)
396+
if new_file_match:
397+
src_report = {}
398+
filepath = new_file_match.group(1)
399+
if args.root:
400+
filepath = os.path.relpath(filepath, args.root)
401+
abs_filepath = os.path.join(abs_root, filepath)
402+
src_report['name'] = str(posix_path(filepath))
403+
with io.open(abs_filepath, mode='rb') as src_file:
404+
src_report['source_digest'] = hashlib.md5(src_file.read()).hexdigest()
405+
src_report['coverage'] = parse_lcov_file_info(args, abs_filepath, line_iter, line_coverage_re, "end_of_record")
406+
src_files[filepath] = src_report
407+
elif line != "TN:":
408+
print('Invalid info file')
409+
print('line: ' + line)
410+
sys.exit(0)
418411
else:
419412
for root, dirs, files in os.walk(args.root, followlinks=args.follow_symlinks):
420413
dirs[:] = filter_dirs(root, dirs, excl_paths)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
requests
22
urllib3[secure]
3+
future

0 commit comments

Comments
 (0)