Follow up punch_hole patch

Add missing tests to get more coverage and reduce a line.

Change-Id: I34d8063ee82323c9751b4c965bee01ab584c5eb5
This commit is contained in:
Kota Tsuyuzaki 2018-09-15 06:49:18 +09:00
parent dbacdcf01c
commit 814a76689f
2 changed files with 12 additions and 2 deletions

View File

@ -831,14 +831,13 @@ class _LibcWrapper(object):
# spurious AttributeError.
func_handle = load_libc_function(
func_name, fail_if_missing=True)
self._func_handle = func_handle
except AttributeError:
# We pass fail_if_missing=True to load_libc_function and
# then ignore the error. It's weird, but otherwise we have
# to check if self._func_handle is noop_libc_function, and
# that's even weirder.
pass
else:
self._func_handle = func_handle
self._loaded = True
@property

View File

@ -7699,6 +7699,15 @@ class TestFallocate(unittest.TestCase):
# work the way you'd expect with ctypes :-/
self.assertEqual(sys_fallocate_mock.mock_calls[0][1][2].value, 0)
self.assertEqual(sys_fallocate_mock.mock_calls[0][1][3].value, 0)
sys_fallocate_mock.reset_mock()
# negative size will be adjusted as 0
utils.fallocate(0, -1, 0)
self.assertEqual(
[mock.call(0, utils.FALLOC_FL_KEEP_SIZE, mock.ANY, mock.ANY)],
sys_fallocate_mock.mock_calls)
self.assertEqual(sys_fallocate_mock.mock_calls[0][1][2].value, 0)
self.assertEqual(sys_fallocate_mock.mock_calls[0][1][3].value, 0)
@patch.object(os, 'fstatvfs')
@ -7890,6 +7899,8 @@ class TestPunchHole(unittest.TestCase):
with self.assertRaises(ValueError):
utils.punch_hole(0, 1, -1)
with self.assertRaises(ValueError):
utils.punch_hole(0, 1 << 64, 1)
with self.assertRaises(ValueError):
utils.punch_hole(0, -1, 1)
with self.assertRaises(ValueError):