Show More
@@ -8,8 +8,6 b'' | |||||
8 | import unittest |
|
8 | import unittest | |
9 | import sys |
|
9 | import sys | |
10 |
|
10 | |||
11 | import nose.tools as nt |
|
|||
12 |
|
||||
13 | from IPython.core import inputsplitter as isp |
|
11 | from IPython.core import inputsplitter as isp | |
14 | from IPython.core.inputtransformer import InputTransformer |
|
12 | from IPython.core.inputtransformer import InputTransformer | |
15 | from IPython.core.tests.test_inputtransformer import syntax, syntax_ml |
|
13 | from IPython.core.tests.test_inputtransformer import syntax, syntax_ml | |
@@ -98,10 +96,10 b' def test_remove_comments():' | |||||
98 |
|
96 | |||
99 | def test_get_input_encoding(): |
|
97 | def test_get_input_encoding(): | |
100 | encoding = isp.get_input_encoding() |
|
98 | encoding = isp.get_input_encoding() | |
101 |
|
|
99 | assert isinstance(encoding, str) | |
102 | # simple-minded check that at least encoding a simple string works with the |
|
100 | # simple-minded check that at least encoding a simple string works with the | |
103 | # encoding we got. |
|
101 | # encoding we got. | |
104 |
|
|
102 | assert "test".encode(encoding) == b"test" | |
105 |
|
103 | |||
106 |
|
104 | |||
107 | class NoInputEncodingTestCase(unittest.TestCase): |
|
105 | class NoInputEncodingTestCase(unittest.TestCase): | |
@@ -527,38 +525,38 b" if __name__ == '__main__':" | |||||
527 | # Tests for cell magics support |
|
525 | # Tests for cell magics support | |
528 |
|
526 | |||
529 | def test_last_blank(): |
|
527 | def test_last_blank(): | |
530 |
|
|
528 | assert isp.last_blank("") is False | |
531 |
|
|
529 | assert isp.last_blank("abc") is False | |
532 |
|
|
530 | assert isp.last_blank("abc\n") is False | |
533 |
|
|
531 | assert isp.last_blank("abc\na") is False | |
534 |
|
532 | |||
535 |
|
|
533 | assert isp.last_blank("\n") is True | |
536 |
|
|
534 | assert isp.last_blank("\n ") is True | |
537 |
|
|
535 | assert isp.last_blank("abc\n ") is True | |
538 |
|
|
536 | assert isp.last_blank("abc\n\n") is True | |
539 |
|
|
537 | assert isp.last_blank("abc\nd\n\n") is True | |
540 |
|
|
538 | assert isp.last_blank("abc\nd\ne\n\n") is True | |
541 |
|
|
539 | assert isp.last_blank("abc \n \n \n\n") is True | |
542 |
|
540 | |||
543 |
|
541 | |||
544 | def test_last_two_blanks(): |
|
542 | def test_last_two_blanks(): | |
545 |
|
|
543 | assert isp.last_two_blanks("") is False | |
546 |
|
|
544 | assert isp.last_two_blanks("abc") is False | |
547 |
|
|
545 | assert isp.last_two_blanks("abc\n") is False | |
548 |
|
|
546 | assert isp.last_two_blanks("abc\n\na") is False | |
549 |
|
|
547 | assert isp.last_two_blanks("abc\n \n") is False | |
550 |
|
|
548 | assert isp.last_two_blanks("abc\n\n") is False | |
551 |
|
549 | |||
552 |
|
|
550 | assert isp.last_two_blanks("\n\n") is True | |
553 |
|
|
551 | assert isp.last_two_blanks("\n\n ") is True | |
554 |
|
|
552 | assert isp.last_two_blanks("\n \n") is True | |
555 |
|
|
553 | assert isp.last_two_blanks("abc\n\n ") is True | |
556 |
|
|
554 | assert isp.last_two_blanks("abc\n\n\n") is True | |
557 |
|
|
555 | assert isp.last_two_blanks("abc\n\n \n") is True | |
558 |
|
|
556 | assert isp.last_two_blanks("abc\n\n \n ") is True | |
559 |
|
|
557 | assert isp.last_two_blanks("abc\n\n \n \n") is True | |
560 |
|
|
558 | assert isp.last_two_blanks("abc\nd\n\n\n") is True | |
561 |
|
|
559 | assert isp.last_two_blanks("abc\nd\ne\nf\n\n\n") is True | |
562 |
|
560 | |||
563 |
|
561 | |||
564 | class CellMagicsCommon(object): |
|
562 | class CellMagicsCommon(object): | |
@@ -567,11 +565,11 b' class CellMagicsCommon(object):' | |||||
567 | src = "%%cellm line\nbody\n" |
|
565 | src = "%%cellm line\nbody\n" | |
568 | out = self.sp.transform_cell(src) |
|
566 | out = self.sp.transform_cell(src) | |
569 | ref = "get_ipython().run_cell_magic('cellm', 'line', 'body')\n" |
|
567 | ref = "get_ipython().run_cell_magic('cellm', 'line', 'body')\n" | |
570 |
|
|
568 | assert out == ref | |
571 |
|
569 | |||
572 | def test_cellmagic_help(self): |
|
570 | def test_cellmagic_help(self): | |
573 | self.sp.push('%%cellm?') |
|
571 | self.sp.push('%%cellm?') | |
574 |
|
|
572 | assert self.sp.push_accepts_more() is False | |
575 |
|
573 | |||
576 | def tearDown(self): |
|
574 | def tearDown(self): | |
577 | self.sp.reset() |
|
575 | self.sp.reset() | |
@@ -582,13 +580,13 b' class CellModeCellMagics(CellMagicsCommon, unittest.TestCase):' | |||||
582 |
|
580 | |||
583 | def test_incremental(self): |
|
581 | def test_incremental(self): | |
584 | sp = self.sp |
|
582 | sp = self.sp | |
585 |
sp.push( |
|
583 | sp.push("%%cellm firstline\n") | |
586 |
|
|
584 | assert sp.push_accepts_more() is True # 1 | |
587 |
sp.push( |
|
585 | sp.push("line2\n") | |
588 |
|
|
586 | assert sp.push_accepts_more() is True # 2 | |
589 |
sp.push( |
|
587 | sp.push("\n") | |
590 | # This should accept a blank line and carry on until the cell is reset |
|
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 | def test_no_strip_coding(self): |
|
591 | def test_no_strip_coding(self): | |
594 | src = '\n'.join([ |
|
592 | src = '\n'.join([ | |
@@ -597,7 +595,7 b' class CellModeCellMagics(CellMagicsCommon, unittest.TestCase):' | |||||
597 | 'print(u"üñîçø∂é")', |
|
595 | 'print(u"üñîçø∂é")', | |
598 | ]) |
|
596 | ]) | |
599 | out = self.sp.transform_cell(src) |
|
597 | out = self.sp.transform_cell(src) | |
600 |
|
|
598 | assert "# coding: utf-8" in out | |
601 |
|
599 | |||
602 |
|
600 | |||
603 | class LineModeCellMagics(CellMagicsCommon, unittest.TestCase): |
|
601 | class LineModeCellMagics(CellMagicsCommon, unittest.TestCase): | |
@@ -605,11 +603,12 b' class LineModeCellMagics(CellMagicsCommon, unittest.TestCase):' | |||||
605 |
|
603 | |||
606 | def test_incremental(self): |
|
604 | def test_incremental(self): | |
607 | sp = self.sp |
|
605 | sp = self.sp | |
608 |
sp.push( |
|
606 | sp.push("%%cellm line2\n") | |
609 |
|
|
607 | assert sp.push_accepts_more() is True # 1 | |
610 |
sp.push( |
|
608 | sp.push("\n") | |
611 | # In this case, a blank line should end the cell magic |
|
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 | indentation_samples = [ |
|
613 | indentation_samples = [ | |
615 | ('a = 1', 0), |
|
614 | ('a = 1', 0), |
General Comments 0
You need to be logged in to leave comments.
Login now