Show More
@@ -8,8 +8,6 b'' | |||
|
8 | 8 | import unittest |
|
9 | 9 | import sys |
|
10 | 10 | |
|
11 | import nose.tools as nt | |
|
12 | ||
|
13 | 11 | from IPython.core import inputsplitter as isp |
|
14 | 12 | from IPython.core.inputtransformer import InputTransformer |
|
15 | 13 | from IPython.core.tests.test_inputtransformer import syntax, syntax_ml |
@@ -98,10 +96,10 b' def test_remove_comments():' | |||
|
98 | 96 | |
|
99 | 97 | def test_get_input_encoding(): |
|
100 | 98 | encoding = isp.get_input_encoding() |
|
101 |
|
|
|
99 | assert isinstance(encoding, str) | |
|
102 | 100 | # simple-minded check that at least encoding a simple string works with the |
|
103 | 101 | # encoding we got. |
|
104 |
|
|
|
102 | assert "test".encode(encoding) == b"test" | |
|
105 | 103 | |
|
106 | 104 | |
|
107 | 105 | class NoInputEncodingTestCase(unittest.TestCase): |
@@ -419,7 +417,7 b' class IPythonInputTestCase(InputSplitterTestCase):' | |||
|
419 | 417 | for lraw, out_t_part in line_pairs: |
|
420 | 418 | if out_t_part is not None: |
|
421 | 419 | out_t_parts.append(out_t_part) |
|
422 | ||
|
420 | ||
|
423 | 421 | if lraw is not None: |
|
424 | 422 | isp.push(lraw) |
|
425 | 423 | raw_parts.append(lraw) |
@@ -442,7 +440,7 b' class IPythonInputTestCase(InputSplitterTestCase):' | |||
|
442 | 440 | out = isp.transform_cell(raw) |
|
443 | 441 | # Match ignoring trailing whitespace |
|
444 | 442 | self.assertEqual(out.rstrip(), out_t.rstrip()) |
|
445 | ||
|
443 | ||
|
446 | 444 | def test_cellmagic_preempt(self): |
|
447 | 445 | isp = self.isp |
|
448 | 446 | for raw, name, line, cell in [ |
@@ -464,17 +462,17 b' class IPythonInputTestCase(InputSplitterTestCase):' | |||
|
464 | 462 | class CommentTransformer(InputTransformer): |
|
465 | 463 | def __init__(self): |
|
466 | 464 | self._lines = [] |
|
467 | ||
|
465 | ||
|
468 | 466 | def push(self, line): |
|
469 | 467 | self._lines.append(line + '#') |
|
470 | ||
|
468 | ||
|
471 | 469 | def reset(self): |
|
472 | 470 | text = '\n'.join(self._lines) |
|
473 | 471 | self._lines = [] |
|
474 | 472 | return text |
|
475 | ||
|
473 | ||
|
476 | 474 | isp.physical_line_transforms.insert(0, CommentTransformer()) |
|
477 | ||
|
475 | ||
|
478 | 476 | for raw, expected in [ |
|
479 | 477 | ("a=5", "a=5#"), |
|
480 | 478 | ("%ls foo", "get_ipython().run_line_magic(%r, %r)" % (u'ls', u'foo#')), |
@@ -527,38 +525,38 b" if __name__ == '__main__':" | |||
|
527 | 525 | # Tests for cell magics support |
|
528 | 526 | |
|
529 | 527 | def test_last_blank(): |
|
530 |
|
|
|
531 |
|
|
|
532 |
|
|
|
533 |
|
|
|
528 | assert isp.last_blank("") is False | |
|
529 | assert isp.last_blank("abc") is False | |
|
530 | assert isp.last_blank("abc\n") is False | |
|
531 | assert isp.last_blank("abc\na") is False | |
|
534 | 532 | |
|
535 |
|
|
|
536 |
|
|
|
537 |
|
|
|
538 |
|
|
|
539 |
|
|
|
540 |
|
|
|
541 |
|
|
|
533 | assert isp.last_blank("\n") is True | |
|
534 | assert isp.last_blank("\n ") is True | |
|
535 | assert isp.last_blank("abc\n ") is True | |
|
536 | assert isp.last_blank("abc\n\n") is True | |
|
537 | assert isp.last_blank("abc\nd\n\n") is True | |
|
538 | assert isp.last_blank("abc\nd\ne\n\n") is True | |
|
539 | assert isp.last_blank("abc \n \n \n\n") is True | |
|
542 | 540 | |
|
543 | 541 | |
|
544 | 542 | def test_last_two_blanks(): |
|
545 |
|
|
|
546 |
|
|
|
547 |
|
|
|
548 |
|
|
|
549 |
|
|
|
550 |
|
|
|
551 | ||
|
552 |
|
|
|
553 |
|
|
|
554 |
|
|
|
555 |
|
|
|
556 |
|
|
|
557 |
|
|
|
558 |
|
|
|
559 |
|
|
|
560 |
|
|
|
561 |
|
|
|
543 | assert isp.last_two_blanks("") is False | |
|
544 | assert isp.last_two_blanks("abc") is False | |
|
545 | assert isp.last_two_blanks("abc\n") is False | |
|
546 | assert isp.last_two_blanks("abc\n\na") is False | |
|
547 | assert isp.last_two_blanks("abc\n \n") is False | |
|
548 | assert isp.last_two_blanks("abc\n\n") is False | |
|
549 | ||
|
550 | assert isp.last_two_blanks("\n\n") is True | |
|
551 | assert isp.last_two_blanks("\n\n ") is True | |
|
552 | assert isp.last_two_blanks("\n \n") is True | |
|
553 | assert isp.last_two_blanks("abc\n\n ") is True | |
|
554 | assert isp.last_two_blanks("abc\n\n\n") is True | |
|
555 | assert isp.last_two_blanks("abc\n\n \n") is True | |
|
556 | assert isp.last_two_blanks("abc\n\n \n ") is True | |
|
557 | assert isp.last_two_blanks("abc\n\n \n \n") is True | |
|
558 | assert isp.last_two_blanks("abc\nd\n\n\n") is True | |
|
559 | assert isp.last_two_blanks("abc\nd\ne\nf\n\n\n") is True | |
|
562 | 560 | |
|
563 | 561 | |
|
564 | 562 | class CellMagicsCommon(object): |
@@ -567,11 +565,11 b' class CellMagicsCommon(object):' | |||
|
567 | 565 | src = "%%cellm line\nbody\n" |
|
568 | 566 | out = self.sp.transform_cell(src) |
|
569 | 567 | ref = "get_ipython().run_cell_magic('cellm', 'line', 'body')\n" |
|
570 |
|
|
|
571 | ||
|
568 | assert out == ref | |
|
569 | ||
|
572 | 570 | def test_cellmagic_help(self): |
|
573 | 571 | self.sp.push('%%cellm?') |
|
574 |
|
|
|
572 | assert self.sp.push_accepts_more() is False | |
|
575 | 573 | |
|
576 | 574 | def tearDown(self): |
|
577 | 575 | self.sp.reset() |
@@ -582,14 +580,14 b' class CellModeCellMagics(CellMagicsCommon, unittest.TestCase):' | |||
|
582 | 580 | |
|
583 | 581 | def test_incremental(self): |
|
584 | 582 | sp = self.sp |
|
585 |
sp.push( |
|
|
586 |
|
|
|
587 |
sp.push( |
|
|
588 |
|
|
|
589 |
sp.push( |
|
|
583 | sp.push("%%cellm firstline\n") | |
|
584 | assert sp.push_accepts_more() is True # 1 | |
|
585 | sp.push("line2\n") | |
|
586 | assert sp.push_accepts_more() is True # 2 | |
|
587 | sp.push("\n") | |
|
590 | 588 | # This should accept a blank line and carry on until the cell is reset |
|
591 |
|
|
|
592 | ||
|
589 | assert sp.push_accepts_more() is True # 3 | |
|
590 | ||
|
593 | 591 | def test_no_strip_coding(self): |
|
594 | 592 | src = '\n'.join([ |
|
595 | 593 | '%%writefile foo.py', |
@@ -597,7 +595,7 b' class CellModeCellMagics(CellMagicsCommon, unittest.TestCase):' | |||
|
597 | 595 | 'print(u"üñîçø∂é")', |
|
598 | 596 | ]) |
|
599 | 597 | out = self.sp.transform_cell(src) |
|
600 |
|
|
|
598 | assert "# coding: utf-8" in out | |
|
601 | 599 | |
|
602 | 600 | |
|
603 | 601 | class LineModeCellMagics(CellMagicsCommon, unittest.TestCase): |
@@ -605,11 +603,12 b' class LineModeCellMagics(CellMagicsCommon, unittest.TestCase):' | |||
|
605 | 603 | |
|
606 | 604 | def test_incremental(self): |
|
607 | 605 | sp = self.sp |
|
608 |
sp.push( |
|
|
609 |
|
|
|
610 |
sp.push( |
|
|
606 | sp.push("%%cellm line2\n") | |
|
607 | assert sp.push_accepts_more() is True # 1 | |
|
608 | sp.push("\n") | |
|
611 | 609 | # In this case, a blank line should end the cell magic |
|
612 |
|
|
|
610 | assert sp.push_accepts_more() is False # 2 | |
|
611 | ||
|
613 | 612 | |
|
614 | 613 | indentation_samples = [ |
|
615 | 614 | ('a = 1', 0), |
General Comments 0
You need to be logged in to leave comments.
Login now