diff --git a/IPython/testing/tests/test_tools.py b/IPython/testing/tests/test_tools.py index 5226c8c..3c79ec9 100644 --- a/IPython/testing/tests/test_tools.py +++ b/IPython/testing/tests/test_tools.py @@ -88,3 +88,27 @@ class TestAssertPrints(unittest.TestCase): print b"ghi" self.assertRaises(AssertionError, func) + + +class Test_ipexec_validate(unittest.TestCase, tt.TempFileMixin): + def test_main_path(self): + """Test with only stdout results. + """ + self.mktmp("print('A')\n" + "print('B')\n" + ) + out = "A\nB" + tt.ipexec_validate(self.fname, out) + + def test_exception_path(self): + """Test exception path in exception_validate. + """ + self.mktmp("from __future__ import print_function\n" + "import sys\n" + "print('A')\n" + "print('B')\n" + "print('C', file=sys.stderr)\n" + "print('D', file=sys.stderr)\n" + ) + out = "A\nB" + tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\nD") diff --git a/IPython/testing/tools.py b/IPython/testing/tools.py index d1c7c43..2b47f55 100644 --- a/IPython/testing/tools.py +++ b/IPython/testing/tools.py @@ -235,7 +235,7 @@ def ipexec_validate(fname, expected_out, expected_err='', # more informative than simply having an empty stdout. if err: if expected_err: - nt.assert_equal(err.strip(), expected_err.strip()) + nt.assert_equal("\n".join(err.strip().splitlines()), "\n".join(expected_err.strip().splitlines())) else: raise ValueError('Running file %r produced error: %r' % (fname, err))