Validate that the given input lines produce the resulting namespace. Note: the input lines are given exactly as they would be typed in an auto-indenting environment, as mini_interactive_loop above already does auto-indenting and prepends spaces to the input.
(self, lines, ns)
| 351 | """Tests for an interactive loop like a python shell. |
| 352 | """ |
| 353 | def check_ns(self, lines, ns): |
| 354 | """Validate that the given input lines produce the resulting namespace. |
| 355 | |
| 356 | Note: the input lines are given exactly as they would be typed in an |
| 357 | auto-indenting environment, as mini_interactive_loop above already does |
| 358 | auto-indenting and prepends spaces to the input. |
| 359 | """ |
| 360 | src = mini_interactive_loop(pseudo_input(lines)) |
| 361 | test_ns = {} |
| 362 | exec(src, test_ns) |
| 363 | # We can't check that the provided ns is identical to the test_ns, |
| 364 | # because Python fills test_ns with extra keys (copyright, etc). But |
| 365 | # we can check that the given dict is *contained* in test_ns |
| 366 | for k,v in ns.items(): |
| 367 | self.assertEqual(test_ns[k], v) |
| 368 | |
| 369 | def test_simple(self): |
| 370 | self.check_ns(['x=1'], dict(x=1)) |
no test coverage detected