From 814a76689f69957f0d092546e07c0c1ce9c3d38b Mon Sep 17 00:00:00 2001 From: Kota Tsuyuzaki Date: Sat, 15 Sep 2018 06:49:18 +0900 Subject: [PATCH] Follow up punch_hole patch Add missing tests to get more coverage and reduce a line. Change-Id: I34d8063ee82323c9751b4c965bee01ab584c5eb5 --- swift/common/utils.py | 3 +-- test/unit/common/test_utils.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/swift/common/utils.py b/swift/common/utils.py index 68ffcbf167..5ca12b66c4 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -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 diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index be3e2c8f6d..0b4c3c53b1 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -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):