(tmp_path, tmp_path_factory)
| 179 | |
| 180 | @pytest.fixture |
| 181 | def short_socket_name(tmp_path, tmp_path_factory): # pragma: py-win32 |
| 182 | max_sock_len = 100 |
| 183 | socket_filename = "my.sock" |
| 184 | identifier = f"{uuid4()}-" |
| 185 | identifier_len = len(identifier.encode()) |
| 186 | tmp_dir = Path("/tmp").resolve() |
| 187 | os_tmp_dir = Path(os.getenv("TMPDIR", "/tmp")).resolve() |
| 188 | basetemp = Path( |
| 189 | str(tmp_path_factory.getbasetemp()), |
| 190 | ).resolve() |
| 191 | hash_basetemp = md5( |
| 192 | str(basetemp).encode(), |
| 193 | ).hexdigest() |
| 194 | |
| 195 | def make_tmp_dir(base_dir): |
| 196 | return TemporaryDirectory( |
| 197 | dir=str(base_dir), |
| 198 | prefix="p-", |
| 199 | suffix=f"-{hash_basetemp}", |
| 200 | ) |
| 201 | |
| 202 | paths = basetemp, os_tmp_dir, tmp_dir |
| 203 | for _num, tmp_dir_path in enumerate(paths, 1): |
| 204 | with make_tmp_dir(tmp_dir_path) as tmpd: |
| 205 | tmpd = Path(tmpd).resolve() |
| 206 | sock_path = str(tmpd / socket_filename) |
| 207 | sock_path_len = len(sock_path.encode()) |
| 208 | if sock_path_len <= max_sock_len: |
| 209 | if max_sock_len - sock_path_len >= identifier_len: # pragma: no cover |
| 210 | sock_path = str(tmpd / "".join((identifier, socket_filename))) |
| 211 | yield sock_path |
| 212 | return |
| 213 | |
| 214 | |
| 215 | def _unused_port(socket_type: int) -> int: |
nothing calls this directly
no test coverage detected