Changeset 17327 for main/waeup.kofa/trunk/src
- Timestamp:
- 31 Jan 2023, 16:15:54 (22 months ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/startup.py
r12110 r17327 49 49 """ 50 50 import os 51 import sys 52 import zdaemon.zdctl 51 53 from ConfigParser import RawConfigParser 52 from grokcore.startup import application_factory, debug_application_factory 54 from grokcore.startup import ( 55 application_factory, debug_application_factory, 56 interactive_debug_prompt) 57 53 58 54 59 def _set_env_vars(global_conf): … … 62 67 os.environ[key] = val 63 68 return 69 64 70 65 71 def env_app_factory(global_conf, **local_conf): … … 94 100 return application_factory(global_conf, **local_conf) 95 101 102 96 103 def env_debug_app_factory(global_conf, **local_conf): 97 104 """A debugger application factory. … … 104 111 _set_env_vars(global_conf) 105 112 return debug_application_factory(global_conf, **local_conf) 113 114 115 class ControllerCommands(zdaemon.zdctl.ZDCmd): 116 117 def do_debug(self, rest): 118 zope_conf = os.path.join('parts', 'etc', 'zope.conf') 119 del sys.argv[0] 120 interactive_debug_prompt(zope_conf=zope_conf) 121 122 def help_debug(self): 123 print("debug -- Initialize the application, providing a debugger") 124 print(" object at an interactive Python prompt.") 125 126 127 def zdaemon_controller(zdaemon_conf=os.path.join('parts', 'etc', 128 'zdaemon.conf')): 129 args = ['-C', zdaemon_conf] + sys.argv[1:] 130 zdaemon.zdctl.main(args, options=None, cmdclass=ControllerCommands) -
main/waeup.kofa/trunk/src/waeup/kofa/tests/test_startup.py
r12110 r17327 1 1 # Tests for local startup functions. 2 import mock 2 3 import os 3 4 import shutil 5 import sys 4 6 import tempfile 5 7 import unittest 8 # from zdaemon.zdctl import 9 import zdaemon.zdctl 6 10 from zope.app.wsgi import WSGIPublisherApplication 7 from waeup.kofa.startup import env_app_factory, env_debug_app_factory 11 # from zdaemon.tests.testzdctl import run as run_zdctl 12 from waeup.kofa.startup import ( 13 env_app_factory, env_debug_app_factory, zdaemon_controller, 14 ) 15 try: 16 from StringIO import StringIO # py2 17 except ImportError: 18 from io import StringIO # py3 19 20 8 21 9 22 ZOPE_CONF_TEMPL = ''' … … 21 34 ''' 22 35 36 37 ZDAEMON_CONF_TEMPL = ''' 38 <runner> 39 program echo "zdaemon started" 40 </runner> 41 ''' 42 43 23 44 class StartUpTests(unittest.TestCase): 24 45 … … 29 50 self.zope_conf = os.path.join(self.workdir, 'zope.conf') 30 51 open(self.zope_conf, 'wb').write(ZOPE_CONF_TEMPL % self.site_zcml) 52 self.zdaemon_conf = os.path.join(self.workdir, 'zdaemon.conf') 53 open(self.zdaemon_conf, 'wb').write(ZDAEMON_CONF_TEMPL) 31 54 return 32 55 … … 75 98 self.assertEqual(os.environ.get('TEST_FOO', None), 'value1') 76 99 return 100 101 @mock.patch("sys.stdout", new_callable=StringIO) 102 def test_zdaemon_has_debug_help(self, mock_out): 103 # We provide a `debug` help text for `kofactl` 104 with mock.patch.object(sys, "argv", ["kofactl", "help", "debug"]): 105 with self.assertRaises(SystemExit): 106 zdaemon_controller(zdaemon_conf=self.zdaemon_conf) 107 self.assertTrue("providing a debugger" in mock_out.getvalue()) 108 109 @mock.patch("waeup.kofa.startup.interactive_debug_prompt") 110 def test_zdaemon_can_start_debug(self, mock_prompt): 111 # We can actually run the debugger... 112 with mock.patch.object(sys, "argv", ["kofactl", "debug"]): 113 with self.assertRaises(SystemExit): 114 zdaemon_controller(zdaemon_conf=self.zdaemon_conf) 115 self.assertTrue(mock_prompt.called)
Note: See TracChangeset for help on using the changeset viewer.