core: cleanup my.core.common.unique_everseen

- move to my.core.utils.itertools
- more robust check for hashable types -- now checks in runtime (since the one based on types purely isn't necessarily sound)
- add more testing
This commit is contained in:
Dima Gerasimov 2024-08-15 13:28:45 +03:00
parent e7089a0961
commit b390f8b1cb
3 changed files with 183 additions and 63 deletions

View file

@ -1,4 +1,6 @@
from contextlib import contextmanager
import os
from typing import Iterator, Optional
import pytest
@ -10,3 +12,20 @@ skip_if_uses_optional_deps = pytest.mark.skipif(
V not in os.environ,
reason=f'test only works when optional dependencies are installed. Set env variable {V}=true to override.',
)
# TODO maybe move to hpi core?
@contextmanager
def tmp_environ_set(key: str, value: Optional[str]) -> Iterator[None]:
prev_value = os.environ.get(key)
if value is None:
os.environ.pop(key, None)
else:
os.environ[key] = value
try:
yield
finally:
if prev_value is None:
os.environ.pop(key, None)
else:
os.environ[key] = prev_value