##// END OF EJS Templates
[core][tests][inputsplitter] Remove nose
Samuel Gaist -
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 nt.assert_true(isinstance(encoding, str))
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 nt.assert_equal(u'test'.encode(encoding), b'test')
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 nt.assert_false(isp.last_blank(''))
531 nt.assert_false(isp.last_blank('abc'))
532 nt.assert_false(isp.last_blank('abc\n'))
533 nt.assert_false(isp.last_blank('abc\na'))
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 nt.assert_true(isp.last_blank('\n'))
536 nt.assert_true(isp.last_blank('\n '))
537 nt.assert_true(isp.last_blank('abc\n '))
538 nt.assert_true(isp.last_blank('abc\n\n'))
539 nt.assert_true(isp.last_blank('abc\nd\n\n'))
540 nt.assert_true(isp.last_blank('abc\nd\ne\n\n'))
541 nt.assert_true(isp.last_blank('abc \n \n \n\n'))
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 nt.assert_false(isp.last_two_blanks(''))
546 nt.assert_false(isp.last_two_blanks('abc'))
547 nt.assert_false(isp.last_two_blanks('abc\n'))
548 nt.assert_false(isp.last_two_blanks('abc\n\na'))
549 nt.assert_false(isp.last_two_blanks('abc\n \n'))
550 nt.assert_false(isp.last_two_blanks('abc\n\n'))
551
552 nt.assert_true(isp.last_two_blanks('\n\n'))
553 nt.assert_true(isp.last_two_blanks('\n\n '))
554 nt.assert_true(isp.last_two_blanks('\n \n'))
555 nt.assert_true(isp.last_two_blanks('abc\n\n '))
556 nt.assert_true(isp.last_two_blanks('abc\n\n\n'))
557 nt.assert_true(isp.last_two_blanks('abc\n\n \n'))
558 nt.assert_true(isp.last_two_blanks('abc\n\n \n '))
559 nt.assert_true(isp.last_two_blanks('abc\n\n \n \n'))
560 nt.assert_true(isp.last_two_blanks('abc\nd\n\n\n'))
561 nt.assert_true(isp.last_two_blanks('abc\nd\ne\nf\n\n\n'))
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 nt.assert_equal(out, ref)
571
568 assert out == ref
569
572 570 def test_cellmagic_help(self):
573 571 self.sp.push('%%cellm?')
574 nt.assert_false(self.sp.push_accepts_more())
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('%%cellm firstline\n')
586 nt.assert_true(sp.push_accepts_more()) #1
587 sp.push('line2\n')
588 nt.assert_true(sp.push_accepts_more()) #2
589 sp.push('\n')
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 nt.assert_true(sp.push_accepts_more()) #3
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 nt.assert_in('# coding: utf-8', out)
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('%%cellm line2\n')
609 nt.assert_true(sp.push_accepts_more()) #1
610 sp.push('\n')
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 nt.assert_false(sp.push_accepts_more()) #2
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