Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tschorr committed Oct 4, 2018
1 parent 015bca6 commit 26cf728
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ https://github.com/zopefoundation/Zope/blob/4.0a6/CHANGES.rst
New features
++++++++++++

- add zconsole module for running scripts and interactive mode
- Add zconsole module for running scripts and interactive mode.

- Restore support for XML-RPC when using the WSGI publisher - dropped in 4.0a2.

Expand Down
24 changes: 11 additions & 13 deletions src/Zope2/utilities/tests/test_zconsole.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import os
import shutil
import sys
import tempfile
import unittest

if sys.version_info.major == 2:
from StringIO import StringIO
else:
from io import StringIO
from six import StringIO

zope_conf_template = """
%define INSTANCE {}
Expand Down Expand Up @@ -37,28 +34,29 @@ class ZConsoleTestCase(unittest.TestCase):
def setUp(self):
self.instancedir = tempfile.mkdtemp(prefix='instance')
self.zopeconf = os.path.join(self.instancedir, 'zope.conf')
self.stored_sys_argv = sys.argv
self.stored_stdout = sys.stdout
with open(self.zopeconf, 'w') as conffile:
conffile.write(zope_conf_template.format(self.instancedir))

def tearDown(self):
shutil.rmtree(self.instancedir)

def test_debug(self):
stored_sys_argv = sys.argv
stored_stdout = sys.stdout
try:
from Zope2.utilities.zconsole import debug
sys.stdout = StringIO()
got = debug(self.zopeconf)
expected = '<Application at >'
finally:
sys.argv = stored_sys_argv
sys.stdout = stored_stdout
sys.argv = self.stored_sys_argv
sys.stdout = self.stored_stdout
self.assertEqual(expected, str(got))

def test_runscript(self):
script = os.path.join(self.instancedir, 'test_script.py')
with open(script, 'w') as scriptfile:
scriptfile.write(test_script)
stored_sys_argv = sys.argv
stored_stdout = sys.stdout
try:
from Zope2.utilities.zconsole import runscript
sys.argv = [
Expand All @@ -73,7 +71,7 @@ def test_runscript(self):
sys.stdout.seek(0)
got = sys.stdout.read()
finally:
sys.argv = stored_sys_argv
sys.stdout = stored_stdout
sys.argv = self.stored_sys_argv
sys.stdout = self.stored_stdout
expected = "42\n['run', '{}', '{}', 'bar', 'baz']\n".format(self.zopeconf, script) # noqa: E501
self.assertEqual(expected, got)

0 comments on commit 26cf728

Please sign in to comment.