Show More
@@ -108,8 +108,33 b' class IndentationErrorTest(unittest.TestCase):' | |||||
108 | with tt.AssertPrints("zoon()", suppress=False): |
|
108 | with tt.AssertPrints("zoon()", suppress=False): | |
109 | ip.magic('run %s' % fname) |
|
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 | class SyntaxErrorTest(unittest.TestCase): |
|
119 | class SyntaxErrorTest(unittest.TestCase): | |
112 | def test_syntaxerror_without_lineno(self): |
|
120 | def test_syntaxerror_without_lineno(self): | |
113 | with tt.AssertNotPrints("TypeError"): |
|
121 | with tt.AssertNotPrints("TypeError"): | |
114 | with tt.AssertPrints("line unknown"): |
|
122 | with tt.AssertPrints("line unknown"): | |
115 | ip.run_cell("raise SyntaxError()") |
|
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 | def __init__(self, s, channel='stdout', suppress=True): |
|
347 | def __init__(self, s, channel='stdout', suppress=True): | |
348 | self.s = s |
|
348 | self.s = s | |
|
349 | if isinstance(self.s, str): | |||
|
350 | self.s = [self.s] | |||
349 | self.channel = channel |
|
351 | self.channel = channel | |
350 | self.suppress = suppress |
|
352 | self.suppress = suppress | |
351 |
|
353 | |||
@@ -359,7 +361,8 b' class AssertPrints(object):' | |||||
359 | self.tee.flush() |
|
361 | self.tee.flush() | |
360 | setattr(sys, self.channel, self.orig_stream) |
|
362 | setattr(sys, self.channel, self.orig_stream) | |
361 | printed = self.buffer.getvalue() |
|
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 | return False |
|
366 | return False | |
364 |
|
367 | |||
365 | printed_msg = """Found {0!r} in printed output (on {1}): |
|
368 | printed_msg = """Found {0!r} in printed output (on {1}): | |
@@ -376,7 +379,8 b' class AssertNotPrints(AssertPrints):' | |||||
376 | self.tee.flush() |
|
379 | self.tee.flush() | |
377 | setattr(sys, self.channel, self.orig_stream) |
|
380 | setattr(sys, self.channel, self.orig_stream) | |
378 | printed = self.buffer.getvalue() |
|
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 | return False |
|
384 | return False | |
381 |
|
385 | |||
382 | @contextmanager |
|
386 | @contextmanager |
General Comments 0
You need to be logged in to leave comments.
Login now