From fa274210cccf8db816a24f1d55195fa79c9a2ad4 Mon Sep 17 00:00:00 2001 From: Jonathan Matthew Date: Sun, 10 Aug 2008 03:28:03 +0000 Subject: Bug 547067 – add File.replace_contents, replace_contents_async, MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-08-10 Jonathan Matthew Bug 547067 – add File.replace_contents, replace_contents_async, replace_contents_finish. * gio/gfile.override: * gio/gio.defs: * tests/test_gio.py: Add overrides, docs, and tests for File.replace_contents, replace_contents_async, and replace_contents_finish. svn path=/trunk/; revision=935 --- tests/test_gio.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests') diff --git a/tests/test_gio.py b/tests/test_gio.py index ad186fe..8244852 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -373,6 +373,47 @@ class TestFile(unittest.TestCase): 10, gio.FILE_QUERY_INFO_NONE) self.assertEqual(ret, True) + def testReplaceContents(self): + self.file.replace_contents("testing replace_contents") + cont, leng, etag = self.file.load_contents() + self.assertEqual(cont, "testing replace_contents") + + caught = False + try: + self.file.replace_contents("this won't work", etag="wrong") + except gio.Error, e: + self.assertEqual(e.code, gio.ERROR_WRONG_ETAG) + caught = True + self.failUnless(caught) + + self.file.replace_contents("testing replace_contents again", etag=etag) + cont, leng, etag = self.file.load_contents() + self.assertEqual(cont, "testing replace_contents again") + + self.file.replace_contents("testing replace_contents yet again", etag=None) + cont, leng, etag = self.file.load_contents() + self.assertEqual(cont, "testing replace_contents yet again") + + def testReplaceContentsAsync(self): + + def callback(contents, result): + try: + newetag = contents.replace_contents_finish(result) + cont, leng, etag = self.file.load_contents() + self.assertEqual(cont, "testing replace_contents_async") + self.assertEqual(leng, 30) + self.assertEqual(etag, newetag) + self.assertNotEqual(newetag, '') + finally: + loop.quit() + + canc = gio.Cancellable() + self.file.replace_contents_async("testing replace_contents_async", callback, cancellable=canc) + + loop = glib.MainLoop() + loop.run() + + class TestGFileEnumerator(unittest.TestCase): def setUp(self): -- cgit