@@ -1631,13 +1631,34 @@ def test_pathological_trailing_whitespace(self):
1631
1631
def test_comment_at_the_end_of_the_source_without_newline (self ):
1632
1632
# See http://bugs.python.org/issue44667
1633
1633
source = 'b = 1\n \n #test'
1634
- expected_tokens = [token .NAME , token .EQUAL , token .NUMBER , token .NEWLINE , token .NL , token .COMMENT ]
1634
+ expected_tokens = [
1635
+ TokenInfo (type = token .ENCODING , string = 'utf-8' , start = (0 , 0 ), end = (0 , 0 ), line = '' ),
1636
+ TokenInfo (type = token .NAME , string = 'b' , start = (1 , 0 ), end = (1 , 1 ), line = 'b = 1\n ' ),
1637
+ TokenInfo (type = token .OP , string = '=' , start = (1 , 2 ), end = (1 , 3 ), line = 'b = 1\n ' ),
1638
+ TokenInfo (type = token .NUMBER , string = '1' , start = (1 , 4 ), end = (1 , 5 ), line = 'b = 1\n ' ),
1639
+ TokenInfo (type = token .NEWLINE , string = '\n ' , start = (1 , 5 ), end = (1 , 6 ), line = 'b = 1\n ' ),
1640
+ TokenInfo (type = token .NL , string = '\n ' , start = (2 , 0 ), end = (2 , 1 ), line = '\n ' ),
1641
+ TokenInfo (type = token .COMMENT , string = '#test' , start = (3 , 0 ), end = (3 , 5 ), line = '#test\n ' ),
1642
+ TokenInfo (type = token .NL , string = '' , start = (3 , 5 ), end = (3 , 6 ), line = '#test\n ' ),
1643
+ TokenInfo (type = token .ENDMARKER , string = '' , start = (4 , 0 ), end = (4 , 0 ), line = '' )
1644
+ ]
1645
+
1646
+ tokens = list (tokenize (BytesIO (source .encode ('utf-8' )).readline ))
1647
+ self .assertEqual (tokens , expected_tokens )
1648
+
1649
+ def test_newline_and_space_at_the_end_of_the_source_without_newline (self ):
1650
+ # See https://github.com/python/cpython/issues/105435
1651
+ source = 'a\n '
1652
+ expected_tokens = [
1653
+ TokenInfo (token .ENCODING , string = 'utf-8' , start = (0 , 0 ), end = (0 , 0 ), line = '' ),
1654
+ TokenInfo (token .NAME , string = 'a' , start = (1 , 0 ), end = (1 , 1 ), line = 'a\n ' ),
1655
+ TokenInfo (token .NEWLINE , string = '\n ' , start = (1 , 1 ), end = (1 , 2 ), line = 'a\n ' ),
1656
+ TokenInfo (token .NL , string = '' , start = (2 , 1 ), end = (2 , 2 ), line = ' \n ' ),
1657
+ TokenInfo (token .ENDMARKER , string = '' , start = (3 , 0 ), end = (3 , 0 ), line = '' )
1658
+ ]
1635
1659
1636
1660
tokens = list (tokenize (BytesIO (source .encode ('utf-8' )).readline ))
1637
- self .assertEqual (tok_name [tokens [0 ].exact_type ], tok_name [ENCODING ])
1638
- for i in range (6 ):
1639
- self .assertEqual (tok_name [tokens [i + 1 ].exact_type ], tok_name [expected_tokens [i ]])
1640
- self .assertEqual (tok_name [tokens [- 1 ].exact_type ], tok_name [token .ENDMARKER ])
1661
+ self .assertEqual (tokens , expected_tokens )
1641
1662
1642
1663
def test_invalid_character_in_fstring_middle (self ):
1643
1664
# See gh-103824
0 commit comments