当前位置: 首页>>代码示例>>Python>>正文


Python diff_parser.DiffParser类代码示例

本文整理汇总了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)
开发者ID:Chetane,项目名称:changes,代码行数:35,代码来源:build_coverage_stats.py

示例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
"""
        )
开发者ID:mr-justin,项目名称:changes,代码行数:26,代码来源:test_diff_parser.py

示例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)
开发者ID:dropbox,项目名称:changes,代码行数:60,代码来源:build_coverage_stats.py

示例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()
开发者ID:rzachary,项目名称:changes,代码行数:8,代码来源:build_revision.py

示例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}}
开发者ID:martyanov,项目名称:changes,代码行数:8,代码来源:test_diff_parser.py

示例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,
                     },
                 ]
             ],
         }
     ]
开发者ID:mr-justin,项目名称:changes,代码行数:57,代码来源:test_diff_parser.py

示例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))
开发者ID:mr-justin,项目名称:changes,代码行数:9,代码来源:test_diff_parser.py

示例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)
             ]],
         )
     ]
开发者ID:dropbox,项目名称:changes,代码行数:54,代码来源:test_diff_parser.py

示例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() == {}
开发者ID:dropbox,项目名称:changes,代码行数:12,代码来源:test_diff_parser.py

示例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()
开发者ID:mr-justin,项目名称:changes,代码行数:12,代码来源:base.py

示例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() == {}
开发者ID:mr-justin,项目名称:changes,代码行数:12,代码来源:test_diff_parser.py

示例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 == """
开发者ID:martyanov,项目名称:changes,代码行数:13,代码来源:test_diff_parser.py

示例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 == """
开发者ID:martyanov,项目名称:changes,代码行数:13,代码来源:test_diff_parser.py

示例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 == """
开发者ID:martyanov,项目名称:changes,代码行数:14,代码来源:test_diff_parser.py

示例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 == """
开发者ID:dropbox,项目名称:changes,代码行数:14,代码来源:test_diff_parser.py


注:本文中的changes.utils.diff_parser.DiffParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。