Show More
@@ -108,8 +108,33 b' class IndentationErrorTest(unittest.TestCase):' | |||
|
108 | 108 | with tt.AssertPrints("zoon()", suppress=False): |
|
109 | 109 | ip.magic('run %s' % fname) |
|
110 | 110 | |
|
111 | se_file_1 = """1 | |
|
112 | 2 | |
|
113 | 7/ | |
|
114 | """ | |
|
115 | ||
|
116 | se_file_2 = """7/ | |
|
117 | """ | |
|
118 | ||
|
111 | 119 | class SyntaxErrorTest(unittest.TestCase): |
|
112 | 120 | def test_syntaxerror_without_lineno(self): |
|
113 | 121 | with tt.AssertNotPrints("TypeError"): |
|
114 | 122 | with tt.AssertPrints("line unknown"): |
|
115 | 123 | ip.run_cell("raise SyntaxError()") |
|
124 | ||
|
125 | def test_changing_py_file(self): | |
|
126 | with TemporaryDirectory() as td: | |
|
127 | fname = os.path.join(td, "foo.py") | |
|
128 | with open(fname, 'w') as f: | |
|
129 | f.write(se_file_1) | |
|
130 | ||
|
131 | with tt.AssertPrints(["7/", "SyntaxError"]): | |
|
132 | ip.magic("run " + fname) | |
|
133 | ||
|
134 | # Modify the file | |
|
135 | with open(fname, 'w') as f: | |
|
136 | f.write(se_file_2) | |
|
137 | ||
|
138 | # The SyntaxError should point to the correct line | |
|
139 | with tt.AssertPrints(["7/", "SyntaxError"]): | |
|
140 | ip.magic("run " + fname) |
@@ -346,6 +346,8 b' class AssertPrints(object):' | |||
|
346 | 346 | """ |
|
347 | 347 | def __init__(self, s, channel='stdout', suppress=True): |
|
348 | 348 | self.s = s |
|
349 | if isinstance(self.s, str): | |
|
350 | self.s = [self.s] | |
|
349 | 351 | self.channel = channel |
|
350 | 352 | self.suppress = suppress |
|
351 | 353 | |
@@ -359,7 +361,8 b' class AssertPrints(object):' | |||
|
359 | 361 | self.tee.flush() |
|
360 | 362 | setattr(sys, self.channel, self.orig_stream) |
|
361 | 363 | printed = self.buffer.getvalue() |
|
362 | assert self.s in printed, notprinted_msg.format(self.s, self.channel, printed) | |
|
364 | for s in self.s: | |
|
365 | assert s in printed, notprinted_msg.format(s, self.channel, printed) | |
|
363 | 366 | return False |
|
364 | 367 | |
|
365 | 368 | printed_msg = """Found {0!r} in printed output (on {1}): |
@@ -376,7 +379,8 b' class AssertNotPrints(AssertPrints):' | |||
|
376 | 379 | self.tee.flush() |
|
377 | 380 | setattr(sys, self.channel, self.orig_stream) |
|
378 | 381 | printed = self.buffer.getvalue() |
|
379 | assert self.s not in printed, printed_msg.format(self.s, self.channel, printed) | |
|
382 | for s in self.s: | |
|
383 | assert s not in printed, printed_msg.format(s, self.channel, printed) | |
|
380 | 384 | return False |
|
381 | 385 | |
|
382 | 386 | @contextmanager |
General Comments 0
You need to be logged in to leave comments.
Login now