예제 #1
0
파일: util.py 프로젝트: simpkins/eden
    def setup(self) -> None:
        self.temp_mgr = TempFileManager()
        self.test_tmp = self.temp_mgr.make_temp_dir()

        hgrc_path = os.path.join(new_dir(), "global_hgrc")
        self.env = {
            "HGRCPATH": hgrc_path,
            "TESTTMP": str(self.test_tmp),
            "TEST_PROD_CONFIGS": "true",
        }
예제 #2
0
 def __init__(
     self,
     path: str,
     system_hgrc: Optional[str] = None,
     temp_mgr: Optional[TempFileManager] = None,
 ) -> None:
     """
     If hgrc is specified, it will be used as the value of the HGRCPATH
     environment variable when `hg` is run.
     """
     super().__init__(path)
     self.temp_mgr = temp_mgr or TempFileManager("hgrepo")
     self.hg_environment = os.environ.copy()
     # Drop any environment variables starting with 'HG'
     # to ensure the user's environment does not affect the tests.
     self.hg_environment = {
         k: v for k, v in os.environ.items() if not k.startswith("HG")
     }
     self.hg_environment["HGPLAIN"] = "1"
     self.hg_environment["HG_REAL_BIN"] = FindExe.HG_REAL
     self.hg_environment["NOSCMLOG"] = "1"
     self.hg_environment["LOCALE"] = "en_US.UTF-8"
     self.hg_environment["LC_ALL"] = "en_US.UTF-8"
     # Set HGRCPATH to make sure we aren't affected by the local system's
     # mercurial settings from /etc/mercurial/
     if system_hgrc:
         self.hg_environment["HGRCPATH"] = system_hgrc
     else:
         self.hg_environment["HGRCPATH"] = ""
     self.hg_bin = FindExe.HG
예제 #3
0
def temp_systemd(
        temp_mgr: TempFileManager) -> Iterator[SystemdUserServiceManager]:
    """Create an isolated systemd instance for tests."""
    parent_systemd: BaseSystemdUserServiceManager = BaseSystemdUserServiceManager(
        xdg_runtime_dir=_get_current_xdg_runtime_dir())

    def should_create_managed() -> bool:
        forced_type_variable = "EDEN_TEST_FORCE_SYSTEMD_USER_SERVICE_MANAGER_TYPE"
        forced_type = os.getenv(forced_type_variable)
        if forced_type is not None and forced_type:
            if forced_type == "managed":
                return True
            if forced_type == "unmanaged":
                return False
            raise ValueError(
                f"Unsupported value for {forced_type_variable}: {forced_type!r}"
            )

        if not _is_system_booted_with_systemd():
            return False

        # It's possible that the system was booted with systemd but PID 1 is not
        # systemd. This happens on Sandcastle (Facebook's CI) which runs tests
        # in a Linux process namespace. If this is the case, systemctl and
        # systemd-run fail with the following message:
        #
        # > Failed to connect to bus: No data available
        #
        # If we can't talk to the system's systemd for this reason, run our
        # temporary systemd user service manager unmanaged.
        if os.getuid() == 0 and not parent_systemd.is_alive():
            return False

        return True

    lifetime_duration = 30
    xdg_runtime_dir = temp_mgr.make_temp_dir("xdg_runtime")
    if should_create_managed():
        with _transient_managed_systemd_user_service_manager(
                xdg_runtime_dir=xdg_runtime_dir,
                parent_systemd=parent_systemd,
                lifetime_duration=lifetime_duration,
        ) as child_systemd:
            yield child_systemd
    else:
        with _TransientUnmanagedSystemdUserServiceManager(
                xdg_runtime_dir=xdg_runtime_dir,
                lifetime_duration=lifetime_duration) as systemd:
            yield systemd
예제 #4
0
파일: util.py 프로젝트: simpkins/eden
class GlobalTestState(threading.local):
    temp_mgr: TempFileManager
    test_tmp: Path
    env: Dict[str, str]

    def __init__(self) -> None:
        # These are needed to satisfy pyre, but should never be used.
        self.temp_mgr = TempFileManager()
        self.test_tmp = Path("")
        self.env = {}

    def setup(self) -> None:
        self.temp_mgr = TempFileManager()
        self.test_tmp = self.temp_mgr.make_temp_dir()

        hgrc_path = os.path.join(new_dir(), "global_hgrc")
        self.env = {
            "HGRCPATH": hgrc_path,
            "TESTTMP": str(self.test_tmp),
            "TEST_PROD_CONFIGS": "true",
        }

    def cleanup(self) -> None:
        self.temp_mgr.cleanup()
예제 #5
0
 def __init__(self, path: str, temp_mgr: Optional[TempFileManager] = None) -> None:
     super().__init__(path)
     self.git_bin = FindExe.GIT  # pyre-ignore[8]: T38947910
     self.temp_mgr = temp_mgr or TempFileManager("gitrepo")
예제 #6
0
def temporary_systemd_user_service_manager(
) -> typing.Iterator[SystemdUserServiceManager]:
    temp_mgr = TempFileManager()
    with temp_systemd(temp_mgr) as systemd:
        yield systemd
예제 #7
0
파일: util.py 프로젝트: simpkins/eden
 def __init__(self) -> None:
     # These are needed to satisfy pyre, but should never be used.
     self.temp_mgr = TempFileManager()
     self.test_tmp = Path("")
     self.env = {}