Skip to content

Commit cdb82f0

Browse files
committed
remove ZIM reference in filesystem exceptions
1 parent ddbf524 commit cdb82f0

File tree

4 files changed

+41
-40
lines changed

4 files changed

+41
-40
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
### Changed
10+
### Breaking Changes
1111

12-
- **BREAKING** Renamed `filesystem.validate_zimfile_creatable` to `filesystem.file_creatable` to reflect general applicability to check file creation beyond ZIM files #200
12+
- Renamed `filesystem.validate_zimfile_creatable` to `filesystem.file_creatable` to reflect general applicability to check file creation beyond ZIM files #200
13+
- Remove any "ZIM" reference in exceptions while working with files.
1314

1415
### Added
1516

src/zimscraperlib/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "4.0.1-dev0"
1+
__version__ = "5.0.0-dev0"

src/zimscraperlib/zim/filesystem.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -220,33 +220,33 @@ def make_zim_file(
220220
zim_file.finish()
221221

222222

223-
class IncorrectZIMPathError(Exception):
224-
"""A generic exception for any problem encountered in validate_zimfile_creatable"""
223+
class IncorrectPathError(Exception):
224+
"""A generic exception for any problem encountered while working with filepaths"""
225225

226226
pass
227227

228228

229-
class MissingZIMFolderError(IncorrectZIMPathError):
230-
"""Exception raised in validate_zimfile_creatable when folder does not exists"""
229+
class MissingFolderError(IncorrectPathError):
230+
"""Exception raised when folder does not exist"""
231231

232232
pass
233233

234234

235-
class NotADirectoryZIMFolderError(IncorrectZIMPathError):
236-
"""Exception raised in validate_zimfile_creatable when folder is not a directory"""
235+
class NotADirectoryFolderError(IncorrectPathError):
236+
"""Exception raised when folder is not a directory"""
237237

238238
pass
239239

240240

241-
class NotWritableZIMFolderError(IncorrectZIMPathError):
242-
"""Exception raised in validate_zimfile_creatable when folder is not writable"""
241+
class NotWritableFolderError(IncorrectPathError):
242+
"""Exception raised when folder is not writable"""
243243

244244
pass
245245

246246

247-
class IncorrectZIMFilenameError(IncorrectZIMPathError):
247+
class IncorrectFilenameError(IncorrectPathError):
248248
"""
249-
Exception raised in validate_zimfile_creatable when filename is not creatable
249+
Exception raised when filename is not creatable
250250
251251
This usually occurs when bad characters are present in filename (typically
252252
characters not supported on current filesystem).
@@ -258,21 +258,21 @@ class IncorrectZIMFilenameError(IncorrectZIMPathError):
258258
def validate_folder_writable(folder: pathlib.Path):
259259
"""Validate that a file can be created in a given folder.
260260
261-
Any problem encountered raises an exception inheriting from IncorrectZIMPathError
261+
Any problem encountered raises an exception inheriting from IncorrectPathError
262262
263263
Checks that:
264-
- folder passed exists (or raise MissingZIMFolderError exception)
265-
- folder passed is a directory (or raise NotADirectoryZIMFolderError exception)
264+
- folder passed exists (or raise MissingFolderError exception)
265+
- folder passed is a directory (or raise NotADirectoryFolderError exception)
266266
- folder is writable, i.e. it is possible to create a file in folder (or raise
267-
NotWritableZIMFolderError exception with inner exception details)
267+
NotWritableFolderError exception with inner exception details)
268268
"""
269269
# ensure folder exists
270270
if not folder.exists():
271-
raise MissingZIMFolderError(f"Folder does not exist: {folder}")
271+
raise MissingFolderError(f"Folder does not exist: {folder}")
272272

273273
# ensure folder is a directory
274274
if not folder.is_dir():
275-
raise NotADirectoryZIMFolderError(f"Folder is not a directory: {folder}")
275+
raise NotADirectoryFolderError(f"Folder is not a directory: {folder}")
276276

277277
logger.debug(f"Attempting to confirm output is writable in directory {folder}")
278278

@@ -281,17 +281,17 @@ def validate_folder_writable(folder: pathlib.Path):
281281
with tempfile.NamedTemporaryFile(dir=folder, delete=True) as fh:
282282
logger.debug(f"Output is writable. Temporary file used for test: {fh.name}")
283283
except Exception as exc:
284-
raise NotWritableZIMFolderError(f"Folder is not writable: {folder}") from exc
284+
raise NotWritableFolderError(f"Folder is not writable: {folder}") from exc
285285

286286

287287
def validate_file_creatable(folder: str | pathlib.Path, filename: str):
288288
"""Validate that a file can be created in given folder with given filename
289289
290-
Any problem encountered raises an exception inheriting from IncorrectZIMPathError
290+
Any problem encountered raises an exception inheriting from IncorrectPathError
291291
292292
Checks that:
293293
- folder is writable (or raise exception from `validate_folder_writable`)
294-
- file can be created (or raise IncorrectZIMFilenameError exception with
294+
- file can be created (or raise IncorrectFilenameError exception with
295295
inner exception details)
296296
"""
297297
folder = pathlib.Path(folder)
@@ -305,21 +305,21 @@ def validate_file_creatable(folder: str | pathlib.Path, filename: str):
305305
fpath.touch()
306306
fpath.unlink()
307307
except Exception as exc:
308-
raise IncorrectZIMFilenameError(f"File is not creatable: {fpath}") from exc
308+
raise IncorrectFilenameError(f"File is not creatable: {fpath}") from exc
309309

310310

311311
def validate_zimfile_creatable(folder: str | pathlib.Path, filename: str):
312312
"""Validate that a ZIM can be created in given folder with given filename
313313
314-
Any problem encountered raises an exception inheriting from IncorrectZIMPathError
314+
Any problem encountered raises an exception inheriting from IncorrectPathError
315315
316316
Checks that:
317-
- folder passed exists (or raise MissingZIMFolderError exception)
318-
- folder passed is a directory (or raise NotADirectoryZIMFolderError exception)
317+
- folder passed exists (or raise MissingFolderError exception)
318+
- folder passed is a directory (or raise NotADirectoryFolderError exception)
319319
- folder is writable, i.e. it is possible to create a file in folder (or raise
320-
NotWritableZIMFolderError exception with inner exception details)
320+
NotWritableFolderError exception with inner exception details)
321321
- filename is creatable, i.e. there is no bad characters in filename (or raise
322-
IncorrectZIMFilenameError exception with inner exception details)
322+
IncorrectFilenameError exception with inner exception details)
323323
"""
324324
warnings.warn(
325325
"'validate_zimfile_creatable' is deprecated and will be removed. "

tests/zim/test_fs.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from zimscraperlib.zim.archive import Archive
1212
from zimscraperlib.zim.filesystem import (
1313
FileItem,
14-
IncorrectZIMFilenameError,
15-
MissingZIMFolderError,
16-
NotADirectoryZIMFolderError,
17-
NotWritableZIMFolderError,
14+
IncorrectFilenameError,
15+
MissingFolderError,
16+
NotADirectoryFolderError,
17+
NotWritableFolderError,
1818
make_zim_file,
1919
validate_file_creatable,
2020
validate_folder_writable,
@@ -180,46 +180,46 @@ def test_validate_zimfile_creatable_ok(tmp_path, valid_zim_filename):
180180

181181
def test_validate_zimfile_creatable_folder_not_exists(tmp_path, valid_zim_filename):
182182

183-
with pytest.raises(MissingZIMFolderError):
183+
with pytest.raises(MissingFolderError):
184184
validate_zimfile_creatable(tmp_path / "foo", valid_zim_filename)
185185

186186

187187
def test_validate_zimfile_creatable_bad_folder(tmp_path, valid_zim_filename):
188188

189-
with pytest.raises(NotADirectoryZIMFolderError):
189+
with pytest.raises(NotADirectoryFolderError):
190190
(tmp_path / "foo.txt").touch()
191191
validate_zimfile_creatable(tmp_path / "foo.txt", valid_zim_filename)
192192

193193

194194
def test_validate_zimfile_creatable_folder_not_writable(tmp_path, valid_zim_filename):
195195

196-
with pytest.raises(NotWritableZIMFolderError):
196+
with pytest.raises(NotWritableFolderError):
197197
(tmp_path / "foo").mkdir(mode=111)
198198
validate_zimfile_creatable(tmp_path / "foo", valid_zim_filename)
199199

200200

201201
def test_validate_zimfile_creatable_bad_name(tmp_path):
202202

203-
with pytest.raises(IncorrectZIMFilenameError):
203+
with pytest.raises(IncorrectFilenameError):
204204
validate_zimfile_creatable(tmp_path, "t\0t\0.zim")
205205

206206

207207
def test_validate_folder_writable_not_exists(tmp_path):
208208

209-
with pytest.raises(MissingZIMFolderError):
209+
with pytest.raises(MissingFolderError):
210210
validate_folder_writable(tmp_path / "foo")
211211

212212

213213
def test_validate_folder_writable_not_dir(tmp_path):
214214

215-
with pytest.raises(NotADirectoryZIMFolderError):
215+
with pytest.raises(NotADirectoryFolderError):
216216
(tmp_path / "foo.txt").touch()
217217
validate_folder_writable(tmp_path / "foo.txt")
218218

219219

220220
def test_validate_folder_writable_not_writable(tmp_path):
221221

222-
with pytest.raises(NotWritableZIMFolderError):
222+
with pytest.raises(NotWritableFolderError):
223223
(tmp_path / "foo").mkdir(mode=111)
224224
validate_folder_writable(tmp_path / "foo")
225225

@@ -235,5 +235,5 @@ def test_validate_file_creatable_ok(tmp_path, valid_zim_filename):
235235

236236
def test_validate_file_creatable_bad_name(tmp_path):
237237

238-
with pytest.raises(IncorrectZIMFilenameError):
238+
with pytest.raises(IncorrectFilenameError):
239239
validate_file_creatable(tmp_path, "t\0t\0.zim")

0 commit comments

Comments
 (0)