Show More
@@ -88,3 +88,49 b' class TestAssertPrints(unittest.TestCase):' | |||||
88 | print b"ghi" |
|
88 | print b"ghi" | |
89 |
|
89 | |||
90 | self.assertRaises(AssertionError, func) |
|
90 | self.assertRaises(AssertionError, func) | |
|
91 | ||||
|
92 | ||||
|
93 | class Test_ipexec_validate(unittest.TestCase, tt.TempFileMixin): | |||
|
94 | def test_main_path(self): | |||
|
95 | """Test with only stdout results. | |||
|
96 | """ | |||
|
97 | self.mktmp("print('A')\n" | |||
|
98 | "print('B')\n" | |||
|
99 | ) | |||
|
100 | out = "A\nB" | |||
|
101 | tt.ipexec_validate(self.fname, out) | |||
|
102 | ||||
|
103 | def test_main_path2(self): | |||
|
104 | """Test with only stdout results, expecting windows line endings. | |||
|
105 | """ | |||
|
106 | self.mktmp("print('A')\n" | |||
|
107 | "print('B')\n" | |||
|
108 | ) | |||
|
109 | out = "A\r\nB" | |||
|
110 | tt.ipexec_validate(self.fname, out) | |||
|
111 | ||||
|
112 | def test_exception_path(self): | |||
|
113 | """Test exception path in exception_validate. | |||
|
114 | """ | |||
|
115 | self.mktmp("from __future__ import print_function\n" | |||
|
116 | "import sys\n" | |||
|
117 | "print('A')\n" | |||
|
118 | "print('B')\n" | |||
|
119 | "print('C', file=sys.stderr)\n" | |||
|
120 | "print('D', file=sys.stderr)\n" | |||
|
121 | ) | |||
|
122 | out = "A\nB" | |||
|
123 | tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\nD") | |||
|
124 | ||||
|
125 | def test_exception_path(self): | |||
|
126 | """Test exception path in exception_validate, expecting windows line endings. | |||
|
127 | """ | |||
|
128 | self.mktmp("from __future__ import print_function\n" | |||
|
129 | "import sys\n" | |||
|
130 | "print('A')\n" | |||
|
131 | "print('B')\n" | |||
|
132 | "print('C', file=sys.stderr)\n" | |||
|
133 | "print('D', file=sys.stderr)\n" | |||
|
134 | ) | |||
|
135 | out = "A\r\nB" | |||
|
136 | tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\r\nD") |
@@ -235,12 +235,12 b" def ipexec_validate(fname, expected_out, expected_err=''," | |||||
235 | # more informative than simply having an empty stdout. |
|
235 | # more informative than simply having an empty stdout. | |
236 | if err: |
|
236 | if err: | |
237 | if expected_err: |
|
237 | if expected_err: | |
238 | nt.assert_equal(err.strip(), expected_err.strip()) |
|
238 | nt.assert_equal("\n".join(err.strip().splitlines()), "\n".join(expected_err.strip().splitlines())) | |
239 | else: |
|
239 | else: | |
240 | raise ValueError('Running file %r produced error: %r' % |
|
240 | raise ValueError('Running file %r produced error: %r' % | |
241 | (fname, err)) |
|
241 | (fname, err)) | |
242 | # If no errors or output on stderr was expected, match stdout |
|
242 | # If no errors or output on stderr was expected, match stdout | |
243 | nt.assert_equal(out.strip(), expected_out.strip()) |
|
243 | nt.assert_equal("\n".join(out.strip().splitlines()), "\n".join(expected_out.strip().splitlines())) | |
244 |
|
244 | |||
245 |
|
245 | |||
246 | class TempFileMixin(object): |
|
246 | class TempFileMixin(object): |
General Comments 0
You need to be logged in to leave comments.
Login now