Beispiel #1
0
 def test_autofixed_parent_path(self):
     # [ ] exception vs return codes for error recovery
     #  [x] separate return code when patch lib compensated the error
     #      (implemented as warning count)
     pto = patch.fromfile(join(tests_dir, "data/autofix/parent-path.diff"))
     self.assertEqual(pto.errors, 0)
     self.assertEqual(pto.warnings, 2)
     self.assertEqual(pto.items[0].source, "patch.py")
Beispiel #2
0
 def test_apply_strip(self):
     treeroot = join(self.tmpdir, 'rootparent')
     shutil.copytree(join(tests_dir, '06nested'), treeroot)
     pto = patch.fromfile(join(tests_dir, '06nested/06nested.patch'))
     for p in pto:
       p.source = 'nasty/prefix/' + p.source
       p.target = 'nasty/prefix/' + p.target
     self.assert_(pto.apply(strip=2, root=treeroot))
Beispiel #3
0
    def test_diffstat(self):
        output = """\
 updatedlg.cpp | 20 ++++++++++++++++++--
 updatedlg.h   |  1 +
 manifest.xml  | 15 ++++++++-------
 conf.cpp      | 23 +++++++++++++++++------
 conf.h        |  7 ++++---
 5 files changed, 48 insertions(+), 18 deletions(-), +1203 bytes"""
        pto = patch.fromfile(join(tests_dir, "01uni_multi/01uni_multi.patch"))
        self.assertEqual(pto.diffstat(), output, "Output doesn't match")
Beispiel #4
0
 def test_revert(self):
     self.tmpcopy(['03trail_fname.patch',
                   '03trail_fname.from'])
     pto = patch.fromfile('03trail_fname.patch')
     self.assert_(pto.apply())
     self.assertNotEqual(open(self.tmpdir + '/03trail_fname.from').read(),
                         open(tests_dir + '/03trail_fname.from').read())
     self.assert_(pto.revert())
     self.assertEqual(open(self.tmpdir + '/03trail_fname.from').read(),
                      open(tests_dir + '/03trail_fname.from').read())
Beispiel #5
0
 def test_hg_exported(self):
     pto = patch.fromfile(join(tests_dir, "data/hg-exported.diff"))
     self.assertEqual(pto.type, patch.HG)
Beispiel #6
0
 def test_hg_detected(self):
     pto = patch.fromfile(join(tests_dir, "data/hg-added-file.diff"))
     self.assertEqual(pto.type, patch.HG)
Beispiel #7
0
 def test_svn_detected(self):
     pto = patch.fromfile(join(tests_dir, "01uni_multi/01uni_multi.patch"))
     self.assertEqual(pto.type, patch.SVN)
Beispiel #8
0
 def test_multiline_false_on_other_file(self):
     pto = patch.fromfile("01uni_multi/01uni_multi.patch")
     os.chdir(join(tests_dir, "01uni_multi"))
     self.assertFalse(pto.can_patch("updatedlg.cpp"))
Beispiel #9
0
 def test_apply_root(self):
     treeroot = join(self.tmpdir, 'rootparent')
     shutil.copytree(join(tests_dir, '06nested'), treeroot)
     pto = patch.fromfile(join(tests_dir, '06nested/06nested.patch'))
     self.assert_(pto.apply(root=treeroot))
Beispiel #10
0
 def test_apply_returns_true_on_success(self):
     self.tmpcopy(['03trail_fname.patch',
                   '03trail_fname.from'])
     pto = patch.fromfile('03trail_fname.patch')
     self.assert_(pto.apply())
Beispiel #11
0
 def test_hunk_desc(self):
     pto = patch.fromfile(fixture('git-changed-file.diff'))
     self.assertEqual(pto.items[0].hunks[0].desc, 'class JSONPluginMgr(object):')
Beispiel #12
0
 def test_header_for_second_file_in_svn_diff(self):
     pto = patch.fromfile(join(tests_dir, "01uni_multi/01uni_multi.patch"))
     self.assertEqual(pto.items[1].header[0], 'Index: updatedlg.h\r\n')
     self.assert_(pto.items[1].header[1].startswith('====='))
Beispiel #13
0
 def test_no_header_for_plain_diff_with_single_file(self):
     pto = patch.fromfile(join(tests_dir, "03trail_fname.patch"))
     self.assertEqual(pto.items[0].header, [])
Beispiel #14
0
 def test_fromfile(self):
     pst = patch.fromfile(join(tests_dir, "01uni_multi/01uni_multi.patch"))
     self.assertNotEqual(pst, False)
     self.assertEqual(len(pst), 5)
     ps2 = patch.fromfile(fixture("failing/not-a-patch.log"))
     self.assertFalse(ps2)
Beispiel #15
0
 def test_can_patch_checks_source_filename_even_if_target_can_be_patched(self):
     pto2 = patch.fromfile("04can_patch.patch")
     self.assertFalse(pto2.can_patch("04can_patch.to"))
Beispiel #16
0
 def test_single_false_on_other_file(self):
     pto3 = patch.fromfile("03trail_fname.patch")
     self.assertFalse(pto3.can_patch("03trail_fname.from"))
Beispiel #17
0
 def test_git_changed_detected(self):
     pto = patch.fromfile(join(tests_dir, "data/git-changed-file.diff"))
     self.assertEqual(pto.type, patch.GIT)
Beispiel #18
0
 def test_apply_returns_false_on_failure(self):
     self.tmpcopy(['data/failing/non-empty-patch-for-empty-file.diff',
                   'data/failing/upload.py'])
     pto = patch.fromfile('non-empty-patch-for-empty-file.diff')
     self.assertFalse(pto.apply())
Beispiel #19
0
 def test_autofixed_absolute_path(self):
     pto = patch.fromfile(join(tests_dir, "data/autofix/absolute-path.diff"))
     self.assertEqual(pto.errors, 0)
     self.assertEqual(pto.warnings, 2)
     self.assertEqual(pto.items[0].source, "winnt/tests/run_tests.py")
Beispiel #20
0
 def test_can_patch_single_source(self):
     pto2 = patch.fromfile("02uni_newline.patch")
     self.assert_(pto2.can_patch("02uni_newline.from"))
Beispiel #21
0
 def test_autofixed_stripped_trailing_whitespace(self):
     pto = patch.fromfile(join(tests_dir, "data/autofix/stripped-trailing-whitespace.diff"))
     self.assertEqual(pto.errors, 0)
     self.assertEqual(pto.warnings, 4)
Beispiel #22
0
 def test_patched_multipatch(self):
     pto = patch.fromfile("01uni_multi/01uni_multi.patch")
     os.chdir(join(tests_dir, "01uni_multi", "[result]"))
     self.assert_(pto.can_patch("updatedlg.cpp"))
Beispiel #23
0
 def test_can_patch_fails_on_target_file(self):
     pto3 = patch.fromfile("03trail_fname.patch")
     self.assertEqual(None, pto3.can_patch("03trail_fname.to"))
     self.assertEqual(None, pto3.can_patch("not_in_source.also"))