def test_open_is_called(self, dc_open): utils.daemonize("run/tests.pid", self.tmp_dir, False, False, do_open=True) self.assertEqual(dc_open.call_count, 1)
def test_daemonize_not_fully(dc_open): context = utils.daemonize("run/tests.pid", ".", False, False, do_open=False) assert context assert not dc_open.called dc_open.reset_mock() context = utils.daemonize("run/tests.pid", ".", "/tmp", 0002, do_open=True) assert context assert dc_open.called
def test_daemonize_not_fully(dc_open): context = utils.daemonize("run/tests.pid", ".", False, False, do_open=False) assert context assert_equal(dc_open.call_count, 0) dc_open.reset_mock() context = utils.daemonize("run/tests.pid", ".", "/tmp", 0o002, do_open=True) assert context assert_equal(dc_open.call_count, 1)
def test_chdir_does_not_exist(self, dc_open): chdir = os.path.join(self.tmp_dir, "test") with self.assertRaises(OSError): utils.daemonize("run/tests.pid", chdir, False, False, do_open=False) self.assertEqual(dc_open.call_count, 0)
def test_umask(self, dc_open): context = utils.daemonize("run/tests.pid", self.tmp_dir, False, False, do_open=False) self.assertEqual(context.umask, 0) context = utils.daemonize("run/tests.pid", self.tmp_dir, False, 0o002, do_open=False) self.assertEqual(context.umask, 2)
def test_daemonize_not_fully(dc_open): context = utils.daemonize("run/tests.pid", ".", False, False, do_open=False) assert context assert not dc_open.called dc_open.reset_mock() context = utils.daemonize("run/tests.pid", ".", "/tmp", 0002, do_open=True) assert context assert dc_open.called
def test_umask(self, dc_open): context = utils.daemonize("run/tests.pid", self.tmp_dir, None, 0o002, do_open=False) self.assertEqual(context.chroot_directory, None) self.assertEqual(context.stdout.name, os.path.join(self.tmp_dir, "logs", "salmon.out")) self.assertEqual(context.stderr.name, os.path.join(self.tmp_dir, "logs", "salmon.err")) self.assertEqual(context.pidfile.path, os.path.join("run", "tests.pid")) self.assertEqual(context.umask, 2)
def test_open_is_called(self, dc_open): context = utils.daemonize("run/tests.pid", self.tmp_dir, None, None, do_open=True) self.assertEqual(dc_open.call_count, 1) self.assertEqual(context.chroot_directory, None) self.assertEqual(context.stdout.name, os.path.join(self.tmp_dir, "logs", "salmon.out")) self.assertEqual(context.stderr.name, os.path.join(self.tmp_dir, "logs", "salmon.err")) self.assertEqual(context.pidfile.path, os.path.join("run", "tests.pid")) self.assertEqual(context.umask, 0)
def test_working_dir(self, dc_open): context = utils.daemonize("run/tests.pid", self.tmp_dir, False, False, do_open=False) self.assertEqual(dc_open.call_count, 0) self.assertEqual(context.working_directory, self.tmp_dir) self.assertEqual(context.chroot_directory, None) self.assertEqual(context.stdout.name, os.path.join(self.tmp_dir, "logs", "salmon.out")) self.assertEqual(context.stderr.name, os.path.join(self.tmp_dir, "logs", "salmon.err")) self.assertEqual(context.pidfile.path, os.path.join("run", "tests.pid"))
def test_logs_dir_already_exists(self, dc_open): os.mkdir(os.path.join(self.tmp_dir, "logs")) with patch("os.mkdir", self.error_maybe(lambda p: p.endswith("/logs"), os.mkdir)): context = utils.daemonize("run/tests.pid", self.tmp_dir, False, False, do_open=False) self.assertEqual(dc_open.call_count, 0) self.assertEqual(context.working_directory, self.tmp_dir) self.assertEqual(context.stdout.name, os.path.join(self.tmp_dir, "logs", "salmon.out")) self.assertEqual(context.stderr.name, os.path.join(self.tmp_dir, "logs", "salmon.err")) self.assertEqual(context.pidfile.path, os.path.join("run", "tests.pid"))