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


Python DiffParser.parse方法代码示例

本文整理汇总了Python中changes.utils.diff_parser.DiffParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Python DiffParser.parse方法的具体用法?Python DiffParser.parse怎么用?Python DiffParser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在changes.utils.diff_parser.DiffParser的用法示例。


在下文中一共展示了DiffParser.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_no_newline_both

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    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,代码行数:28,代码来源:test_diff_parser.py

示例2: get

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    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,代码行数:37,代码来源:build_coverage_stats.py

示例3: test_parse_simple_diff

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
 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,代码行数:59,代码来源:test_diff_parser.py

示例4: test_parse_simple_diff

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
 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,代码行数:56,代码来源:test_diff_parser.py

示例5: test_add_empty_file

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    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,代码行数:14,代码来源:test_diff_parser.py

示例6: test_remove_empty_file

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    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,代码行数:14,代码来源:test_diff_parser.py

示例7: test_no_newline_empty_target

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    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,代码行数:15,代码来源:test_diff_parser.py

示例8: test_no_newline_empty_source

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    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,代码行数:15,代码来源:test_diff_parser.py

示例9: test_no_newline_target

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    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,代码行数:16,代码来源:test_diff_parser.py

示例10: test_no_newline_source

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    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,代码行数:16,代码来源:test_diff_parser.py

示例11: test_add_multiple_empty_files

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    def test_add_multiple_empty_files(self):
        patch = """diff --git a/diff-from/__init__.py b/diff-from/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/diff-from/other.py b/diff-from/other.py
new file mode 100644
index 0000000..e69de29
"""
        parser = DiffParser(patch)
        (first_dict, second_dict) = parser.parse()
        assert first_dict["new_filename"] == "b/diff-from/__init__.py"
        assert first_dict["old_filename"] is None
        assert second_dict["new_filename"] == "b/diff-from/other.py"
        assert second_dict["old_filename"] is None
        assert parser.get_changed_files() == set(["diff-from/__init__.py", "diff-from/other.py"])
        assert parser.get_lines_by_file() == {}
开发者ID:mr-justin,项目名称:changes,代码行数:18,代码来源:test_diff_parser.py

示例12: test_add_multiple_empty_files

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    def test_add_multiple_empty_files(self):
        patch = """diff --git a/diff-from/__init__.py b/diff-from/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/diff-from/other.py b/diff-from/other.py
new file mode 100644
index 0000000..e69de29
"""
        parser = DiffParser(patch)
        (first_info, second_info,) = parser.parse()
        assert first_info.new_filename == 'b/diff-from/__init__.py'
        assert first_info.old_filename is None
        assert second_info.new_filename == 'b/diff-from/other.py'
        assert second_info.old_filename is None
        assert parser.get_changed_files() == set(['diff-from/__init__.py', 'diff-from/other.py'])
        assert parser.get_lines_by_file() == {}
开发者ID:dropbox,项目名称:changes,代码行数:18,代码来源:test_diff_parser.py

示例13: get_changed_files

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    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)
        parsed_diff = diff_parser.parse()

        results = set()
        for info in parsed_diff:
            if info['new_filename']:
                results.add(info['new_filename'][2:])
            if info['old_filename']:
                results.add(info['old_filename'][2:])
        return results
开发者ID:stefan-avramov,项目名称:changes,代码行数:18,代码来源:build_revision.py

示例14: test_reconstruct_file_diff_simple_diff

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    def test_reconstruct_file_diff_simple_diff(self):
        parser = DiffParser(SIMPLE_DIFF)
        files = parser.parse()
        assert len(files) == 1
        diff = parser.reconstruct_file_diff(files[0])
        correct = """
--- a/changes/utils/diff_parser.py
+++ b/changes/utils/diff_parser.py
@@ -71,6 +71,7 @@ class DiffParser(object):
""" + ' ' + """
             in_header = False
             chunks = []
+                chunk_markers = []
             old, new = self._extract_rev(line, lineiter.next())
             files.append({
                 'is_header': False,
"""
        assert diff == correct
开发者ID:martyanov,项目名称:changes,代码行数:20,代码来源:test_diff_parser.py

示例15: test_reconstruct_file_diff_simple_diff

# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import parse [as 别名]
    def test_reconstruct_file_diff_simple_diff(self):
        parser = DiffParser(SIMPLE_DIFF)
        files = parser.parse()
        assert len(files) == 1
        diff = parser.reconstruct_file_diff(files[0])
        correct = """
--- a/changes/utils/diff_parser.py
+++ b/changes/utils/diff_parser.py
@@ -71,6 +71,7 @@ class DiffParser(object):
                 continue
""" + ' ' + """
             chunks = []
+            chunk_markers = []
             old, new = self._extract_rev(line, lineiter.next())
             files.append({
                 'old_filename': old[0] if old[0] != '/dev/null' else None,
"""
        assert diff == correct
开发者ID:dropbox,项目名称:changes,代码行数:20,代码来源:test_diff_parser.py


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