mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add shared file tests to main test runner
This commit is contained in:
parent
08d56e2eee
commit
253fd95479
@ -62,6 +62,8 @@ def find_tests(which_tests=None):
|
|||||||
if ok('misc'):
|
if ok('misc'):
|
||||||
from calibre.ebooks.metadata.tag_mapper import find_tests
|
from calibre.ebooks.metadata.tag_mapper import find_tests
|
||||||
a(find_tests())
|
a(find_tests())
|
||||||
|
from calibre.utils.shared_file import find_tests
|
||||||
|
a(find_tests())
|
||||||
|
|
||||||
tests = unittest.TestSuite(ans)
|
tests = unittest.TestSuite(ans)
|
||||||
return tests
|
return tests
|
||||||
|
@ -172,32 +172,34 @@ else:
|
|||||||
def raise_winerror(x):
|
def raise_winerror(x):
|
||||||
raise NotImplementedError(), None, sys.exc_info()[2]
|
raise NotImplementedError(), None, sys.exc_info()[2]
|
||||||
|
|
||||||
def test():
|
def find_tests():
|
||||||
import repr as reprlib
|
import unittest
|
||||||
|
|
||||||
def eq(x, y):
|
|
||||||
if x != y:
|
|
||||||
raise AssertionError('%s != %s' % (reprlib.repr(x), reprlib.repr(y)))
|
|
||||||
|
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
with TemporaryDirectory() as tdir:
|
|
||||||
fname = os.path.join(tdir, 'test.txt')
|
|
||||||
with share_open(fname, 'wb') as f:
|
|
||||||
f.write(b'a' * 20 * 1024)
|
|
||||||
eq(fname, f.name)
|
|
||||||
f = share_open(fname, 'rb')
|
|
||||||
eq(f.read(1), b'a')
|
|
||||||
if iswindows:
|
|
||||||
os.rename(fname, fname+'.moved')
|
|
||||||
os.remove(fname+'.moved')
|
|
||||||
else:
|
|
||||||
os.remove(fname)
|
|
||||||
eq(f.read(1), b'a')
|
|
||||||
f2 = share_open(fname, 'w+b')
|
|
||||||
f2.write(b'b' * 10 * 1024)
|
|
||||||
f2.seek(0)
|
|
||||||
eq(f.read(10000), b'a'*10000)
|
|
||||||
eq(f2.read(100), b'b' * 100)
|
|
||||||
f3 = share_open(fname, 'rb')
|
|
||||||
eq(f3.read(100), b'b' * 100)
|
|
||||||
|
|
||||||
|
class SharedFileTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_shared_file(self):
|
||||||
|
eq = self.assertEqual
|
||||||
|
|
||||||
|
with TemporaryDirectory() as tdir:
|
||||||
|
fname = os.path.join(tdir, 'test.txt')
|
||||||
|
with share_open(fname, 'wb') as f:
|
||||||
|
f.write(b'a' * 20 * 1024)
|
||||||
|
eq(fname, f.name)
|
||||||
|
f = share_open(fname, 'rb')
|
||||||
|
eq(f.read(1), b'a')
|
||||||
|
if iswindows:
|
||||||
|
os.rename(fname, fname+'.moved')
|
||||||
|
os.remove(fname+'.moved')
|
||||||
|
else:
|
||||||
|
os.remove(fname)
|
||||||
|
eq(f.read(1), b'a')
|
||||||
|
f2 = share_open(fname, 'w+b')
|
||||||
|
f2.write(b'b' * 10 * 1024)
|
||||||
|
f2.seek(0)
|
||||||
|
eq(f.read(10000), b'a'*10000)
|
||||||
|
eq(f2.read(100), b'b' * 100)
|
||||||
|
f3 = share_open(fname, 'rb')
|
||||||
|
eq(f3.read(100), b'b' * 100)
|
||||||
|
|
||||||
|
return unittest.defaultTestLoader.loadTestsFromTestCase(SharedFileTest)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user