mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 16:31:02 +03:00
c763e922a2
Summary: This updates the various systemd-related tests to use EdenTestCaseBase, and allows us to delete the EnvironmentVariableMixin and SystemdUserServiceManagerMixin classes. The main goal of this clean-up is to make it easier to consolidate most of the systemd-related code into just a few locations, so that we can more easily disable the systemd-related tests in build environments where systemd is not supported. Reviewed By: wez Differential Revision: D21084098 fbshipit-source-id: d5e05254c689c28751fe48d2dc38d722c7e77ed3
34 lines
859 B
Python
34 lines
859 B
Python
#!/usr/bin/env python3
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2.
|
|
|
|
import abc
|
|
import contextlib
|
|
import os
|
|
from typing import Any, Callable, Generator, Mapping, Optional
|
|
|
|
|
|
def _setenv(name: str, value: Optional[str]) -> None:
|
|
if value is None:
|
|
os.environ.pop(name, None)
|
|
else:
|
|
os.environ[name] = value
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def setenv_scope(name: str, value: Optional[str]) -> Generator[None, None, None]:
|
|
old_value = os.environ.get(name)
|
|
_setenv(name, value)
|
|
yield
|
|
_setenv(name, old_value)
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def unsetenv_scope(name: str) -> Generator[None, None, None]:
|
|
old_value = os.environ.get(name)
|
|
os.environ.pop(name, None)
|
|
yield
|
|
_setenv(name, old_value)
|