| # Copyright 2026 The Fuchsia Authors. All rights reserved. | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| import os | |
| import signal | |
| import tempfile | |
| import unittest | |
| from unittest import mock | |
| class DaemonTestCase(unittest.IsolatedAsyncioTestCase): | |
| """Base test case for daemon unit tests.""" | |
| def run( | |
| self, result: unittest.TestResult | None = None | |
| ) -> unittest.TestResult | None: | |
| previous_handler = signal.getsignal(signal.SIGUSR1) | |
| try: | |
| return super().run(result) | |
| finally: | |
| signal.signal(signal.SIGUSR1, previous_handler) | |
| def setUp(self) -> None: | |
| super().setUp() | |
| runtime_tmp_dir = tempfile.TemporaryDirectory(dir="/tmp") | |
| self.addCleanup(runtime_tmp_dir.cleanup) | |
| env_patcher = mock.patch.dict( | |
| os.environ, | |
| { | |
| "ZXDB_CLI_RUNTIME_DIR": runtime_tmp_dir.name, | |
| "FUCHSIA_BUILD_DIR_FROM_FX": "/out/default", | |
| }, | |
| ) | |
| env_patcher.start() | |
| self.addCleanup(env_patcher.stop) |