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
fc055252
Commit
fc055252
authored
Feb 03, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20368: Add tests for Tkinter methods exprstring(), exprdouble(),
exprlong() and exprboolean().
parent
3633da23
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
135 additions
and
0 deletions
+135
-0
Lib/test/test_tcl.py
Lib/test/test_tcl.py
+135
-0
No files found.
Lib/test/test_tcl.py
View file @
fc055252
...
...
@@ -177,6 +177,141 @@ class TclTest(unittest.TestCase):
# exit code must be zero
self
.
assertEqual
(
f
.
close
(),
None
)
def
test_exprstring
(
self
):
tcl
=
self
.
interp
tcl
.
call
(
'set'
,
'a'
,
3
)
tcl
.
call
(
'set'
,
'b'
,
6
)
def
check
(
expr
,
expected
):
result
=
tcl
.
exprstring
(
expr
)
self
.
assertEqual
(
result
,
expected
)
self
.
assertIsInstance
(
result
,
str
)
self
.
assertRaises
(
TypeError
,
tcl
.
exprstring
)
self
.
assertRaises
(
TypeError
,
tcl
.
exprstring
,
'8.2'
,
'+6'
)
self
.
assertRaises
(
TypeError
,
tcl
.
exprstring
,
b'8.2 + 6'
)
self
.
assertRaises
(
TclError
,
tcl
.
exprstring
,
'spam'
)
check
(
''
,
'0'
)
check
(
'8.2 + 6'
,
'14.2'
)
check
(
'2**64'
,
str
(
2
**
64
))
check
(
'3.1 + $a'
,
'6.1'
)
check
(
'2 + "$a.$b"'
,
'5.6'
)
check
(
'4*[llength "6 2"]'
,
'8'
)
check
(
'{word one} < "word $a"'
,
'0'
)
check
(
'4*2 < 7'
,
'0'
)
check
(
'hypot($a, 4)'
,
'5.0'
)
check
(
'5 / 4'
,
'1'
)
check
(
'5 / 4.0'
,
'1.25'
)
check
(
'5 / ( [string length "abcd"] + 0.0 )'
,
'1.25'
)
check
(
'20.0/5.0'
,
'4.0'
)
check
(
'"0x03" > "2"'
,
'1'
)
check
(
'[string length "a
\
xbd
\
u20ac
"]'
,
'3'
)
check
(
r'[string length "a\xbd\u20ac"]'
,
'3'
)
check
(
'"abc"'
,
'abc'
)
check
(
'"a
\
xbd
\
u20ac
"'
,
'a
\
xbd
\
u20ac
'
)
check
(
r'"a\xbd\u20ac"'
,
'a
\
xbd
\
u20ac
'
)
def
test_exprdouble
(
self
):
tcl
=
self
.
interp
tcl
.
call
(
'set'
,
'a'
,
3
)
tcl
.
call
(
'set'
,
'b'
,
6
)
def
check
(
expr
,
expected
):
result
=
tcl
.
exprdouble
(
expr
)
self
.
assertEqual
(
result
,
expected
)
self
.
assertIsInstance
(
result
,
float
)
self
.
assertRaises
(
TypeError
,
tcl
.
exprdouble
)
self
.
assertRaises
(
TypeError
,
tcl
.
exprdouble
,
'8.2'
,
'+6'
)
self
.
assertRaises
(
TypeError
,
tcl
.
exprdouble
,
b'8.2 + 6'
)
self
.
assertRaises
(
TclError
,
tcl
.
exprdouble
,
'spam'
)
check
(
''
,
0.0
)
check
(
'8.2 + 6'
,
14.2
)
check
(
'2**64'
,
float
(
2
**
64
))
check
(
'3.1 + $a'
,
6.1
)
check
(
'2 + "$a.$b"'
,
5.6
)
check
(
'4*[llength "6 2"]'
,
8.0
)
check
(
'{word one} < "word $a"'
,
0.0
)
check
(
'4*2 < 7'
,
0.0
)
check
(
'hypot($a, 4)'
,
5.0
)
check
(
'5 / 4'
,
1.0
)
check
(
'5 / 4.0'
,
1.25
)
check
(
'5 / ( [string length "abcd"] + 0.0 )'
,
1.25
)
check
(
'20.0/5.0'
,
4.0
)
check
(
'"0x03" > "2"'
,
1.0
)
check
(
'[string length "a
\
xbd
\
u20ac
"]'
,
3.0
)
check
(
r'[string length "a\xbd\u20ac"]'
,
3.0
)
self
.
assertRaises
(
TclError
,
tcl
.
exprdouble
,
'"abc"'
)
def
test_exprlong
(
self
):
tcl
=
self
.
interp
tcl
.
call
(
'set'
,
'a'
,
3
)
tcl
.
call
(
'set'
,
'b'
,
6
)
def
check
(
expr
,
expected
):
result
=
tcl
.
exprlong
(
expr
)
self
.
assertEqual
(
result
,
expected
)
self
.
assertIsInstance
(
result
,
int
)
self
.
assertRaises
(
TypeError
,
tcl
.
exprlong
)
self
.
assertRaises
(
TypeError
,
tcl
.
exprlong
,
'8.2'
,
'+6'
)
self
.
assertRaises
(
TypeError
,
tcl
.
exprlong
,
b'8.2 + 6'
)
self
.
assertRaises
(
TclError
,
tcl
.
exprlong
,
'spam'
)
check
(
''
,
0
)
check
(
'8.2 + 6'
,
14
)
self
.
assertRaises
(
TclError
,
tcl
.
exprlong
,
'2**64'
)
check
(
'3.1 + $a'
,
6
)
check
(
'2 + "$a.$b"'
,
5
)
check
(
'4*[llength "6 2"]'
,
8
)
check
(
'{word one} < "word $a"'
,
0
)
check
(
'4*2 < 7'
,
0
)
check
(
'hypot($a, 4)'
,
5
)
check
(
'5 / 4'
,
1
)
check
(
'5 / 4.0'
,
1
)
check
(
'5 / ( [string length "abcd"] + 0.0 )'
,
1
)
check
(
'20.0/5.0'
,
4
)
check
(
'"0x03" > "2"'
,
1
)
check
(
'[string length "a
\
xbd
\
u20ac
"]'
,
3
)
check
(
r'[string length "a\xbd\u20ac"]'
,
3
)
self
.
assertRaises
(
TclError
,
tcl
.
exprlong
,
'"abc"'
)
def
test_exprboolean
(
self
):
tcl
=
self
.
interp
tcl
.
call
(
'set'
,
'a'
,
3
)
tcl
.
call
(
'set'
,
'b'
,
6
)
def
check
(
expr
,
expected
):
result
=
tcl
.
exprboolean
(
expr
)
self
.
assertEqual
(
result
,
expected
)
self
.
assertIsInstance
(
result
,
int
)
self
.
assertNotIsInstance
(
result
,
bool
)
self
.
assertRaises
(
TypeError
,
tcl
.
exprboolean
)
self
.
assertRaises
(
TypeError
,
tcl
.
exprboolean
,
'8.2'
,
'+6'
)
self
.
assertRaises
(
TypeError
,
tcl
.
exprboolean
,
b'8.2 + 6'
)
self
.
assertRaises
(
TclError
,
tcl
.
exprboolean
,
'spam'
)
check
(
''
,
False
)
for
value
in
(
'0'
,
'false'
,
'no'
,
'off'
):
check
(
value
,
False
)
check
(
'"%s"'
%
value
,
False
)
check
(
'{%s}'
%
value
,
False
)
for
value
in
(
'1'
,
'true'
,
'yes'
,
'on'
):
check
(
value
,
True
)
check
(
'"%s"'
%
value
,
True
)
check
(
'{%s}'
%
value
,
True
)
check
(
'8.2 + 6'
,
True
)
check
(
'2**64'
,
True
)
check
(
'3.1 + $a'
,
True
)
check
(
'2 + "$a.$b"'
,
True
)
check
(
'4*[llength "6 2"]'
,
True
)
check
(
'{word one} < "word $a"'
,
False
)
check
(
'4*2 < 7'
,
False
)
check
(
'hypot($a, 4)'
,
True
)
check
(
'5 / 4'
,
True
)
check
(
'5 / 4.0'
,
True
)
check
(
'5 / ( [string length "abcd"] + 0.0 )'
,
True
)
check
(
'20.0/5.0'
,
True
)
check
(
'"0x03" > "2"'
,
True
)
check
(
'[string length "a
\
xbd
\
u20ac
"]'
,
True
)
check
(
r'[string length "a\xbd\u20ac"]'
,
True
)
self
.
assertRaises
(
TclError
,
tcl
.
exprboolean
,
'"abc"'
)
def
test_passing_values
(
self
):
def
passValue
(
value
):
return
self
.
interp
.
call
(
'set'
,
'_'
,
value
)
...
...
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