def main(): parser = OptionParser() parser.set_usage(_("Usage: billreminder [OPTIONS...]")) parser.add_option('--version', action='store_true', dest='app_version', default=False, help=_('Displays the version number for this application.')) parser.add_option('--verbose', action='store_true', dest='app_verbose', default=False, help=_('Print output messages.')) parser.add_option('--no-daemon', action='store_true', dest='app_nodaemon', default=False, help=_("Don't run as a daemon.")) parser.add_option('--open-gui', action='store_true', dest='app_opengui', default=False, help=_('Start daemon and launch GUI.')) parser.add_option('--stop', action='store_true', dest='app_stop', default=False, help=_('Stop daemon.')) # Verify arguments options, args = parser.parse_args() if options.app_stop: import dbus import dbus.service if verify_service(common.DBUS_INTERFACE): session_bus = dbus.SessionBus() obj = session_bus.get_object(common.DBUS_INTERFACE, common.DBUS_PATH) dbus_interface = dbus.Interface(obj, common.DBUS_INTERFACE) dbus_interface.quit() elif options.app_version: print _('This is %(appname)s - Version: %(version)s') % \ {'appname': _("BillReminder Notifier"), 'version': common.APPVERSION} else: BillReminderd.main(options)
def test_run_loop_forever_when_we_are_detected_daemon(loop_forever): # write same as us signature Daemon().write_pid() main(['--debug', '-f']) assert loop_forever.call_count == 1
def test_refuse_to_run_when_daemon_process_is_already_running( loop_forever, daemon_process_running): daemon_process_running.return_value = True with pytest.raises(SystemExit) as error: main(['--debug', '-f']) assert loop_forever.call_count == 0 assert error.value.code == 1
def test_refuse_to_run_when_another_daemon_process_is_running_with_non_same_pid_as_us( mocker, daemon_process_running, loop_forever): daemon_process_running.return_value = True mocker.patch(main.__module__ + '.os.getpid', return_value=799) # write daemon signature with another pid Daemon().write_pid() # ensure testing pid is not another pid mocker.patch(main.__module__ + '.os.getpid', return_value=790) with pytest.raises(SystemExit) as error: main(['--debug', '-f']) assert loop_forever.call_count == 0 assert error.value.code == 1
def main(): parser = OptionParser() parser.set_usage(_("Usage: billreminder [OPTIONS...]")) parser.add_option( '--version', action='store_true', dest='app_version', default=False, help=_('Displays the version number for this application.')) parser.add_option('--verbose', action='store_true', dest='app_verbose', default=False, help=_('Print output messages.')) parser.add_option('--no-daemon', action='store_true', dest='app_nodaemon', default=False, help=_("Don't run as a daemon.")) parser.add_option('--open-gui', action='store_true', dest='app_opengui', default=False, help=_('Start daemon and launch GUI.')) parser.add_option('--stop', action='store_true', dest='app_stop', default=False, help=_('Stop daemon.')) # Verify arguments options, args = parser.parse_args() if options.app_stop: import dbus import dbus.service if verify_service(common.DBUS_INTERFACE): session_bus = dbus.SessionBus() obj = session_bus.get_object(common.DBUS_INTERFACE, common.DBUS_PATH) dbus_interface = dbus.Interface(obj, common.DBUS_INTERFACE) dbus_interface.quit() elif options.app_version: print _('This is %(appname)s - Version: %(version)s') % \ {'appname': _("BillReminder Notifier"), 'version': common.APPVERSION} else: BillReminderd.main(options)
def test_correct_calls(self): """Ensure the main method makes the correct calls to reproduce.""" with self.assertRaises(SystemExit): main.main() self.assert_exact_calls(self.mock.load_sanity_check_testcases, [mock.call()]) self.assert_exact_calls(self.mock.load_new_testcases, [mock.call(), mock.call()]) self.assert_exact_calls(self.mock.reset_and_run_testcase, [ mock.call(1, 'sanity', sys.argv[1]), mock.call(2, 'sanity', sys.argv[1]), mock.call(3, 'continuous', sys.argv[1]), mock.call(4, 'continuous', sys.argv[1]), mock.call(5, 'continuous', sys.argv[1])]) self.assertEqual(2, self.mock.update_auth_header.call_count)
def test_correct_calls(self): """Ensure the main method makes the correct calls to reproduce.""" main.main() self.assert_exact_calls( self.mock.load_sanity_check_testcase_ids, [mock.call()]) self.assert_exact_calls( self.mock.load_new_testcases, [mock.call()] * 3) self.assert_exact_calls(self.mock.reset_and_run_testcase, [ mock.call(1, 'sanity', 'release-test'), mock.call(2, 'sanity', 'release-test'), mock.call(3, 'job', 'release-test'), mock.call(4, 'job', 'release-test'), mock.call(5, 'job', 'release-test')]) self.assertEqual(3, self.mock.update_auth_header.call_count) self.mock.prepare_binary_and_get_version.assert_called_once_with( 'release-test')
def test_refuse_to_run_when_osvcd_lock_is_held(loop_forever): from time import sleep def lock_holder(): # need lock holder in separate process with cmlock(lockfile=Env.paths.daemon_lock): sleep(50) from multiprocessing import Process proc = Process(target=lock_holder) proc.start() sleep(0.5) with pytest.raises(SystemExit) as error: main(['--debug', '-f']) proc.terminate() proc.join(timeout=1) assert loop_forever.call_count == 0 assert error.value.code == 1
def test_run_loop_forever_when_daemon_is_dead(loop_forever): with open(Env.paths.daemon_pid, 'w') as pid_file: pid_file.write('1') main(['--debug', '-f']) assert loop_forever.call_count == 1
def test_run_loop_forever_when_no_other_daemon_are_here(loop_forever): main(['--debug', '-f']) assert loop_forever.call_count == 1