Commit adec18bd authored by Kirill Smelkov's avatar Kirill Smelkov

util: Factor readfile function into here

Soon we will need to use it not only from test_restore.py
parent 80559a94
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
from __future__ import print_function from __future__ import print_function
from zodbtools.zodbrestore import zodbrestore from zodbtools.zodbrestore import zodbrestore
from zodbtools.util import storageFromURL from zodbtools.util import storageFromURL, readfile
from os.path import dirname from os.path import dirname
from tempfile import mkdtemp from tempfile import mkdtemp
...@@ -49,12 +49,6 @@ def test_zodbrestore(zext): ...@@ -49,12 +49,6 @@ def test_zodbrestore(zext):
zodbrestore(stor, zdump) zodbrestore(stor, zdump)
_() _()
zfs1 = _readfile("%s/1%s.fs" % (tdata, zkind)) zfs1 = readfile("%s/1%s.fs" % (tdata, zkind))
zfs2 = _readfile("%s/2.fs" % tmpd) zfs2 = readfile("%s/2.fs" % tmpd)
assert zfs1 == zfs2 assert zfs1 == zfs2
# _readfile reads file at path.
def _readfile(path): # -> data(bytes)
with open(path, 'rb') as _:
return _.read()
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# zodbtools - various utility routines # zodbtools - various utility routines
# Copyright (C) 2016-2019 Nexedi SA and Contributors. # Copyright (C) 2016-2022 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# Jérome Perrin <jerome@nexedi.com> # Jérome Perrin <jerome@nexedi.com>
# #
...@@ -235,3 +235,9 @@ def asbinstream(stream): ...@@ -235,3 +235,9 @@ def asbinstream(stream):
if isinstance(stream, io.TextIOBase): if isinstance(stream, io.TextIOBase):
return stream.buffer return stream.buffer
return stream return stream
# readfile reads file at path.
def readfile(path): # -> data(bytes)
with open(path, 'rb') as _:
return _.read()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment