diff options
author | Mohammed Junaid <junaid@redhat.com> | 2013-02-10 02:10:25 +0530 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2013-03-07 03:00:10 -0800 |
commit | ee5df68f08e44451e14c42adc9bc4d38721b5d6c (patch) | |
tree | d6e1b69d2064c2dfa420226c6b35a2c23e7ea707 | |
parent | 598ca6bbaabc0b67708a1ecfbef1372eb9927ed9 (diff) |
object-storage: Fixing the errors and warnings in unittest.
Change-Id: Id22c968aefd82c4b62445b3ecc93cbabc2b35ffc
BUG: 887301
Signed-off-by: Mohammed Junaid <junaid@redhat.com>
Reviewed-on: http://review.gluster.org/4394
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Peter Portante <pportant@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
-rw-r--r-- | ufo/test/unit/common/test_diskfile.py | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/ufo/test/unit/common/test_diskfile.py b/ufo/test/unit/common/test_diskfile.py index fb0dc3e16d5..85d539a29f0 100644 --- a/ufo/test/unit/common/test_diskfile.py +++ b/ufo/test/unit/common/test_diskfile.py @@ -66,6 +66,21 @@ def _mock_do_unlink(f): raise ose +def _mock_do_unlink_eacces_err(f): + ose = OSError() + ose.errno = errno.EACCES + raise ose + +def _mock_getsize_eaccess_err(f): + ose = OSError() + ose.errno = errno.EACCES + raise ose + +def _mock_do_rmdir_eacces_err(f): + ose = OSError() + ose.errno = errno.EACCES + raise ose + class MockRenamerCalled(Exception): pass @@ -654,13 +669,16 @@ class TestDiskFile(unittest.TestCase): os.chmod(the_path, stats.st_mode & (~stat.S_IWUSR)) # Handle the case do_unlink() raises an OSError + __os_unlink = os.unlink + os.unlink = _mock_do_unlink_eacces_err try: gdf.unlinkold(normalize_timestamp(later)) except OSError as e: - assert e.errno != errno.ENOENT + assert e.errno == errno.EACCES else: self.fail("Excepted an OSError when unlinking file") finally: + os.unlink = __os_unlink os.chmod(the_path, stats.st_mode) assert os.path.isdir(gdf.datadir) @@ -699,11 +717,14 @@ class TestDiskFile(unittest.TestCase): stats = os.stat(gdf.datadir) os.chmod(gdf.datadir, 0) + __os_rmdir = os.rmdir + os.rmdir = _mock_do_rmdir_eacces_err try: later = float(gdf.metadata['X-Timestamp']) + 1 gdf.unlinkold(normalize_timestamp(later)) finally: os.chmod(gdf.datadir, stats.st_mode) + os.rmdir = __os_rmdir assert os.path.isdir(gdf.datadir) assert os.path.isdir(gdf.data_file) finally: @@ -795,13 +816,16 @@ class TestDiskFile(unittest.TestCase): assert not gdf._is_dir stats = os.stat(the_path) os.chmod(the_path, 0) + __os_path_getsize = os.path.getsize + os.path.getsize = _mock_getsize_eaccess_err try: s = gdf.get_data_file_size() except OSError as err: - assert err.errno != errno.ENOENT + assert err.errno == errno.EACCES else: self.fail("Expected OSError exception") finally: + os.path.getsize = __os_path_getsize os.chmod(the_path, stats.st_mode) finally: shutil.rmtree(td) @@ -873,7 +897,15 @@ class TestDiskFile(unittest.TestCase): assert os.path.basename(saved_tmppath)[:3] == '.z.' assert os.path.exists(saved_tmppath) os.write(fd, "123") + # At the end of previous with block a close on fd is called. + # Calling os.close on the same fd will raise an OSError + # exception and we must catch it. + try: os.close(fd) + except OSError as err: + pass + else: + self.fail("Exception expected") assert not os.path.exists(saved_tmppath) finally: shutil.rmtree(td) |