Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VTK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christian Butz
VTK
Commits
8aead085
Commit
8aead085
authored
9 years ago
by
David Gobbi
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for encoded strings in python.
parent
4f450d14
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Common/Core/Testing/Python/TestStrings.py
+36
-6
36 additions, 6 deletions
Common/Core/Testing/Python/TestStrings.py
with
36 additions
and
6 deletions
Common/Core/Testing/Python/TestStrings.py
+
36
−
6
View file @
8aead085
...
...
@@ -17,13 +17,14 @@ import sys
import
vtk
from
vtk.test
import
Testing
if
sys
.
hexversion
>
0x03000000
:
if
sys
.
hexversion
>
=
0x03000000
:
cedilla
=
'
Fran
\xe7
ois
'
nocedilla
=
'
Francois
'
eightbit
=
'
Francois
'
.
encode
(
'
ascii
'
)
else
:
cedilla
=
unicode
(
'
Fran
\xe7
ois
'
,
'
latin1
'
)
nocedilla
=
unicode
(
'
Francois
'
)
eightbit
=
'
Francois
'
class
TestString
(
Testing
.
vtkTest
):
def
testPassByValue
(
self
):
...
...
@@ -62,18 +63,47 @@ class TestString(Testing.vtkTest):
u
=
a
.
GetValue
(
0
)
self
.
assertEqual
(
u
,
cedilla
)
def
testPass
String
AsUnicode
(
self
):
"""
Pass
a
string when unicode is expected. Should fail.
"""
def
testPass
Bytes
AsUnicode
(
self
):
"""
Pass
8-bit
string when unicode is expected. Should fail.
"""
a
=
vtk
.
vtkUnicodeStringArray
()
self
.
assertRaises
(
TypeError
,
a
.
InsertNextValue
,
(
'
Francois
'
,)
)
a
.
InsertNextValue
,
eightbit
)
def
testPassUnicodeAsString
(
self
):
"""
Pass
a
unicode where
a
string is expected. Should succeed.
"""
"""
Pass unicode where string is expected. Should succeed.
"""
a
=
vtk
.
vtkStringArray
()
a
.
InsertNextValue
(
nocedilla
)
s
=
a
.
GetValue
(
0
)
self
.
assertEqual
(
s
,
'
Francois
'
)
def
testPassBytesAsString
(
self
):
"""
Pass 8-bit string where string is expected. Should succeed.
"""
a
=
vtk
.
vtkStringArray
()
a
.
InsertNextValue
(
eightbit
)
s
=
a
.
GetValue
(
0
)
self
.
assertEqual
(
s
,
'
Francois
'
)
def
testPassEncodedString
(
self
):
"""
Pass encoded 8-bit strings.
"""
a
=
vtk
.
vtkStringArray
()
# latin1 encoded string will be returned as "bytes", which is
# just a normal str object in Python 2
encoded
=
cedilla
.
encode
(
'
latin1
'
)
a
.
InsertNextValue
(
encoded
)
result
=
a
.
GetValue
(
0
)
self
.
assertEqual
(
type
(
result
),
bytes
)
self
.
assertEqual
(
result
,
encoded
)
# utf-8 encoded string will be returned as "str", which is
# actually unicode in Python 3
a
=
vtk
.
vtkStringArray
()
encoded
=
cedilla
.
encode
(
'
utf-8
'
)
a
.
InsertNextValue
(
encoded
)
result
=
a
.
GetValue
(
0
)
self
.
assertEqual
(
type
(
result
),
str
)
if
sys
.
hexversion
>=
0x03000000
:
self
.
assertEqual
(
result
.
encode
(
'
utf-8
'
),
encoded
)
else
:
self
.
assertEqual
(
result
,
encoded
)
if
__name__
==
"
__main__
"
:
Testing
.
main
([(
TestString
,
'
test
'
)])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment