Skip to content

Commit

Permalink
debug() test more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
tschorr committed Oct 3, 2018
1 parent 13cceb6 commit b999c20
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Zope2/utilities/tests/test_zconsole.py
Expand Up @@ -38,8 +38,6 @@ def setUp(self):
conffile.write(zope_conf_template.format(self.instancedir))

def test_debug(self):
# XXX it would be nice to test debug_console, but somehow
# the call to os.system seems to get in the way
with Popen(sys.executable, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) as test: # noqa: E501
test.stdin.write(
bytes('from Zope2.utilities.zconsole import debug; app = debug("{}")\n'.format( # noqa: E501
Expand All @@ -48,8 +46,17 @@ def test_debug(self):
got, errs = test.communicate(b'print(app)\n', timeout=1)
except TimeoutExpired:
test.kill()
expected = b'<Application at >\n'
self.assertEqual(expected, got)
stored_sys_argv = sys.argv
stored_stdout = sys.stdout
try:
from Zope2.utilities.zconsole import debug
sys.stdout = io.StringIO()
got = debug(self.zopeconf)
expected = '<Application at >'
finally:
sys.argv = stored_sys_argv
sys.stdout = stored_stdout
self.assertEqual(expected, str(got))

def test_runscript(self):
script = os.path.join(self.instancedir, 'test_script.py')
Expand Down

0 comments on commit b999c20

Please sign in to comment.