File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33 Shortcuts to retrieve mime type using magic"""
44
5- import os
65import pathlib
76from contextlib import contextmanager
87from tempfile import TemporaryDirectory
@@ -40,10 +39,9 @@ def get_content_mimetype(content: bytes | str) -> str:
4039 return MIME_OVERRIDES .get (detected_mime , detected_mime )
4140
4241
43- def delete_callback (fpath : str | pathlib .Path ):
42+ def delete_callback (fpath : pathlib .Path ):
4443 """helper deleting passed filepath"""
45-
46- os .unlink (fpath )
44+ fpath .unlink (missing_ok = True )
4745
4846
4947@contextmanager
Original file line number Diff line number Diff line change @@ -57,6 +57,12 @@ def test_delete_callback(tmp_path: pathlib.Path):
5757
5858 assert not fpath .exists ()
5959
60+ # file already gone should not be a problem
61+ delete_callback (fpath )
62+
63+ # wrong path should not be a problem
64+ delete_callback (pathlib .Path ("/foo.txt" ))
65+
6066
6167def test_path_from_tmp_dir ():
6268 tempdir = TemporaryDirectory ()
You can’t perform that action at this time.
0 commit comments