def test_get_data_file_size_os_err(self): td = tempfile.mkdtemp() the_path = os.path.join(td, "vol0", "bar") the_file = os.path.join(the_path, "z") try: os.makedirs(the_path) with open(the_file, "wb") as fd: fd.write("1234") gdf = DiskFile(td, "vol0", "p57", "ufo47", "bar", "z", self.lg) assert gdf._obj == "z" assert gdf.data_file == the_file assert not gdf._is_dir stats = os.stat(the_path) try: os.chmod(the_path, 0) def _mock_getsize_eaccess_err(f): raise OSError(errno.EACCES, os.strerror(errno.EACCES)) with patch("os.path.getsize", _mock_getsize_eaccess_err): try: gdf.get_data_file_size() except OSError as err: assert err.errno == errno.EACCES else: self.fail("Expected OSError exception") finally: os.chmod(the_path, stats.st_mode) finally: shutil.rmtree(td)
def test_get_data_file_size_dne(self): assert not os.path.exists("/tmp/foo") gdf = DiskFile("/tmp/foo", "vol0", "p57", "ufo47", "bar", "/b/a/z/", self.lg) try: gdf.get_data_file_size() except DiskFileNotExist: pass else: self.fail("Expected DiskFileNotExist exception")
def test_get_data_file_size_dne_os_err(self): td = tempfile.mkdtemp() the_path = os.path.join(td, "vol0", "bar") the_file = os.path.join(the_path, "z") try: os.makedirs(the_path) with open(the_file, "wb") as fd: fd.write("1234") gdf = DiskFile(td, "vol0", "p57", "ufo47", "bar", "z", self.lg) assert gdf._obj == "z" assert gdf.data_file == the_file assert not gdf._is_dir gdf.data_file = gdf.data_file + ".dne" try: gdf.get_data_file_size() except DiskFileNotExist: pass else: self.fail("Expected DiskFileNotExist exception") finally: shutil.rmtree(td)
def test_get_data_file_size_dir(self): td = tempfile.mkdtemp() the_path = os.path.join(td, "vol0", "bar") the_dir = os.path.join(the_path, "d") try: os.makedirs(the_dir) gdf = DiskFile(td, "vol0", "p57", "ufo47", "bar", "d", self.lg, keep_data_fp=True) assert gdf._obj == "d" assert gdf.data_file == the_dir assert gdf._is_dir assert 0 == gdf.get_data_file_size() finally: shutil.rmtree(td)
def test_get_data_file_size(self): td = tempfile.mkdtemp() the_path = os.path.join(td, "vol0", "bar") the_file = os.path.join(the_path, "z") try: os.makedirs(the_path) with open(the_file, "wb") as fd: fd.write("1234") gdf = DiskFile(td, "vol0", "p57", "ufo47", "bar", "z", self.lg) assert gdf._obj == "z" assert gdf.data_file == the_file assert not gdf._is_dir assert 4 == gdf.get_data_file_size() finally: shutil.rmtree(td)