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): |
@@ -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 |
|
|
|
568 | assert out == ref | |
|
571 | 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,13 +580,13 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 |
|
|
|
589 | assert sp.push_accepts_more() is True # 3 | |
|
592 | 590 | |
|
593 | 591 | def test_no_strip_coding(self): |
|
594 | 592 | src = '\n'.join([ |
@@ -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