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
dbb9630c
Commit
dbb9630c
authored
Dec 26, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backported tests for Tkinter variables.
parent
5e116551
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
0 deletions
+154
-0
Lib/lib-tk/test/test_tkinter/test_variables.py
Lib/lib-tk/test/test_tkinter/test_variables.py
+152
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/lib-tk/test/test_tkinter/test_variables.py
0 → 100644
View file @
dbb9630c
import
unittest
from
Tkinter
import
Variable
,
StringVar
,
IntVar
,
DoubleVar
,
BooleanVar
,
Tk
,
TclError
class
TestBase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
root
=
Tk
()
def
tearDown
(
self
):
self
.
root
.
destroy
()
class
TestVariable
(
TestBase
):
def
info_exists
(
self
,
*
args
):
return
self
.
root
.
getboolean
(
self
.
root
.
call
(
"info"
,
"exists"
,
*
args
))
def
test_default
(
self
):
v
=
Variable
(
self
.
root
)
self
.
assertEqual
(
""
,
v
.
get
())
self
.
assertRegexpMatches
(
str
(
v
),
r"^PY_VAR(\
d+)$
")
def test_name_and_value(self):
v = Variable(self.root, "
sample
string
", "
varname
")
self.assertEqual("
sample
string
", v.get())
self.assertEqual("
varname
", str(v))
def test___del__(self):
self.assertFalse(self.info_exists("
varname
"))
v = Variable(self.root, "
sample
string
", "
varname
")
self.assertTrue(self.info_exists("
varname
"))
del v
self.assertFalse(self.info_exists("
varname
"))
def test_dont_unset_not_existing(self):
self.assertFalse(self.info_exists("
varname
"))
v1 = Variable(self.root, name="
name
")
v2 = Variable(self.root, name="
name
")
del v1
self.assertFalse(self.info_exists("
name
"))
# shouldn't raise exception
del v2
self.assertFalse(self.info_exists("
name
"))
def test___eq__(self):
# values doesn't matter, only class and name are checked
v1 = Variable(self.root, name="
abc
")
v2 = Variable(self.root, name="
abc
")
self.assertEqual(v1, v2)
v3 = Variable(self.root, name="
abc
")
v4 = StringVar(self.root, name="
abc
")
self.assertNotEqual(v3, v4)
def test_invalid_name(self):
with self.assertRaises(TypeError):
Variable(self.root, name=123)
class TestStringVar(TestBase):
def test_default(self):
v = StringVar(self.root)
self.assertEqual("", v.get())
def test_get(self):
v = StringVar(self.root, "
abc
", "
name
")
self.assertEqual("
abc
", v.get())
self.root.globalsetvar("
name
", "
value
")
self.assertEqual("
value
", v.get())
class TestIntVar(TestBase):
def test_default(self):
v = IntVar(self.root)
self.assertEqual(0, v.get())
def test_get(self):
v = IntVar(self.root, 123, "
name
")
self.assertEqual(123, v.get())
self.root.globalsetvar("
name
", "
345
")
self.assertEqual(345, v.get())
def test_invalid_value(self):
v = IntVar(self.root, name="
name
")
self.root.globalsetvar("
name
", "
value
")
with self.assertRaises(ValueError):
v.get()
self.root.globalsetvar("
name
", "
345.0
")
with self.assertRaises(ValueError):
v.get()
class TestDoubleVar(TestBase):
def test_default(self):
v = DoubleVar(self.root)
self.assertEqual(0.0, v.get())
def test_get(self):
v = DoubleVar(self.root, 1.23, "
name
")
self.assertAlmostEqual(1.23, v.get())
self.root.globalsetvar("
name
", "
3.45
")
self.assertAlmostEqual(3.45, v.get())
def test_get_from_int(self):
v = DoubleVar(self.root, 1.23, "
name
")
self.assertAlmostEqual(1.23, v.get())
self.root.globalsetvar("
name
", "
3.45
")
self.assertAlmostEqual(3.45, v.get())
self.root.globalsetvar("
name
", "
456
")
self.assertAlmostEqual(456, v.get())
def test_invalid_value(self):
v = DoubleVar(self.root, name="
name
")
self.root.globalsetvar("
name
", "
value
")
with self.assertRaises(ValueError):
v.get()
class TestBooleanVar(TestBase):
def test_default(self):
v = BooleanVar(self.root)
self.assertEqual(False, v.get())
def test_get(self):
v = BooleanVar(self.root, True, "
name
")
self.assertAlmostEqual(True, v.get())
self.root.globalsetvar("
name
", "
0
")
self.assertAlmostEqual(False, v.get())
def test_invalid_value_domain(self):
v = BooleanVar(self.root, name="
name
")
self.root.globalsetvar("
name
", "
value
")
with self.assertRaises(TclError):
v.get()
self.root.globalsetvar("
name
", "
1.0
")
with self.assertRaises(TclError):
v.get()
tests_gui = (TestVariable, TestStringVar, TestIntVar,
TestDoubleVar, TestBooleanVar)
if __name__ == "
__main__
":
from test.support import run_unittest
run_unittest(*tests_gui)
Misc/NEWS
View file @
dbb9630c
...
...
@@ -134,6 +134,8 @@ IDLE
Tests
-----
- Backported tests for Tkinter variables.
- Issue #19320: test_tcl no longer fails when wantobjects is false.
- Issue #19683: Removed empty tests from test_minidom. Initial patch by
...
...
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