summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-11-11 08:56:08 +0100
committerGeorg Brandl <georg@python.org>2014-11-11 08:56:08 +0100
commit51d35f516f952edfea4ea6c7b3661d2a47e164d3 (patch)
treeca324c52cb734c1c3d446424b851af174ad534d9
parent1b0b3bd0c52d997f707201fbaf973b9f49c5dcb8 (diff)
downloadpygments-51d35f516f952edfea4ea6c7b3661d2a47e164d3.tar.gz
Switch exception test to a different exception from closed streams.
-rw-r--r--tests/test_cmdline.py26
1 files changed, 7 insertions, 19 deletions
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index d6a149ae..64c4245e 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -15,9 +15,8 @@ import sys
import tempfile
import unittest
-from pygments import highlight
+from pygments import highlight, cmdline
from pygments.util import StringIO, BytesIO
-from pygments.cmdline import main as cmdline_main
import support
@@ -36,7 +35,7 @@ def run_cmdline(*args):
stdout_buffer = new_stdout = sys.stdout = StringIO()
stderr_buffer = new_stderr = sys.stderr = StringIO()
try:
- ret = cmdline_main(["pygmentize"] + list(args))
+ ret = cmdline.main(["pygmentize"] + list(args))
finally:
sys.stdout = saved_stdout
sys.stderr = saved_stderr
@@ -47,19 +46,6 @@ def run_cmdline(*args):
return (ret, out, err)
-def run_cmdline_with_closed_stdout(*args):
- saved_stdout, saved_stderr = sys.stdout, sys.stderr
- sys.stdout, sys.stderr = StringIO(), StringIO()
- sys.stdout.buffer = sys.stdout
- sys.stdout.close()
- try:
- ret = cmdline_main(['pygmentize'] + list(args))
- err = sys.stderr.getvalue()
- finally:
- sys.stdout, sys.stderr = saved_stdout, saved_stderr
- return ret, err
-
-
class CmdLineTest(unittest.TestCase):
def test_L_opt(self):
@@ -171,7 +157,9 @@ class CmdLineTest(unittest.TestCase):
def test_exception(self):
# unexpected exception while highlighting
- # (we can force that by closing stdout)
- c, e = run_cmdline_with_closed_stdout('-lpython', TESTFILE)
- self.assertEqual(c, 1)
+ cmdline.highlight = None # override callable
+ try:
+ e = self.check_failure('-lpython', TESTFILE)
+ finally:
+ cmdline.highlight = highlight
self.assertTrue('*** Error while highlighting:' in e)