Show More
@@ -380,7 +380,8 b' class InteractiveShellTestCase(unittest.TestCase):' | |||||
380 | class A(object): |
|
380 | class A(object): | |
381 | @property |
|
381 | @property | |
382 | def foo(self): |
|
382 | def foo(self): | |
383 | raise NotImplementedError() |
|
383 | raise NotImplementedError() # pragma: no cover | |
|
384 | ||||
384 | a = A() |
|
385 | a = A() | |
385 |
|
386 | |||
386 | found = ip._ofind('a.foo', [('locals', locals())]) |
|
387 | found = ip._ofind('a.foo', [('locals', locals())]) | |
@@ -392,7 +393,7 b' class InteractiveShellTestCase(unittest.TestCase):' | |||||
392 | class A(object): |
|
393 | class A(object): | |
393 | @property |
|
394 | @property | |
394 | def foo(self): |
|
395 | def foo(self): | |
395 | raise NotImplementedError() |
|
396 | raise NotImplementedError() # pragma: no cover | |
396 |
|
397 | |||
397 | a = A() |
|
398 | a = A() | |
398 | a.a = A() |
|
399 | a.a = A() | |
@@ -585,9 +586,9 b' class ExitCodeChecks(tt.TempFileMixin):' | |||||
585 | self.assertEqual(ip.user_ns['_exit_code'], -signal.SIGALRM) |
|
586 | self.assertEqual(ip.user_ns['_exit_code'], -signal.SIGALRM) | |
586 |
|
587 | |||
587 | @onlyif_cmds_exist("csh") |
|
588 | @onlyif_cmds_exist("csh") | |
588 | def test_exit_code_signal_csh(self): |
|
589 | def test_exit_code_signal_csh(self): # pragma: no cover | |
589 |
SHELL = os.environ.get( |
|
590 | SHELL = os.environ.get("SHELL", None) | |
590 |
os.environ[ |
|
591 | os.environ["SHELL"] = find_cmd("csh") | |
591 | try: |
|
592 | try: | |
592 | self.test_exit_code_signal() |
|
593 | self.test_exit_code_signal() | |
593 | finally: |
|
594 | finally: | |
@@ -615,7 +616,7 b' class TestSystemRaw(ExitCodeChecks):' | |||||
615 | def test_control_c(self, *mocks): |
|
616 | def test_control_c(self, *mocks): | |
616 | try: |
|
617 | try: | |
617 | self.system("sleep 1 # wont happen") |
|
618 | self.system("sleep 1 # wont happen") | |
618 | except KeyboardInterrupt: |
|
619 | except KeyboardInterrupt: # pragma: no cove | |
619 | self.fail( |
|
620 | self.fail( | |
620 | "system call should intercept " |
|
621 | "system call should intercept " | |
621 | "keyboard interrupt from subprocess.call" |
|
622 | "keyboard interrupt from subprocess.call" | |
@@ -679,16 +680,20 b' class TestAstTransform(unittest.TestCase):' | |||||
679 |
|
680 | |||
680 | def tearDown(self): |
|
681 | def tearDown(self): | |
681 | ip.ast_transformers.remove(self.negator) |
|
682 | ip.ast_transformers.remove(self.negator) | |
682 |
|
683 | |||
|
684 | def test_non_int_const(self): | |||
|
685 | with tt.AssertPrints("hello"): | |||
|
686 | ip.run_cell('print("hello")') | |||
|
687 | ||||
683 | def test_run_cell(self): |
|
688 | def test_run_cell(self): | |
684 |
with tt.AssertPrints( |
|
689 | with tt.AssertPrints("-34"): | |
685 |
ip.run_cell( |
|
690 | ip.run_cell("print(12 + 22)") | |
686 |
|
691 | |||
687 | # A named reference to a number shouldn't be transformed. |
|
692 | # A named reference to a number shouldn't be transformed. | |
688 |
ip.user_ns[ |
|
693 | ip.user_ns["n"] = 55 | |
689 |
with tt.AssertNotPrints( |
|
694 | with tt.AssertNotPrints("-55"): | |
690 |
ip.run_cell( |
|
695 | ip.run_cell("print(n)") | |
691 |
|
696 | |||
692 | def test_timeit(self): |
|
697 | def test_timeit(self): | |
693 | called = set() |
|
698 | called = set() | |
694 | def f(x): |
|
699 | def f(x): | |
@@ -796,7 +801,11 b' class TestAstTransform2(unittest.TestCase):' | |||||
796 | # This shouldn't throw an error |
|
801 | # This shouldn't throw an error | |
797 | ip.run_cell("o = 2.0") |
|
802 | ip.run_cell("o = 2.0") | |
798 | self.assertEqual(ip.user_ns['o'], 2.0) |
|
803 | self.assertEqual(ip.user_ns['o'], 2.0) | |
799 |
|
804 | |||
|
805 | def test_run_cell_non_int(self): | |||
|
806 | ip.run_cell("n = 'a'") | |||
|
807 | assert self.calls == [] | |||
|
808 | ||||
800 | def test_timeit(self): |
|
809 | def test_timeit(self): | |
801 | called = set() |
|
810 | called = set() | |
802 | def f(x): |
|
811 | def f(x): | |
@@ -815,14 +824,9 b' class TestAstTransform2(unittest.TestCase):' | |||||
815 | class ErrorTransformer(ast.NodeTransformer): |
|
824 | class ErrorTransformer(ast.NodeTransformer): | |
816 | """Throws an error when it sees a number.""" |
|
825 | """Throws an error when it sees a number.""" | |
817 |
|
826 | |||
818 | # for Python 3.7 and earlier |
|
|||
819 | def visit_Num(self, node): |
|
|||
820 | raise ValueError("test") |
|
|||
821 |
|
||||
822 | # for Python 3.8+ |
|
|||
823 | def visit_Constant(self, node): |
|
827 | def visit_Constant(self, node): | |
824 | if isinstance(node.value, int): |
|
828 | if isinstance(node.value, int): | |
825 | return self.visit_Num(node) |
|
829 | raise ValueError("test") | |
826 | return node |
|
830 | return node | |
827 |
|
831 | |||
828 |
|
832 | |||
@@ -845,10 +849,6 b' class StringRejector(ast.NodeTransformer):' | |||||
845 | not be executed by throwing an InputRejected. |
|
849 | not be executed by throwing an InputRejected. | |
846 | """ |
|
850 | """ | |
847 |
|
851 | |||
848 | #for python 3.7 and earlier |
|
|||
849 | def visit_Str(self, node): |
|
|||
850 | raise InputRejected("test") |
|
|||
851 |
|
||||
852 | # 3.8 only |
|
852 | # 3.8 only | |
853 | def visit_Constant(self, node): |
|
853 | def visit_Constant(self, node): | |
854 | if isinstance(node.value, str): |
|
854 | if isinstance(node.value, str): |
General Comments 0
You need to be logged in to leave comments.
Login now