Ignore:
Timestamp:
31 Jan 2023, 16:15:54 (20 months ago)
Author:
uli
Message:

Upgrade grokcore.startup

while still keeping the possibility to use zdaemon. This change requires
rerunning buildout.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/tests/test_startup.py

    r12110 r17327  
    11# Tests for local startup functions.
     2import mock
    23import os
    34import shutil
     5import sys
    46import tempfile
    57import unittest
     8# from zdaemon.zdctl import
     9import zdaemon.zdctl
    610from 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
     12from waeup.kofa.startup import (
     13        env_app_factory, env_debug_app_factory, zdaemon_controller,
     14        )
     15try:
     16    from StringIO import StringIO  # py2
     17except ImportError:
     18    from io import StringIO        # py3
     19
     20
    821
    922ZOPE_CONF_TEMPL = '''
     
    2134'''
    2235
     36
     37ZDAEMON_CONF_TEMPL = '''
     38<runner>
     39  program echo "zdaemon started"
     40</runner>
     41'''
     42
     43
    2344class StartUpTests(unittest.TestCase):
    2445
     
    2950        self.zope_conf = os.path.join(self.workdir, 'zope.conf')
    3051        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)
    3154        return
    3255
     
    7598        self.assertEqual(os.environ.get('TEST_FOO', None), 'value1')
    7699        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.