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
b85898d1
Commit
b85898d1
authored
Apr 05, 2007
by
Collin Winter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert test_normalization to use unittest.
parent
9efcf7e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
51 deletions
+57
-51
Lib/test/test_normalization.py
Lib/test/test_normalization.py
+57
-51
No files found.
Lib/test/test_normalization.py
View file @
b85898d1
from
test.test_support
import
(
verbose
,
TestFailed
,
TestSkipped
,
verify
,
from
test.test_support
import
run_unittest
,
open_urlresource
open_urlresource
)
import
unittest
import
sys
import
sys
import
os
import
os
from
unicodedata
import
normalize
from
unicodedata
import
normalize
...
@@ -28,61 +29,66 @@ def unistr(data):
...
@@ -28,61 +29,66 @@ def unistr(data):
if
x
>
sys
.
maxunicode
:
if
x
>
sys
.
maxunicode
:
raise
RangeError
raise
RangeError
return
u""
.
join
([
unichr
(
x
)
for
x
in
data
])
return
u""
.
join
([
unichr
(
x
)
for
x
in
data
])
class
NormalizationTest
(
unittest
.
TestCase
):
def
test_main
(
self
):
part1_data
=
{}
for
line
in
open_urlresource
(
TESTDATAURL
):
if
'#'
in
line
:
line
=
line
.
split
(
'#'
)[
0
]
line
=
line
.
strip
()
if
not
line
:
continue
if
line
.
startswith
(
"@Part"
):
part
=
line
.
split
()[
0
]
continue
if
part
==
"@Part3"
:
# XXX we don't support PRI #29 yet, so skip these tests for now
continue
try
:
c1
,
c2
,
c3
,
c4
,
c5
=
[
unistr
(
x
)
for
x
in
line
.
split
(
';'
)[:
-
1
]]
except
RangeError
:
# Skip unsupported characters;
# try atleast adding c1 if we are in part1
if
part
==
"@Part1"
:
try
:
c1
=
unistr
(
line
.
split
(
';'
)[
0
])
except
RangeError
:
pass
else
:
part1_data
[
c1
]
=
1
continue
def
test_main
():
# Perform tests
part1_data
=
{}
self
.
failUnless
(
c2
==
NFC
(
c1
)
==
NFC
(
c2
)
==
NFC
(
c3
),
line
)
for
line
in
open_urlresource
(
TESTDATAURL
):
self
.
failUnless
(
c4
==
NFC
(
c4
)
==
NFC
(
c5
),
line
)
if
'#'
in
line
:
self
.
failUnless
(
c3
==
NFD
(
c1
)
==
NFD
(
c2
)
==
NFD
(
c3
),
line
)
line
=
line
.
split
(
'#'
)[
0
]
self
.
failUnless
(
c5
==
NFD
(
c4
)
==
NFD
(
c5
),
line
)
line
=
line
.
strip
()
self
.
failUnless
(
c4
==
NFKC
(
c1
)
==
NFKC
(
c2
)
==
\
if
not
line
:
NFKC
(
c3
)
==
NFKC
(
c4
)
==
NFKC
(
c5
),
continue
line
)
if
line
.
startswith
(
"@Part"
):
self
.
failUnless
(
c5
==
NFKD
(
c1
)
==
NFKD
(
c2
)
==
\
part
=
line
.
split
()[
0
]
NFKD
(
c3
)
==
NFKD
(
c4
)
==
NFKD
(
c5
),
continue
line
)
if
part
==
"@Part3"
:
# XXX we don't support PRI #29 yet, so skip these tests for now
continue
try
:
c1
,
c2
,
c3
,
c4
,
c5
=
[
unistr
(
x
)
for
x
in
line
.
split
(
';'
)[:
-
1
]]
except
RangeError
:
# Skip unsupported characters;
# try atleast adding c1 if we are in part1
if
part
==
"@Part1"
:
try
:
c1
=
unistr
(
line
.
split
(
';'
)[
0
])
except
RangeError
:
pass
else
:
part1_data
[
c1
]
=
1
continue
if
verbose
:
# Record part 1 data
print
line
if
part
==
"@Part1"
:
part1_data
[
c1
]
=
1
# Perform tests
# Perform tests for all other data
verify
(
c2
==
NFC
(
c1
)
==
NFC
(
c2
)
==
NFC
(
c3
),
line
)
for
c
in
range
(
sys
.
maxunicode
+
1
):
verify
(
c4
==
NFC
(
c4
)
==
NFC
(
c5
),
line
)
X
=
unichr
(
c
)
verify
(
c3
==
NFD
(
c1
)
==
NFD
(
c2
)
==
NFD
(
c3
),
line
)
if
X
in
part1_data
:
verify
(
c5
==
NFD
(
c4
)
==
NFD
(
c5
),
line
)
continue
verify
(
c4
==
NFKC
(
c1
)
==
NFKC
(
c2
)
==
NFKC
(
c3
)
==
NFKC
(
c4
)
==
NFKC
(
c5
),
self
.
failUnless
(
X
==
NFC
(
X
)
==
NFD
(
X
)
==
NFKC
(
X
)
==
NFKD
(
X
),
c
)
line
)
verify
(
c5
==
NFKD
(
c1
)
==
NFKD
(
c2
)
==
NFKD
(
c3
)
==
NFKD
(
c4
)
==
NFKD
(
c5
),
line
)
# Record part 1 data
def
test_bug_834676
(
self
):
if
part
==
"@Part1"
:
# Check for bug 834676
part1_data
[
c1
]
=
1
normalize
(
'NFC'
,
u'
\
ud55c
\
uae00
'
)
# Perform tests for all other data
for
c
in
range
(
sys
.
maxunicode
+
1
):
X
=
unichr
(
c
)
if
X
in
part1_data
:
continue
assert
X
==
NFC
(
X
)
==
NFD
(
X
)
==
NFKC
(
X
)
==
NFKD
(
X
),
c
# Check for bug 834676
def
test_main
():
normalize
(
'NFC'
,
u'
\
ud55c
\
uae00
'
)
run_unittest
(
NormalizationTest
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
test_main
()
test_main
()
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