Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8c8d7725
Commit
8c8d7725
authored
Feb 17, 2014
by
Terry Jan Reedy
Browse files
Options
Browse Files
Download
Plain Diff
Untokenize, bad assert: Merge with 3.3
parents
38df2ada
5e6db313
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
+18
-2
Lib/test/test_tokenize.py
Lib/test/test_tokenize.py
+15
-1
Lib/tokenize.py
Lib/tokenize.py
+3
-1
No files found.
Lib/test/test_tokenize.py
View file @
8c8d7725
...
@@ -638,7 +638,7 @@ Legacy unicode literals:
...
@@ -638,7 +638,7 @@ Legacy unicode literals:
from
test
import
support
from
test
import
support
from
tokenize
import
(
tokenize
,
_tokenize
,
untokenize
,
NUMBER
,
NAME
,
OP
,
from
tokenize
import
(
tokenize
,
_tokenize
,
untokenize
,
NUMBER
,
NAME
,
OP
,
STRING
,
ENDMARKER
,
ENCODING
,
tok_name
,
detect_encoding
,
STRING
,
ENDMARKER
,
ENCODING
,
tok_name
,
detect_encoding
,
open
as
tokenize_open
)
open
as
tokenize_open
,
Untokenizer
)
from
io
import
BytesIO
from
io
import
BytesIO
from
unittest
import
TestCase
from
unittest
import
TestCase
import
os
,
sys
,
glob
import
os
,
sys
,
glob
...
@@ -1153,6 +1153,19 @@ class TestTokenize(TestCase):
...
@@ -1153,6 +1153,19 @@ class TestTokenize(TestCase):
# See http://bugs.python.org/issue16152
# See http://bugs.python.org/issue16152
self
.
assertExactTypeEqual
(
'@ '
,
token
.
AT
)
self
.
assertExactTypeEqual
(
'@ '
,
token
.
AT
)
class
UntokenizeTest
(
TestCase
):
def
test_bad_input_order
(
self
):
u
=
Untokenizer
()
u
.
prev_row
=
2
u
.
prev_col
=
2
with
self
.
assertRaises
(
ValueError
)
as
cm
:
u
.
add_whitespace
((
1
,
3
))
self
.
assertEqual
(
cm
.
exception
.
args
[
0
],
'start (1,3) precedes previous end (2,2)'
)
self
.
assertRaises
(
ValueError
,
u
.
add_whitespace
,
(
2
,
1
))
__test__
=
{
"doctests"
:
doctests
,
'decistmt'
:
decistmt
}
__test__
=
{
"doctests"
:
doctests
,
'decistmt'
:
decistmt
}
def
test_main
():
def
test_main
():
...
@@ -1162,6 +1175,7 @@ def test_main():
...
@@ -1162,6 +1175,7 @@ def test_main():
support
.
run_unittest
(
Test_Tokenize
)
support
.
run_unittest
(
Test_Tokenize
)
support
.
run_unittest
(
TestDetectEncoding
)
support
.
run_unittest
(
TestDetectEncoding
)
support
.
run_unittest
(
TestTokenize
)
support
.
run_unittest
(
TestTokenize
)
support
.
run_unittest
(
UntokenizeTest
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
test_main
()
test_main
()
Lib/tokenize.py
View file @
8c8d7725
...
@@ -229,7 +229,9 @@ class Untokenizer:
...
@@ -229,7 +229,9 @@ class Untokenizer:
def add_whitespace(self, start):
def add_whitespace(self, start):
row, col = start
row, col = start
assert row <= self.prev_row
if row < self.prev_row or row == self.prev_row and col < self.prev_col:
raise ValueError("start ({},{}) precedes previous end ({},{})"
.format(row, col, self.prev_row, self.prev_col))
col_offset = col - self.prev_col
col_offset = col - self.prev_col
if col_offset:
if col_offset:
self.tokens.append(" " * col_offset)
self.tokens.append(" " * col_offset)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment