sapling/eden/test_support/environment_variable.py
Adam Simpkins c763e922a2 kill off some of the integration test mixin classes
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
2020-04-22 15:02:42 -07:00

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)