Show More
@@ -610,15 +610,16 b' class TestModules(tt.TempFileMixin, unittest.TestCase):' | |||||
610 | class Negator(ast.NodeTransformer): |
|
610 | class Negator(ast.NodeTransformer): | |
611 | """Negates all number literals in an AST.""" |
|
611 | """Negates all number literals in an AST.""" | |
612 |
|
612 | |||
|
613 | # for python 3.7 and earlier | |||
613 | def visit_Num(self, node): |
|
614 | def visit_Num(self, node): | |
614 | node.n = -node.n |
|
615 | node.n = -node.n | |
615 | return node |
|
616 | return node | |
616 |
|
617 | |||
617 | if sys.version_info > (3,8): |
|
618 | # for python 3.8+ | |
618 |
|
|
619 | def visit_Constant(self, node): | |
619 |
|
|
620 | if isinstance(node.value, int): | |
620 |
|
|
621 | return self.visit_Num(node) | |
621 |
|
|
622 | return node | |
622 |
|
623 | |||
623 | class TestAstTransform(unittest.TestCase): |
|
624 | class TestAstTransform(unittest.TestCase): | |
624 | def setUp(self): |
|
625 | def setUp(self): | |
@@ -681,17 +682,21 b' class TestAstTransform(unittest.TestCase):' | |||||
681 |
|
682 | |||
682 | class IntegerWrapper(ast.NodeTransformer): |
|
683 | class IntegerWrapper(ast.NodeTransformer): | |
683 | """Wraps all integers in a call to Integer()""" |
|
684 | """Wraps all integers in a call to Integer()""" | |
|
685 | ||||
|
686 | # for Python 3.7 and earlier | |||
|
687 | ||||
|
688 | # for Python 3.7 and earlier | |||
684 | def visit_Num(self, node): |
|
689 | def visit_Num(self, node): | |
685 | if isinstance(node.n, int): |
|
690 | if isinstance(node.n, int): | |
686 | return ast.Call(func=ast.Name(id='Integer', ctx=ast.Load()), |
|
691 | return ast.Call(func=ast.Name(id='Integer', ctx=ast.Load()), | |
687 | args=[node], keywords=[]) |
|
692 | args=[node], keywords=[]) | |
688 | return node |
|
693 | return node | |
689 |
|
694 | |||
690 | if sys.version_info > (3,8): |
|
695 | # For Python 3.8+ | |
691 |
|
|
696 | def visit_Constant(self, node): | |
692 |
|
|
697 | if isinstance(node.value, int): | |
693 |
|
|
698 | return self.visit_Num(node) | |
694 |
|
|
699 | return node | |
695 |
|
700 | |||
696 |
|
701 | |||
697 | class TestAstTransform2(unittest.TestCase): |
|
702 | class TestAstTransform2(unittest.TestCase): | |
@@ -734,14 +739,16 b' class TestAstTransform2(unittest.TestCase):' | |||||
734 |
|
739 | |||
735 | class ErrorTransformer(ast.NodeTransformer): |
|
740 | class ErrorTransformer(ast.NodeTransformer): | |
736 | """Throws an error when it sees a number.""" |
|
741 | """Throws an error when it sees a number.""" | |
|
742 | ||||
|
743 | # for Python 3.7 and earlier | |||
737 | def visit_Num(self, node): |
|
744 | def visit_Num(self, node): | |
738 | raise ValueError("test") |
|
745 | raise ValueError("test") | |
739 |
|
746 | |||
740 | if sys.version_info > (3,8): |
|
747 | # for Python 3.8+ | |
741 |
|
|
748 | def visit_Constant(self, node): | |
742 |
|
|
749 | if isinstance(node.value, int): | |
743 |
|
|
750 | return self.visit_Num(node) | |
744 |
|
|
751 | return node | |
745 |
|
752 | |||
746 |
|
753 | |||
747 | class TestAstTransformError(unittest.TestCase): |
|
754 | class TestAstTransformError(unittest.TestCase): | |
@@ -762,7 +769,8 b' class StringRejector(ast.NodeTransformer):' | |||||
762 | Used to verify that NodeTransformers can signal that a piece of code should |
|
769 | Used to verify that NodeTransformers can signal that a piece of code should | |
763 | not be executed by throwing an InputRejected. |
|
770 | not be executed by throwing an InputRejected. | |
764 | """ |
|
771 | """ | |
765 |
|
772 | |||
|
773 | #for python 3.7 and earlier | |||
766 | def visit_Str(self, node): |
|
774 | def visit_Str(self, node): | |
767 | raise InputRejected("test") |
|
775 | raise InputRejected("test") | |
768 |
|
776 |
@@ -384,6 +384,10 b' from IPython.testing.decorators import skipif' | |||||
384 | class TokenizeFailureTest(unittest.TestCase): |
|
384 | class TokenizeFailureTest(unittest.TestCase): | |
385 | """Tests related to https://github.com/ipython/ipython/issues/6864.""" |
|
385 | """Tests related to https://github.com/ipython/ipython/issues/6864.""" | |
386 |
|
386 | |||
|
387 | # that appear to test that we are handling an exception that can be thrown | |||
|
388 | # by the tokenizer due to a bug that seem to have been fixed in 3.8, though | |||
|
389 | # I'm unsure if other sequences can make it raise this error. Let's just | |||
|
390 | # skip in 3.8 for now | |||
387 | @skipif(sys.version_info > (3,8)) |
|
391 | @skipif(sys.version_info > (3,8)) | |
388 | def testLogging(self): |
|
392 | def testLogging(self): | |
389 | message = "An unexpected error occurred while tokenizing input" |
|
393 | message = "An unexpected error occurred while tokenizing input" |
General Comments 0
You need to be logged in to leave comments.
Login now