Skip to content

Commit

Permalink
Merge pull request ipython#2338 from jstenar/fix-2315
Browse files Browse the repository at this point in the history
Normalize line endings for ipexec_validate, fix for ipython#2315.
  • Loading branch information
takluyver committed Aug 26, 2012
2 parents d64d1a1 + 2d15d5a commit f633df0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
46 changes: 46 additions & 0 deletions IPython/testing/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,49 @@ def func():
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_main_path2(self):
"""Test with only stdout results, expecting windows line endings.
"""
self.mktmp("print('A')\n"
"print('B')\n"
)
out = "A\r\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")

def test_exception_path(self):
"""Test exception path in exception_validate, expecting windows line endings.
"""
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\r\nB"
tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\r\nD")
4 changes: 2 additions & 2 deletions IPython/testing/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ 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))
# If no errors or output on stderr was expected, match stdout
nt.assert_equal(out.strip(), expected_out.strip())
nt.assert_equal("\n".join(out.strip().splitlines()), "\n".join(expected_out.strip().splitlines()))


class TempFileMixin(object):
Expand Down

0 comments on commit f633df0

Please sign in to comment.