How to use unidiff - 10 common examples

To help you get started, we’ve selected a few unidiff examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bosondata / badwolf / tests / test_lint.py View on Github external
+        "quotes": [2, "single"]
+    }
+}
diff --git a/a.js b/a.js
new file mode 100644
index 0000000..f119a7f
--- /dev/null
+++ b/a.js
@@ -0,0 +1 @@
+console.log("bar")
"""

    spec = Specification()
    spec.linters.append(ObjectDict(name='eslint', pattern=None))
    lint = LintProcessor(pr_context, spec, os.path.join(FIXTURES_PATH, 'eslint'))
    patch = PatchSet(diff.split('\n'))
    with mock.patch.object(lint, 'load_changes') as load_changes,\
            mock.patch.object(lint, 'update_build_status') as build_status,\
            mock.patch.object(lint, '_report') as report:
        load_changes.return_value = patch
        build_status.return_value = None
        report.return_value = (1, 2)
        lint.problems.set_changes(patch)
        lint.process()

        assert load_changes.called

    assert len(lint.problems) == 1
    problem = lint.problems[0]
    assert problem.filename == 'a.js'
    assert problem.line == 1
github bosondata / badwolf / tests / test_lint.py View on Github external
index 0000000..fdeea15
--- /dev/null
+++ b/a.py
@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
+
+
+def add(a, b):
+    return a+ b
"""

    spec = Specification()
    spec.linters.append(ObjectDict(name='pylint', pattern=None))
    lint = LintProcessor(pr_context, spec, os.path.join(FIXTURES_PATH, 'pylint'))
    patch = PatchSet(diff.split('\n'))
    with mock.patch.object(lint, 'load_changes') as load_changes,\
            mock.patch.object(lint, 'update_build_status') as build_status,\
            mock.patch.object(lint, '_report') as report:
        load_changes.return_value = patch
        build_status.return_value = None
        report.return_value = (1, 2)
        lint.problems.set_changes(patch)
        lint.process()

        assert load_changes.called

    assert len(lint.problems) == 4
    problem = lint.problems[0]
    assert problem.filename == 'a.py'
github matiasb / python-unidiff / tests / test_parser.py View on Github external
def test_patchset_from_string(self):
        with codecs.open(self.sample_file, 'r', encoding='utf-8') as diff_file:
            diff_data = diff_file.read()
            ps1 = PatchSet.from_string(diff_data)

        with codecs.open(self.sample_file, 'r', encoding='utf-8') as diff_file:
            ps2 = PatchSet(diff_file)

        self.assertEqual(ps1, ps2)
github matiasb / python-unidiff / tests / test_parser.py View on Github external
def test_patchset_from_bytes_string(self):
        with codecs.open(self.sample_file, 'rb') as diff_file:
            diff_data = diff_file.read()
            ps1 = PatchSet.from_string(diff_data, encoding='utf-8')

        with codecs.open(self.sample_file, 'r', encoding='utf-8') as diff_file:
            ps2 = PatchSet(diff_file)

        self.assertEqual(ps1, ps2)
github getsentry / sentry / src / test_only_plugins / bitbucket / client.py View on Github external
def get_commit_filechanges(self, repo, sha):
        # returns unidiff file

        resp = self.get("/2.0/repositories/{}/diff/{}".format(repo, sha), allow_text=True)

        diff_file = resp.text
        ps = PatchSet.from_string(diff_file)
        return self.transform_patchset(ps)
github matiasb / python-unidiff / tests / test_hunks.py View on Github external
def test_default_is_valid(self):
        hunk = Hunk()
        self.assertTrue(hunk.is_valid())
github matiasb / python-unidiff / tests / test_hunks.py View on Github external
def test_append_added_line(self):
        hunk = Hunk(src_len=0, tgt_len=1)
        hunk.append(self.added_line)
        self.assertTrue(hunk.is_valid())
        self.assertEqual(len(hunk.target), 1)
        self.assertEqual(hunk.source, [])
        self.assertIn(str(self.added_line), hunk.target)
        target_lines = list(hunk.target_lines())
        self.assertEqual(target_lines, [self.added_line])
github matiasb / python-unidiff / tests / test_hunks.py View on Github external
def test_missing_length(self):
        hunk = Hunk(src_len=None, tgt_len=None)
        hunk.append(self.context_line)
        self.assertTrue(hunk.is_valid())
github matiasb / python-unidiff / tests / test_patchedfile.py View on Github external
def test_is_modified_file(self):
        hunk = Hunk(src_start=1, src_len=10, tgt_start=1, tgt_len=8)
        self.patched_file.append(hunk)
        self.assertTrue(self.patched_file.is_modified_file)
github matiasb / python-unidiff / tests / test_hunks.py View on Github external
def test_missing_data_is_not_valid(self):
        hunk = Hunk(src_len=1, tgt_len=1)
        self.assertFalse(hunk.is_valid())