本文整理汇总了Python中changes.utils.diff_parser.DiffParser类的典型用法代码示例。如果您正苦于以下问题:Python DiffParser类的具体用法?Python DiffParser怎么用?Python DiffParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DiffParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self, build_id):
build = Build.query.get(build_id)
if build is None:
return '', 404
args = self.parser.parse_args()
results = get_coverage_by_build_id(build.id)
if args.diff:
diff = build.source.generate_diff()
if not diff:
return self.respond({})
diff_parser = DiffParser(diff)
parsed_diff = diff_parser.parse()
files_in_diff = set(
d['new_filename'][2:] for d in parsed_diff
if d['new_filename']
)
results = [r for r in results if r.filename in files_in_diff]
coverage = {
c.filename: {
'linesCovered': c.lines_covered,
'linesUncovered': c.lines_uncovered,
'diffLinesCovered': c.diff_lines_covered,
'diffLinesUncovered': c.diff_lines_uncovered,
}
for c in results
}
return self.respond(coverage)
示例2: test_no_newline_both
def test_no_newline_both(self):
patch = """diff --git a/test b/test
index d800886..bed2d6a 100644
--- a/test
+++ b/test
@@ -1 +1 @@
-123
\ No newline at end of file
+123n
\ No newline at end of file
"""
parser = DiffParser(patch)
(file_dict,) = parser.parse()
diff = parser.reconstruct_file_diff(file_dict)
assert (
diff
== """
--- a/test
+++ b/test
@@ -1 +1 @@
-123
\ No newline at end of file
+123n
\ No newline at end of file
"""
)
示例3: get
def get(self, build_id):
build = Build.query.get(build_id)
if build is None:
return '', 404
args = self.parser.parse_args()
results = get_coverage_by_build_id(build.id)
if args.diff:
diff = build.source.generate_diff()
if not diff:
return self.respond({})
diff_parser = DiffParser(diff)
lines_by_file = diff_parser.get_lines_by_file()
results = [r for r in results if r.filename in lines_by_file]
coverage_data = merged_coverage_data(results)
coverage_stats = {}
for filename in lines_by_file:
if filename in coverage_data and filename in lines_by_file:
stats = get_coverage_stats(lines_by_file[filename], coverage_data[filename])
coverage_stats[filename] = {
'linesCovered': stats.lines_covered,
'linesUncovered': stats.lines_uncovered,
'diffLinesCovered': stats.diff_lines_covered,
'diffLinesUncovered': stats.diff_lines_uncovered,
}
else:
# NOTE: Without a diff, the stats may be off if there are
# multiple job steps. (Each job step can potentially
# return a separate FileCoverage row for the same file.)
# For each file, we return the best metrics using
# min()/max(); if you want more correct metrics, pass
# diff=1.
coverage_stats = {}
for r in results:
if r.filename not in coverage_stats:
coverage_stats[r.filename] = {
'linesCovered': r.lines_covered,
'linesUncovered': r.lines_uncovered,
'diffLinesCovered': r.diff_lines_covered,
'diffLinesUncovered': r.diff_lines_uncovered,
}
else:
# Combine metrics using max() for [diff] lines
# covered, min() for [diff] lines uncovered.
stats = coverage_stats[r.filename]
coverage_stats[r.filename] = {
'linesCovered': max(stats['linesCovered'], r.lines_covered),
'linesUncovered': min(stats['linesUncovered'], r.lines_uncovered),
'diffLinesCovered': max(stats['diffLinesCovered'], r.diff_lines_covered),
'diffLinesUncovered': min(stats['diffLinesUncovered'], r.diff_lines_uncovered),
}
return self.respond(coverage_stats)
示例4: get_changed_files
def get_changed_files(self):
vcs = self.repository.get_vcs()
if not vcs:
raise NotImplementedError
diff = vcs.export(self.revision.sha)
diff_parser = DiffParser(diff)
return diff_parser.get_changed_files()
示例5: test_get_changed_files_simple_diff
def test_get_changed_files_simple_diff(self):
parser = DiffParser(SIMPLE_DIFF)
files = parser.get_changed_files()
assert files == set([
'changes/utils/diff_parser.py',
])
lines_by_file = parser.get_lines_by_file()
assert lines_by_file == {'changes/utils/diff_parser.py': {74}}
示例6: test_parse_simple_diff
def test_parse_simple_diff(self):
parser = DiffParser(SIMPLE_DIFF)
files = parser.parse()
assert files == [
{
"old_filename": "a/changes/utils/diff_parser.py",
"new_filename": "b/changes/utils/diff_parser.py",
"chunk_markers": ["@@ -71,6 +71,7 @@ class DiffParser(object):"],
"chunks": [
[
{
"action": "unmod",
"line": " continue",
"new_lineno": 71,
"old_lineno": 71,
"ends_with_newline": True,
},
{"action": "unmod", "line": "", "new_lineno": 72, "old_lineno": 72, "ends_with_newline": True},
{
"action": "unmod",
"line": " chunks = []",
"new_lineno": 73,
"old_lineno": 73,
"ends_with_newline": True,
},
{
"action": "add",
"line": " chunk_markers = []",
"new_lineno": 74,
"old_lineno": u"",
"ends_with_newline": True,
},
{
"action": "unmod",
"line": " old, new = self._extract_rev(line, lineiter.next())",
"new_lineno": 75,
"old_lineno": 74,
"ends_with_newline": True,
},
{
"action": "unmod",
"line": " files.append({",
"new_lineno": 76,
"old_lineno": 75,
"ends_with_newline": True,
},
{
"action": "unmod",
"line": " 'old_filename': old[0] if old[0] != '/dev/null' else None,",
"new_lineno": 77,
"old_lineno": 76,
"ends_with_newline": True,
},
]
],
}
]
示例7: test_get_changed_files_complex_diff
def test_get_changed_files_complex_diff(self):
parser = DiffParser(COMPLEX_DIFF)
files = parser.get_changed_files()
assert files == set(["ci/run_with_retries.py", "ci/server-collect", "ci/not-real"])
lines_by_file = parser.get_lines_by_file()
assert set(lines_by_file) == files
assert lines_by_file["ci/not-real"] == {1}
assert lines_by_file["ci/server-collect"] == {24, 31, 39, 46}
assert lines_by_file["ci/run_with_retries.py"] == {2, 45} | set(range(53, 63)) | set(range(185, 192))
示例8: test_parse_simple_diff
def test_parse_simple_diff(self):
parser = DiffParser(SIMPLE_DIFF)
files = parser.parse()
assert files == [
FileInfo(
old_filename='a/changes/utils/diff_parser.py',
new_filename='b/changes/utils/diff_parser.py',
chunk_markers=['@@ -71,6 +71,7 @@ class DiffParser(object):'],
chunks=[[
LineInfo(
action='unmod',
line=' continue',
new_lineno=71,
old_lineno=71,
ends_with_newline=True),
LineInfo(
action='unmod',
line='',
new_lineno=72,
old_lineno=72,
ends_with_newline=True),
LineInfo(
action='unmod',
line=' chunks = []',
new_lineno=73,
old_lineno=73,
ends_with_newline=True),
LineInfo(
action='add',
line=' chunk_markers = []',
new_lineno=74,
old_lineno=0,
ends_with_newline=True),
LineInfo(
action='unmod',
line=' old, new = self._extract_rev(line, lineiter.next())',
new_lineno=75,
old_lineno=74,
ends_with_newline=True),
LineInfo(
action='unmod',
line=' files.append({',
new_lineno=76,
old_lineno=75,
ends_with_newline=True),
LineInfo(
action='unmod',
line=" 'old_filename': old[0] if old[0] != '/dev/null' else None,",
new_lineno=77,
old_lineno=76,
ends_with_newline=True)
]],
)
]
示例9: test_remove_empty_file
def test_remove_empty_file(self):
patch = """diff --git a/diff-from/__init__.py b/diff-from/__init__.py
deleted file mode 100644
index e69de29..0000000
"""
parser = DiffParser(patch)
(file_info,) = parser.parse()
diff = parser.reconstruct_file_diff(file_info)
assert diff == ""
assert file_info.new_filename is None
assert parser.get_changed_files() == set(['diff-from/__init__.py'])
assert parser.get_lines_by_file() == {}
示例10: get_changed_files
def get_changed_files(self, id):
"""Returns the list of files changed in a revision.
Args:
id (str): The id of the revision.
Returns:
A set of filenames
Raises:
UnknownRevision: If the revision wan't found.
"""
diff = self.export(id)
diff_parser = DiffParser(diff)
return diff_parser.get_changed_files()
示例11: test_add_empty_file
def test_add_empty_file(self):
patch = """diff --git a/diff-from/__init__.py b/diff-from/__init__.py
new file mode 100644
index 0000000..e69de29
"""
parser = DiffParser(patch)
(file_dict,) = parser.parse()
diff = parser.reconstruct_file_diff(file_dict)
assert diff == ""
assert file_dict["old_filename"] is None
assert parser.get_changed_files() == set(["diff-from/__init__.py"])
assert parser.get_lines_by_file() == {}
示例12: test_no_newline_empty_target
def test_no_newline_empty_target(self):
patch = """diff --git a/test b/test
index d800886..e69de29 100644
--- a/test
+++ b/test
@@ -1 +0,0 @@
-123
\ No newline at end of file
"""
parser = DiffParser(patch)
(file_dict,) = parser.parse()
diff = parser.reconstruct_file_diff(file_dict)
assert diff == """
示例13: test_no_newline_empty_source
def test_no_newline_empty_source(self):
patch = """diff --git a/test b/test
index e69de29..d800886 100644
--- a/test
+++ b/test
@@ -0,0 +1 @@
+123
\ No newline at end of file
"""
parser = DiffParser(patch)
(file_dict,) = parser.parse()
diff = parser.reconstruct_file_diff(file_dict)
assert diff == """
示例14: test_no_newline_target
def test_no_newline_target(self):
patch = """diff --git a/test b/test
index 190a180..d800886 100644
--- a/test
+++ b/test
@@ -1 +1 @@
-123
+123
\ No newline at end of file
"""
parser = DiffParser(patch)
(file_dict,) = parser.parse()
diff = parser.reconstruct_file_diff(file_dict)
assert diff == """
示例15: test_no_newline_source
def test_no_newline_source(self):
patch = """diff --git a/test b/test
index d800886..190a180 100644
--- a/test
+++ b/test
@@ -1 +1 @@
-123
\ No newline at end of file
+123
"""
parser = DiffParser(patch)
(file_info,) = parser.parse()
diff = parser.reconstruct_file_diff(file_info)
assert diff == """