(tmp_path: Path)
| 1211 | |
| 1212 | |
| 1213 | def test_safe_exists(tmp_path: Path) -> None: |
| 1214 | d = tmp_path.joinpath("some_dir") |
| 1215 | d.mkdir() |
| 1216 | assert safe_exists(d) is True |
| 1217 | |
| 1218 | f = tmp_path.joinpath("some_file") |
| 1219 | f.touch() |
| 1220 | assert safe_exists(f) is True |
| 1221 | |
| 1222 | # Use unittest.mock() as a context manager to have a very narrow |
| 1223 | # patch lifetime. |
| 1224 | p = tmp_path.joinpath("some long filename" * 100) |
| 1225 | with unittest.mock.patch.object( |
| 1226 | Path, |
| 1227 | "exists", |
| 1228 | autospec=True, |
| 1229 | side_effect=OSError(errno.ENAMETOOLONG, "name too long"), |
| 1230 | ): |
| 1231 | assert safe_exists(p) is False |
| 1232 | |
| 1233 | with unittest.mock.patch.object( |
| 1234 | Path, |
| 1235 | "exists", |
| 1236 | autospec=True, |
| 1237 | side_effect=ValueError("name too long"), |
| 1238 | ): |
| 1239 | assert safe_exists(p) is False |
| 1240 | |
| 1241 | |
| 1242 | def test_import_sets_module_as_attribute(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…