Skip to content

Commit

Permalink
Merge 36508b6 into d6e6f7b
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 17, 2018
2 parents d6e6f7b + 36508b6 commit 8dba401
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 158 deletions.
25 changes: 15 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
language: python
cache: pip
matrix:
include:
- python: 2.7
env: TOXENV=py27
- python: 3.4
env: TOXENV=py34
- python: 3.5
env: TOXENV=py35
- python: 3.6
env: TOXENV=py36
- python: pypy
env: TOXENV=pypy
- python: pypy3
env: TOXENV=pypy3
- python: pypy
env: TOXENV=pypy
- python: 3.7
env: TOXENV=py37
dist: xenial
sudo: true
- python: 3.6
env: TOXENV=py36
- python: 3.5
env: TOXENV=py35
- python: 3.4
env: TOXENV=py34
- python: 2.7
env: TOXENV=py27
install:
- travis_retry pip install coveralls tox
script:
Expand Down
14 changes: 7 additions & 7 deletions diff_cover/diff_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(self, compare_branch='origin/master', git_diff=None,
options.append("unstaged")

# Branch is always present, so use as basis for name
name = "{0}...HEAD".format(compare_branch)
name = "{}...HEAD".format(compare_branch)
if len(options) > 0:
# If more options are present separate them by comma's, except the last one
for item in options[:-1]:
Expand Down Expand Up @@ -311,7 +311,7 @@ def _parse_source_sections(self, diff_str):
# We tolerate other information before we have
# a source file defined, unless it's a hunk line
if line.startswith("@@"):
msg = "Hunk has no source file: '{0}'".format(line)
msg = "Hunk has no source file: '{}'".format(line)
raise GitDiffError(msg)

return source_dict
Expand Down Expand Up @@ -396,7 +396,7 @@ def _parse_source_line(self, line):
elif '--cc' in line:
regex = self.MERGE_CONFLICT_RE
else:
msg = "Do not recognize format of source in line '{0}'".format(line)
msg = "Do not recognize format of source in line '{}'".format(line)
raise GitDiffError(msg)

# Parse for the source file path
Expand All @@ -406,7 +406,7 @@ def _parse_source_line(self, line):
return groups[0]

else:
msg = "Could not parse source path in line '{0}'".format(line)
msg = "Could not parse source path in line '{}'".format(line)
raise GitDiffError(msg)

def _parse_hunk_line(self, line):
Expand Down Expand Up @@ -443,15 +443,15 @@ def _parse_hunk_line(self, line):
return int(groups[0])

except ValueError:
msg = "Could not parse '{0}' as a line number".format(groups[0])
msg = "Could not parse '{}' as a line number".format(groups[0])
raise GitDiffError(msg)

else:
msg = "Could not find start of hunk in line '{0}'".format(line)
msg = "Could not find start of hunk in line '{}'".format(line)
raise GitDiffError(msg)

else:
msg = "Could not parse hunk in line '{0}'".format(line)
msg = "Could not parse hunk in line '{}'".format(line)
raise GitDiffError(msg)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion diff_cover/git_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ def _git_root(cls):
"""
command = ['git', 'rev-parse', '--show-toplevel', '--encoding=utf-8']
git_root = execute(command)[0]
return git_root.split('\n')[0] if git_root else u''
return git_root.split('\n')[0] if git_root else ''
27 changes: 13 additions & 14 deletions diff_cover/report_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class DiffViolations(object):
Class to capture violations generated by a particular diff
"""
def __init__(self, violations, measured_lines, diff_lines):
self.lines = set(
self.lines = {
violation.line for violation in violations
).intersection(diff_lines)
}.intersection(diff_lines)

self.violations = set(
self.violations = {
violation for violation in violations
if violation.line in self.lines
)
}

# By convention, a violation reporter
# can return `None` to indicate that all lines are "measured"
Expand Down Expand Up @@ -80,8 +80,8 @@ def src_paths(self):
Return a list of source files in the diff
for which we have coverage information.
"""
return set(src for src, summary in self._diff_violations().items()
if len(summary.measured_lines) > 0)
return {src for src, summary in self._diff_violations().items()
if len(summary.measured_lines) > 0}

def percent_covered(self, src_path):
"""
Expand Down Expand Up @@ -166,15 +166,14 @@ def _diff_violations(self):
To make this efficient, we cache and reuse the result.
"""
if not self._diff_violations_dict:
self._diff_violations_dict = dict(
(
src_path, DiffViolations(
self._diff_violations_dict = {
src_path: DiffViolations(
self._violations.violations(src_path),
self._violations.measured_lines(src_path),
self._diff.lines_changed(src_path),
)
) for src_path in self._diff.src_paths_changed()
)
for src_path in self._diff.src_paths_changed()
}
return self._diff_violations_dict


Expand Down Expand Up @@ -256,9 +255,9 @@ def _context(self):
"""

# Calculate the information to pass to the template
src_stats = dict(
(src, self._src_path_stats(src)) for src in self.src_paths()
)
src_stats = {
src: self._src_path_stats(src) for src in self.src_paths()
}

# Include snippet style info if we're displaying
# source code snippets
Expand Down
2 changes: 1 addition & 1 deletion diff_cover/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def _group_tokens(cls, token_stream, range_list):
"""

# Create a map from ranges (start/end tuples) to tokens
token_map = dict((rng, []) for rng in range_list)
token_map = {rng: [] for rng in range_list}

# Keep track of the current line number; we will
# increment this as we encounter newlines in token values
Expand Down
12 changes: 6 additions & 6 deletions diff_cover/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ def _deleted_file_entries(deleted_files):

for src_file in deleted_files:
# File information
output.append('diff --git a/{0} b/{1}'.format(src_file, src_file))
output.append('diff --git a/{} b/{}'.format(src_file, src_file))
output.append('index 629e8ad..91b8c0a 100644')
output.append('--- a/{0}'.format(src_file))
output.append('--- a/{}'.format(src_file))
output.append('+++ b/dev/null')

# Choose a random number of lines
num_lines = random.randint(1, 30)

# Hunk information
output.append('@@ -0,{0} +0,0 @@'.format(num_lines))
output.append('@@ -0,{} +0,0 @@'.format(num_lines))
output.extend(['-' + _random_string() for _ in range(num_lines)])

return output
Expand All @@ -155,14 +155,14 @@ def _source_file_entry(src_file, modified_lines):
output = []

# Line for the file names
output.append('diff --git a/{0} b/{1}'.format(src_file, src_file))
output.append('diff --git a/{} b/{}'.format(src_file, src_file))

# Index line
output.append('index 629e8ad..91b8c0a 100644')

# Additions/deletions
output.append('--- a/{0}'.format(src_file))
output.append('+++ b/{0}'.format(src_file))
output.append('--- a/{}'.format(src_file))
output.append('+++ b/{}'.format(src_file))

# Hunk information
for (start, end) in _hunks(modified_lines):
Expand Down
2 changes: 1 addition & 1 deletion diff_cover/tests/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_parse_invalid_arg(self):

for argv in invalid_argv:
with self.assertRaises(SystemExit):
print("args = {0}".format(argv))
print("args = {}".format(argv))
parse_quality_args(argv)

def test_parse_with_exclude(self):
Expand Down
4 changes: 2 additions & 2 deletions diff_cover/tests/test_diff_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,11 @@ def test_git_diff_error(self):
# Expect that both methods that access git diff raise an error
with self.assertRaises(GitDiffError):
print("src_paths_changed() "
"should fail for {0}".format(diff_str))
"should fail for {}".format(diff_str))
self.diff.src_paths_changed()

with self.assertRaises(GitDiffError):
print("lines_changed() should fail for {0}".format(diff_str))
print("lines_changed() should fail for {}".format(diff_str))
self.diff.lines_changed('subdir/file1.py')

def test_plus_sign_in_hunk_bug(self):
Expand Down
2 changes: 1 addition & 1 deletion diff_cover/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def _call_quality_expecting_error(self, tool_name, expected_error, report_arg='p
with io.open('git_diff_add.txt', encoding='utf-8') as git_diff_file:
self._set_git_diff_output(git_diff_file.read(), "")
argv = ['diff-quality',
'--violations={0}'.format(tool_name),
'--violations={}'.format(tool_name),
report_arg]

with patch('diff_cover.tool.LOGGER') as logger:
Expand Down
38 changes: 19 additions & 19 deletions diff_cover/tests/test_java_violations_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def _setup_patch(return_value, status_code=0):

class CloverXmlCoverageReporterTest(unittest.TestCase):

MANY_VIOLATIONS = set([Violation(3, None), Violation(7, None),
Violation(11, None), Violation(13, None)])
FEW_MEASURED = set([2, 3, 5, 7, 11, 13])
MANY_VIOLATIONS = {Violation(3, None), Violation(7, None),
Violation(11, None), Violation(13, None)}
FEW_MEASURED = {2, 3, 5, 7, 11, 13}

FEW_VIOLATIONS = set([Violation(3, None), Violation(11, None)])
MANY_MEASURED = set([2, 3, 5, 7, 11, 13, 17])
FEW_VIOLATIONS = {Violation(3, None), Violation(11, None)}
MANY_MEASURED = {2, 3, 5, 7, 11, 13, 17}

ONE_VIOLATION = set([Violation(11, None)])
VERY_MANY_MEASURED = set([2, 3, 5, 7, 11, 13, 17, 23, 24, 25, 26, 26, 27])
ONE_VIOLATION = {Violation(11, None)}
VERY_MANY_MEASURED = {2, 3, 5, 7, 11, 13, 17, 23, 24, 25, 26, 26, 27}

def setUp(self):
# Paths generated by git_path are always the given argument
Expand Down Expand Up @@ -225,7 +225,7 @@ def test_no_such_file(self):

# Expect that we get no results
result = coverage.violations('file.java')
self.assertEqual(result, set([]))
self.assertEqual(result, set())

def _coverage_xml(
self,
Expand All @@ -251,7 +251,7 @@ def _coverage_xml(
project = etree.SubElement(root, 'project')
package = etree.SubElement(project, 'package')

violation_lines = set(violation.line for violation in violations)
violation_lines = {violation.line for violation in violations}

for path in file_paths:

Expand Down Expand Up @@ -435,7 +435,7 @@ def test_quality_pregenerated_report(self):
# When the user provides us with a pre-generated checkstyle report
# then use that instead of calling checkstyle directly.
checkstyle_reports = [
BytesIO(dedent(u"""
BytesIO(dedent("""
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="8.0">
<file name="path/to/file.java">
Expand All @@ -450,7 +450,7 @@ def test_quality_pregenerated_report(self):
</checkstyle>
""").strip().encode('utf-8')),

BytesIO(dedent(u"""
BytesIO(dedent("""
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="8.0">
<file name="path/to/file.java">
Expand All @@ -468,9 +468,9 @@ def test_quality_pregenerated_report(self):

# Expect that we get the right violations
expected_violations = [
Violation(1, u'error: Missing docstring'),
Violation(57, u'warning: TODO the name of this method is a little bit confusing'),
Violation(183, u"error: Invalid name '' for type argument (should match [a-z_][a-z0-9_]{2,30}$)")
Violation(1, 'error: Missing docstring'),
Violation(57, 'warning: TODO the name of this method is a little bit confusing'),
Violation(183, "error: Invalid name '' for type argument (should match [a-z_][a-z0-9_]{2,30}$)")
]

# We're not guaranteed that the violations are returned
Expand Down Expand Up @@ -515,7 +515,7 @@ def test_quality_pregenerated_report(self):
# When the user provides us with a pre-generated findbugs report
# then use that instead of calling findbugs directly.
findbugs_reports = [
BytesIO(dedent(u"""
BytesIO(dedent("""
<?xml version="1.0" encoding="UTF-8"?>
<BugCollection sequence="0" release="" analysisTimestamp="1512755361404" version="3.0.1" timestamp="1512755226000">
<BugInstance instanceOccurrenceNum="0" instanceHash="1967bf8c4d25c6b964f30356014aa9fb" rank="20" abbrev="Dm" category="I18N" priority="3" type="DM_CONVERT_CASE" instanceOccurrenceMax="0">
Expand All @@ -541,7 +541,7 @@ def test_quality_pregenerated_report(self):
</BugCollection>
""").strip().encode('utf-8')),

BytesIO(dedent(u"""
BytesIO(dedent("""
<?xml version="1.0" encoding="UTF-8"?>
<BugCollection sequence="0" release="" analysisTimestamp="1512755361404" version="3.0.1" timestamp="1512755226000">
<BugInstance instanceOccurrenceNum="0" instanceHash="1967bf8c4d25c6b964f30356014aa9fb" rank="20" abbrev="Dm" category="I18N" priority="3" type="DM_CONVERT_CASE" instanceOccurrenceMax="0">
Expand All @@ -568,7 +568,7 @@ def test_quality_pregenerated_report(self):
""").strip().encode('utf-8')),

# this is a violation which is not bounded to a specific line. We'll skip those
BytesIO(dedent(u"""
BytesIO(dedent("""
<?xml version="1.0" encoding="UTF-8"?>
<BugCollection sequence="0" release="" analysisTimestamp="1512755361404" version="3.0.1" timestamp="1512755226000">
<BugInstance instanceOccurrenceNum="0" instanceHash="2820338ec68e2e75a81848c95d31167f" rank="19" abbrev="Se" category="BAD_PRACTICE" priority="3" type="SE_BAD_FIELD" instanceOccurrenceMax="0">
Expand All @@ -587,8 +587,8 @@ def test_quality_pregenerated_report(self):

# Expect that we get the right violations
expected_violations = [
Violation(97, u'I18N: Consider using Locale parameterized version of invoked method'),
Violation(183, u'I18N: Consider using Locale parameterized version of invoked method')
Violation(97, 'I18N: Consider using Locale parameterized version of invoked method'),
Violation(183, 'I18N: Consider using Locale parameterized version of invoked method')
]

# We're not guaranteed that the violations are returned
Expand Down
4 changes: 2 additions & 2 deletions diff_cover/tests/test_report_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BaseReportGeneratorTest(unittest.TestCase):
"""

# Test data, returned by default from the mocks
SRC_PATHS = set(['file1.py', 'subdir/file2.py'])
SRC_PATHS = {'file1.py', 'subdir/file2.py'}
LINES = [2, 3, 4, 5, 10, 11, 12, 13, 14, 15]
VIOLATIONS = [Violation(n, None) for n in (10, 11, 20)]
MEASURED = [1, 2, 3, 4, 7, 10, 11, 15, 20, 30]
Expand All @@ -47,7 +47,7 @@ class BaseReportGeneratorTest(unittest.TestCase):
REPORT_GENERATOR_CLASS = None

# Snippet returned by the mock
SNIPPET = u"<div>Snippet with \u1235 \u8292 unicode</div>"
SNIPPET = "<div>Snippet with \u1235 \u8292 unicode</div>"
SNIPPET_STYLE = '.css { color:red }'

def setUp(self):
Expand Down
Loading

0 comments on commit 8dba401

Please sign in to comment.