def test_clear(self) -> None: with tempfile.NamedTemporaryFile() as f: pid_saver = PidSaver(logger=mock.MagicMock(), pids_file_path=f.name) pid = 1 pid_saver.save_companion_pid(pid) pid_saver._clear_saved_pids() pid_saver._load() self.assertEqual(pid_saver.companion_pids, []) self.assertEqual(pid_saver.notifier_pid, 0)
def test_get_saved_pids(self) -> None: with tempfile.NamedTemporaryFile() as f: pid_saver = PidSaver(logger=mock.MagicMock(), pids_file_path=f.name) companion_pids = [1, 2] notifier_pid = 3 with open(f.name, "w") as f: json.dump(({ "companions": companion_pids, "notifier": notifier_pid }), f) pid_saver._load() self.assertEqual(pid_saver.companion_pids, companion_pids) self.assertEqual(pid_saver.notifier_pid, notifier_pid)