diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-26 14:41:14 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-26 14:41:14 (GMT) |
commit | 199b7d5662fe3803733e2067e8fad523d74b1988 (patch) | |
tree | 74957b401efb0a0f4439e814ad2057e2afae5f8b /Lib/lib-tk/test/test_tkinter/test_variables.py | |
parent | 0c67a5f3bf021beab319969c539125fe89d1ed6c (diff) | |
download | cpython-199b7d5662fe3803733e2067e8fad523d74b1988.zip cpython-199b7d5662fe3803733e2067e8fad523d74b1988.tar.gz cpython-199b7d5662fe3803733e2067e8fad523d74b1988.tar.bz2 |
Issue #22115: Fixed tracing Tkinter variables.
* trace_vdelete() with wrong mode no longer break tracing
* trace_vinfo() now always returns a list of pairs of strings
Diffstat (limited to 'Lib/lib-tk/test/test_tkinter/test_variables.py')
-rw-r--r-- | Lib/lib-tk/test/test_tkinter/test_variables.py | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/Lib/lib-tk/test/test_tkinter/test_variables.py b/Lib/lib-tk/test/test_tkinter/test_variables.py index 5e07528..11f9414 100644 --- a/Lib/lib-tk/test/test_tkinter/test_variables.py +++ b/Lib/lib-tk/test/test_tkinter/test_variables.py @@ -1,5 +1,5 @@ import unittest - +import gc from Tkinter import (Variable, StringVar, IntVar, DoubleVar, BooleanVar, Tcl, TclError) @@ -67,6 +67,55 @@ class TestVariable(TestBase): with self.assertRaises(ValueError): self.root.setvar('var\x00name', "value") + def test_trace(self): + v = Variable(self.root) + vname = str(v) + trace = [] + def read_tracer(*args): + trace.append(('read',) + args) + def write_tracer(*args): + trace.append(('write',) + args) + cb1 = v.trace_variable('r', read_tracer) + cb2 = v.trace_variable('wu', write_tracer) + self.assertEqual(sorted(v.trace_vinfo()), [('r', cb1), ('wu', cb2)]) + self.assertEqual(trace, []) + + v.set('spam') + self.assertEqual(trace, [('write', vname, '', 'w')]) + + trace = [] + v.get() + self.assertEqual(trace, [('read', vname, '', 'r')]) + + trace = [] + info = sorted(v.trace_vinfo()) + v.trace_vdelete('w', cb1) # Wrong mode + self.assertEqual(sorted(v.trace_vinfo()), info) + with self.assertRaises(TclError): + v.trace_vdelete('r', 'spam') # Wrong command name + self.assertEqual(sorted(v.trace_vinfo()), info) + v.trace_vdelete('r', (cb1, 43)) # Wrong arguments + self.assertEqual(sorted(v.trace_vinfo()), info) + v.get() + self.assertEqual(trace, [('read', vname, '', 'r')]) + + trace = [] + v.trace_vdelete('r', cb1) + self.assertEqual(v.trace_vinfo(), [('wu', cb2)]) + v.get() + self.assertEqual(trace, []) + + trace = [] + del write_tracer + gc.collect() + v.set('eggs') + self.assertEqual(trace, [('write', vname, '', 'w')]) + + #trace = [] + #del v + #gc.collect() + #self.assertEqual(trace, [('write', vname, '', 'u')]) + class TestStringVar(TestBase): |