Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Further review comments for test_multistore_file
Browse files Browse the repository at this point in the history
  • Loading branch information
thobrla committed Nov 17, 2015
1 parent 5d9839b commit 61596a7
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions tests/test_multistore_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@
from oauth2client import multistore_file


class MultistoreFileTests(unittest.TestCase):
class _MockLockedFile(object):

def test_lock_file_raises_ioerror(self):
def __init__(self, filename_str, error_code):
self.filename_str = filename_str
self.error_code = error_code
self.open_and_lock_called = False

class MockLockedFile(object):
def open_and_lock(self):
self.open_and_lock_called = True
raise IOError(self.error_code, '')

def __init__(self, filename_str, error_code):
self.filename_str = filename_str
self.error_code = error_code
def is_locked(self):
return False

def open_and_lock(self):
raise IOError(self.error_code, '')
def filename(self):
return self.filename_str

def is_locked(self):
return False

def filename(self):
return self.filename_str
class MultistoreFileTests(unittest.TestCase):

def test_lock_file_raises_ioerror(self):
filehandle, filename = tempfile.mkstemp()
os.close(filehandle)

try:
for error_code in (errno.EDEADLK, errno.ENOSYS, errno.ENOLCK):
multistore = multistore_file._MultiStore(filename)
multistore._file = MockLockedFile(filename, error_code)
# Should not raise even though the underlying file class did.
multistore._lock()
finally:
os.unlink(filename)
for error_code in (errno.EDEADLK, errno.ENOSYS, errno.ENOLCK):
multistore = multistore_file._MultiStore(filename)
multistore._file = _MockLockedFile(filename, error_code)
# Should not raise even though the underlying file class did.
multistore._lock()
self.assertTrue(multistore._file.open_and_lock_called)

0 comments on commit 61596a7

Please sign in to comment.