Patchwork [3,of,4] atomictempfile: add read to the supported file operations

login
register
mail settings
Submitter Martijn Pieters
Date June 23, 2016, 5:24 p.m.
Message ID <79b315f113e47f7a9958.1466702692@mjpieters-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/15593/
State Accepted
Headers show

Comments

Martijn Pieters - June 23, 2016, 5:24 p.m.
# HG changeset patch
# User Martijn Pieters <mjpieters@fb.com>
# Date 1466702458 -3600
#      Thu Jun 23 18:20:58 2016 +0100
# Node ID 79b315f113e47f7a9958dc538ba3a0f86a0e976b
# Parent  f81ac11e45f12949117babdafda8c727fefb2f9b
atomictempfile: add read to the supported file operations

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1483,6 +1483,7 @@ 
         self._checkambig = checkambig
 
         # delegated methods
+        self.read = self._fp.read
         self.write = self._fp.write
         self.seek = self._fp.seek
         self.tell = self._fp.tell
diff --git a/tests/test-atomictempfile.py b/tests/test-atomictempfile.py
--- a/tests/test-atomictempfile.py
+++ b/tests/test-atomictempfile.py
@@ -89,6 +89,13 @@ 
             # on other faster platforms can detect problems
             pass
 
+    def testread(self):
+        with open(self._filename, 'wb') as f:
+            f.write(b'foobar\n')
+        file = atomictempfile(self._filename, mode='rb')
+        self.assertTrue(file.read(), b'foobar\n')
+        file.discard()
+
 if __name__ == '__main__':
     import silenttestrunner
     silenttestrunner.main(__name__)