TensorFlow: implement gfile.Open mimicking standard open. Fixes #1105.
Change: 114717481
This commit is contained in:
parent
bf08a419e5
commit
edfcee84a9
@ -438,3 +438,16 @@ def Copy(oldpath, newpath, overwrite=False):
|
|||||||
if not overwrite and Exists(newpath):
|
if not overwrite and Exists(newpath):
|
||||||
raise OSError(errno.EEXIST, os.strerror(errno.EEXIST), newpath)
|
raise OSError(errno.EEXIST, os.strerror(errno.EEXIST), newpath)
|
||||||
shutil.copy(oldpath, newpath)
|
shutil.copy(oldpath, newpath)
|
||||||
|
|
||||||
|
|
||||||
|
def Open(name, mode='r'):
|
||||||
|
"""Exact API match to the standard open.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: a file name, either local or a gfile compatible.
|
||||||
|
mode: for example "w" to open the file for writing.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A threadsafe gfile.GFile object.
|
||||||
|
"""
|
||||||
|
return GFile(name, mode=mode)
|
||||||
|
@ -220,6 +220,12 @@ class FunctionTests(_BaseTest, googletest.TestCase):
|
|||||||
lambda: gfile.Rename(self.tmp + "dir1/file1",
|
lambda: gfile.Rename(self.tmp + "dir1/file1",
|
||||||
self.tmp + "newdir/file1"))
|
self.tmp + "newdir/file1"))
|
||||||
|
|
||||||
|
def testOpen(self):
|
||||||
|
with gfile.Open(self.tmp + "test_open", "wb") as f:
|
||||||
|
f.write("foo")
|
||||||
|
with gfile.Open(self.tmp + "test_open") as f:
|
||||||
|
result = f.readlines()
|
||||||
|
self.assertEqual([b"foo"], result)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
googletest.main()
|
googletest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user