Also test self.paste echoing, by temporarily faking the writer
(self)
| 180 | self.assertEqual(ip.user_ns["zz"], 3.5) |
| 181 | |
| 182 | def test_paste_echo(self): |
| 183 | "Also test self.paste echoing, by temporarily faking the writer" |
| 184 | w = StringIO() |
| 185 | old_write = sys.stdout.write |
| 186 | sys.stdout.write = w.write |
| 187 | code = """ |
| 188 | a = 100 |
| 189 | b = 200""" |
| 190 | try: |
| 191 | self.paste(code, "") |
| 192 | out = w.getvalue() |
| 193 | finally: |
| 194 | sys.stdout.write = old_write |
| 195 | self.assertEqual(ip.user_ns["a"], 100) |
| 196 | self.assertEqual(ip.user_ns["b"], 200) |
| 197 | assert out == code + "\n## -- End pasted text --\n" |
| 198 | |
| 199 | def test_paste_leading_commas(self): |
| 200 | "Test multiline strings with leading commas" |