def test_bad_args(self): with tmp_series() as [dir, series]: make_file(b"patch -X\n", series.series_file) with tmp_mapping(vars(sys)) as tmp_sys: tmp_sys.set("stderr", cStringIO()) series.read() self.assertIn("-X", sys.stderr.getvalue())
def _make_conflict(self, dir, series): series.add_patch(Patch("conflict.patch")) make_file( b"--- orig/file\n" b"+++ new/file\n" b"@@ -1 +1 @@\n" b"-old\n" b"+new\n", series.dirname, "conflict.patch") make_file(b"conflict\n", dir, "file")
def test_patch_args(self): with tmp_series() as [dir, series]: make_file(b"patch1 -p0 --reverse\n" b"patch2 --strip=0 -R\n", series.series_file) series.read() [patch1, patch2] = series.patches() self.assertEqual(patch1.strip, "0") self.assertIs(patch1.reverse, True) self.assertEqual(patch2.strip, "0") self.assertIs(patch2.reverse, True)
def test_unrefreshed(self): with TmpDirectory() as dir: db = Db(dir.get_name()) db.add_patch(Patch("unrefreshed.patch")) db.save() make_file(b"", db.dirname, "unrefreshed.patch~refresh") cmd = Pop(dir.get_name(), db.dirname) with six.assertRaisesRegex(self, QuiltError, r"needs to be refreshed"): cmd.unapply_top_patch()
def test_patch_args(self): with tmp_series() as [dir, series]: make_file( b"patch1 -p0 --reverse\n" b"patch2 --strip=0 -R\n", series.series_file) series.read() [patch1, patch2] = series.patches() self.assertEqual(patch1.strip, "0") self.assertIs(patch1.reverse, True) self.assertEqual(patch2.strip, "0") self.assertIs(patch2.reverse, True)
def test_no_backup_named(self): """ Remove a specified patch without leaving a backup """ with tmp_series() as [dir, patches]: patches.add_patch(Patch("patch")) patches.save() patch = os.path.join(patches.dirname, "patch") make_file(b"", patch) run_cli(DeleteCommand, dict(patch="patch", next=False, remove=True, backup=False), patches.dirname, applied=dir) self.assertFalse(os.path.exists(patch)) self.assertFalse(os.path.exists(patch + "~"))
def test_fail_after_success(self): """ Test where the first patch applies but a later patch fails """ with tmp_series() as [dir, series]: make_file( b"--- /dev/null\n" b"+++ dir/new-file\n" b"@@ -0,0 +1,1 @@\n" b"+new file\n", series.dirname, "good.patch") series.add_patch(Patch("good.patch")) self._make_conflict(dir, series) series.save() cmd = Push(dir, quilt_pc=dir, quilt_patches=series.dirname) with six.assertRaisesRegex(self, QuiltError, r"conflict\.patch does not apply"), \ self._suppress_output(): cmd.apply_all() [applied] = Db(dir).patches() self.assertEqual(applied.get_name(), "good.patch") with open(os.path.join(dir, "new-file"), "rb") as file: self.assertEqual(file.read(), b"new file\n") with open(os.path.join(dir, "file"), "rb") as file: self.assertEqual(file.read(), b"conflict\n")
def test_sample_file(self): csv_data = dedent(""" col1,col2,more_data 1,2,3 "a,b","c\td","e f" """).lstrip() with make_file(csv_data) as filename: with open(filename) as csv_file: csv_rows = list(parse_csv(csv_file)) self.assertEqual(len(csv_rows), 2) row1, row2 = csv_rows self.assertEqual(row1.col1, '1') self.assertEqual(row1.col2, '2') self.assertEqual(row1.more_data, '3') self.assertEqual(row1, ('1', '2', '3')) self.assertEqual(row2, ('a,b', 'c\td', 'e f'))
def test_refresh(self): with TmpDirectory() as dir: old_dir = os.getcwd() try: os.chdir(dir.get_name()) db = Db(".pc") db.create() backup = os.path.join(".pc", "patch") os.mkdir(backup) make_file(b"", backup, "file") db.add_patch(Patch("patch")) db.save() make_file(b"", "patch") make_file(b"added\n", "file") cmd = quilt.refresh.Refresh(".", ".pc", ".") cmd.refresh() with open("patch", "r") as patch: self.assertTrue(patch.read(30)) finally: os.chdir(old_dir)
def test_unreverted(self): """ Test when the patch modifies unreverted files """ with tmp_series() as [dir, series]: old_dir = os.getcwd() try: os.chdir(dir) db = Db(dir) db.add_patch(Patch("patch")) db.save() originals = os.path.join(db.dirname, "patch") os.mkdir(originals) make_file(b"unreverted original\n", originals, "unreverted") make_file(b"reverted original\n", originals, "reverted") make_file(b"unreverted patched\n", dir, "unreverted") make_file(b"reverted patched\n", dir, "reverted") Refresh(dir, db.dirname, series.dirname).refresh() make_file(b"unreverted change\n", dir, "unreverted") make_file(b"reverted change\n", dir, "reverted") cmd = quilt.revert.Revert(dir, db.dirname, series.dirname) cmd.revert_file("reverted") with open(os.path.join(dir, "reverted"), "rb") as file: self.assertEqual(file.read(), b"reverted patched\n") with open(os.path.join(dir, "unreverted"), "rb") as file: self.assertEqual(file.read(), b"unreverted change\n") finally: os.chdir(old_dir)
def test_version(self): version = "234\n" self.assertTrue(version.startswith(format(DB_VERSION))) with TmpDirectory() as dir: make_file(version.encode("ascii"), dir.get_name(), ".version") self.assertRaises(DBError, Db, dir.get_name())