Commit 95cf9862 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Import Tkinter as tkinter to help merging and avoid backporting errors.

parent c208fe67
import unittest import unittest
import Tkinter import Tkinter as tkinter
#from Tkinter #from Tkinter
import tkFont as font import tkFont as font
from test.test_support import requires, run_unittest from test.test_support import requires, run_unittest
...@@ -19,7 +19,7 @@ class FontTest(unittest.TestCase): ...@@ -19,7 +19,7 @@ class FontTest(unittest.TestCase):
fontname = "TkDefaultFont" fontname = "TkDefaultFont"
try: try:
f = font.Font(name=fontname, exists=True) f = font.Font(name=fontname, exists=True)
except Tkinter._tkinter.TclError: except tkinter._tkinter.TclError:
f = font.Font(name=fontname, exists=False) f = font.Font(name=fontname, exists=False)
font1 = font.nametofont(fontname) font1 = font.nametofont(fontname)
font2 = font.nametofont(fontname) font2 = font.nametofont(fontname)
......
import unittest import unittest
import Tkinter import Tkinter as tkinter
from test.test_support import requires, run_unittest from test.test_support import requires, run_unittest
from ttk import setup_master from ttk import setup_master
...@@ -9,7 +9,7 @@ class TextTest(unittest.TestCase): ...@@ -9,7 +9,7 @@ class TextTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.root = setup_master() self.root = setup_master()
self.text = Tkinter.Text(self.root) self.text = tkinter.Text(self.root)
def tearDown(self): def tearDown(self):
self.text.destroy() self.text.destroy()
...@@ -30,12 +30,12 @@ class TextTest(unittest.TestCase): ...@@ -30,12 +30,12 @@ class TextTest(unittest.TestCase):
text = self.text text = self.text
# pattern and index are obligatory arguments. # pattern and index are obligatory arguments.
self.assertRaises(Tkinter.TclError, text.search, None, '1.0') self.assertRaises(tkinter.TclError, text.search, None, '1.0')
self.assertRaises(Tkinter.TclError, text.search, 'a', None) self.assertRaises(tkinter.TclError, text.search, 'a', None)
self.assertRaises(Tkinter.TclError, text.search, None, None) self.assertRaises(tkinter.TclError, text.search, None, None)
# Invalid text index. # Invalid text index.
self.assertRaises(Tkinter.TclError, text.search, '', 0) self.assertRaises(tkinter.TclError, text.search, '', 0)
# Check if we are getting the indices as strings -- you are likely # Check if we are getting the indices as strings -- you are likely
# to get Tcl_Obj under Tk 8.5 if Tkinter doesn't convert it. # to get Tcl_Obj under Tk 8.5 if Tkinter doesn't convert it.
......
import unittest import unittest
import Tkinter import Tkinter as tkinter
def get_tk_root(): def get_tk_root():
try: try:
root = Tkinter._default_root root = tkinter._default_root
except AttributeError: except AttributeError:
# it is possible to disable default root in Tkinter, although # it is possible to disable default root in Tkinter, although
# I haven't seen people doing it (but apparently someone did it # I haven't seen people doing it (but apparently someone did it
...@@ -12,7 +12,7 @@ def get_tk_root(): ...@@ -12,7 +12,7 @@ def get_tk_root():
if root is None: if root is None:
# create a new master only if there isn't one already # create a new master only if there isn't one already
root = Tkinter.Tk() root = tkinter.Tk()
return root return root
...@@ -45,7 +45,7 @@ _tk_patchlevel = None ...@@ -45,7 +45,7 @@ _tk_patchlevel = None
def get_tk_patchlevel(): def get_tk_patchlevel():
global _tk_patchlevel global _tk_patchlevel
if _tk_patchlevel is None: if _tk_patchlevel is None:
tcl = Tkinter.Tcl() tcl = tkinter.Tcl()
patchlevel = [] patchlevel = []
for x in tcl.call('info', 'patchlevel').split('.'): for x in tcl.call('info', 'patchlevel').split('.'):
try: try:
...@@ -82,7 +82,7 @@ def tcl_obj_eq(actual, expected): ...@@ -82,7 +82,7 @@ def tcl_obj_eq(actual, expected):
def widget_eq(actual, expected): def widget_eq(actual, expected):
if actual == expected: if actual == expected:
return True return True
if isinstance(actual, (str, Tkinter.Widget)): if isinstance(actual, (str, tkinter.Widget)):
if isinstance(expected, (str, Tkinter.Widget)): if isinstance(expected, (str, tkinter.Widget)):
return str(actual) == str(expected) return str(actual) == str(expected)
return False return False
import sys import sys
import unittest import unittest
import Tkinter import Tkinter as tkinter
import ttk import ttk
from test.test_support import requires, run_unittest from test.test_support import requires, run_unittest
...@@ -22,10 +22,10 @@ class LabeledScaleTest(unittest.TestCase): ...@@ -22,10 +22,10 @@ class LabeledScaleTest(unittest.TestCase):
x = ttk.LabeledScale() x = ttk.LabeledScale()
var = x._variable._name var = x._variable._name
x.destroy() x.destroy()
self.assertRaises(Tkinter.TclError, x.tk.globalgetvar, var) self.assertRaises(tkinter.TclError, x.tk.globalgetvar, var)
# manually created variable # manually created variable
myvar = Tkinter.DoubleVar() myvar = tkinter.DoubleVar()
name = myvar._name name = myvar._name
x = ttk.LabeledScale(variable=myvar) x = ttk.LabeledScale(variable=myvar)
x.destroy() x.destroy()
...@@ -34,10 +34,10 @@ class LabeledScaleTest(unittest.TestCase): ...@@ -34,10 +34,10 @@ class LabeledScaleTest(unittest.TestCase):
else: else:
self.assertEqual(float(x.tk.globalgetvar(name)), myvar.get()) self.assertEqual(float(x.tk.globalgetvar(name)), myvar.get())
del myvar del myvar
self.assertRaises(Tkinter.TclError, x.tk.globalgetvar, name) self.assertRaises(tkinter.TclError, x.tk.globalgetvar, name)
# checking that the tracing callback is properly removed # checking that the tracing callback is properly removed
myvar = Tkinter.IntVar() myvar = tkinter.IntVar()
# LabeledScale will start tracing myvar # LabeledScale will start tracing myvar
x = ttk.LabeledScale(variable=myvar) x = ttk.LabeledScale(variable=myvar)
x.destroy() x.destroy()
...@@ -48,15 +48,15 @@ class LabeledScaleTest(unittest.TestCase): ...@@ -48,15 +48,15 @@ class LabeledScaleTest(unittest.TestCase):
# it tries calling instance attributes not yet defined. # it tries calling instance attributes not yet defined.
ttk.LabeledScale(variable=myvar) ttk.LabeledScale(variable=myvar)
if hasattr(sys, 'last_type'): if hasattr(sys, 'last_type'):
self.assertNotEqual(sys.last_type, Tkinter.TclError) self.assertNotEqual(sys.last_type, tkinter.TclError)
def test_initialization(self): def test_initialization(self):
# master passing # master passing
x = ttk.LabeledScale() x = ttk.LabeledScale()
self.assertEqual(x.master, Tkinter._default_root) self.assertEqual(x.master, tkinter._default_root)
x.destroy() x.destroy()
master = Tkinter.Frame() master = tkinter.Frame()
x = ttk.LabeledScale(master) x = ttk.LabeledScale(master)
self.assertEqual(x.master, master) self.assertEqual(x.master, master)
x.destroy() x.destroy()
...@@ -77,7 +77,7 @@ class LabeledScaleTest(unittest.TestCase): ...@@ -77,7 +77,7 @@ class LabeledScaleTest(unittest.TestCase):
self.assertRaises(ValueError, x._variable.get) self.assertRaises(ValueError, x._variable.get)
x.destroy() x.destroy()
# variable should have its default value set to the from_ value # variable should have its default value set to the from_ value
myvar = Tkinter.DoubleVar(value=20) myvar = tkinter.DoubleVar(value=20)
x = ttk.LabeledScale(variable=myvar) x = ttk.LabeledScale(variable=myvar)
self.assertEqual(x.value, 0) self.assertEqual(x.value, 0)
x.destroy() x.destroy()
...@@ -105,7 +105,7 @@ class LabeledScaleTest(unittest.TestCase): ...@@ -105,7 +105,7 @@ class LabeledScaleTest(unittest.TestCase):
x.destroy() x.destroy()
# extra, and invalid, kwargs # extra, and invalid, kwargs
self.assertRaises(Tkinter.TclError, ttk.LabeledScale, a='b') self.assertRaises(tkinter.TclError, ttk.LabeledScale, a='b')
def test_horizontal_range(self): def test_horizontal_range(self):
...@@ -194,7 +194,7 @@ class OptionMenuTest(unittest.TestCase): ...@@ -194,7 +194,7 @@ class OptionMenuTest(unittest.TestCase):
def setUp(self): def setUp(self):
support.root_deiconify() support.root_deiconify()
self.textvar = Tkinter.StringVar() self.textvar = tkinter.StringVar()
def tearDown(self): def tearDown(self):
del self.textvar del self.textvar
...@@ -202,18 +202,18 @@ class OptionMenuTest(unittest.TestCase): ...@@ -202,18 +202,18 @@ class OptionMenuTest(unittest.TestCase):
def test_widget_destroy(self): def test_widget_destroy(self):
var = Tkinter.StringVar() var = tkinter.StringVar()
optmenu = ttk.OptionMenu(None, var) optmenu = ttk.OptionMenu(None, var)
name = var._name name = var._name
optmenu.update_idletasks() optmenu.update_idletasks()
optmenu.destroy() optmenu.destroy()
self.assertEqual(optmenu.tk.globalgetvar(name), var.get()) self.assertEqual(optmenu.tk.globalgetvar(name), var.get())
del var del var
self.assertRaises(Tkinter.TclError, optmenu.tk.globalgetvar, name) self.assertRaises(tkinter.TclError, optmenu.tk.globalgetvar, name)
def test_initialization(self): def test_initialization(self):
self.assertRaises(Tkinter.TclError, self.assertRaises(tkinter.TclError,
ttk.OptionMenu, None, self.textvar, invalid='thing') ttk.OptionMenu, None, self.textvar, invalid='thing')
optmenu = ttk.OptionMenu(None, self.textvar, 'b', 'a', 'b') optmenu = ttk.OptionMenu(None, self.textvar, 'b', 'a', 'b')
...@@ -259,7 +259,7 @@ class OptionMenuTest(unittest.TestCase): ...@@ -259,7 +259,7 @@ class OptionMenuTest(unittest.TestCase):
self.assertEqual(optmenu._variable.get(), items[0]) self.assertEqual(optmenu._variable.get(), items[0])
# changing to an invalid index shouldn't change the variable # changing to an invalid index shouldn't change the variable
self.assertRaises(Tkinter.TclError, optmenu['menu'].invoke, -1) self.assertRaises(tkinter.TclError, optmenu['menu'].invoke, -1)
self.assertEqual(optmenu._variable.get(), items[0]) self.assertEqual(optmenu._variable.get(), items[0])
optmenu.destroy() optmenu.destroy()
......
import unittest import unittest
import Tkinter import Tkinter as tkinter
import ttk import ttk
from test.test_support import requires, run_unittest from test.test_support import requires, run_unittest
...@@ -44,7 +44,7 @@ class StyleTest(unittest.TestCase): ...@@ -44,7 +44,7 @@ class StyleTest(unittest.TestCase):
def test_layout(self): def test_layout(self):
style = self.style style = self.style
self.assertRaises(Tkinter.TclError, style.layout, 'NotALayout') self.assertRaises(tkinter.TclError, style.layout, 'NotALayout')
tv_style = style.layout('Treeview') tv_style = style.layout('Treeview')
# "erase" Treeview layout # "erase" Treeview layout
...@@ -61,12 +61,12 @@ class StyleTest(unittest.TestCase): ...@@ -61,12 +61,12 @@ class StyleTest(unittest.TestCase):
self.assertIsInstance(style.layout('TButton'), list) self.assertIsInstance(style.layout('TButton'), list)
# correct layout, but "option" doesn't exist as option # correct layout, but "option" doesn't exist as option
self.assertRaises(Tkinter.TclError, style.layout, 'Treeview', self.assertRaises(tkinter.TclError, style.layout, 'Treeview',
[('name', {'option': 'inexistent'})]) [('name', {'option': 'inexistent'})])
def test_theme_use(self): def test_theme_use(self):
self.assertRaises(Tkinter.TclError, self.style.theme_use, self.assertRaises(tkinter.TclError, self.style.theme_use,
'nonexistingname') 'nonexistingname')
curr_theme = self.style.theme_use() curr_theme = self.style.theme_use()
......
This diff is collapsed.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import unittest import unittest
import sys import sys
import Tkinter import Tkinter as tkinter
from ttk import setup_master, Scale from ttk import setup_master, Scale
from test_ttk.support import (tcl_version, requires_tcl, get_tk_patchlevel, from test_ttk.support import (tcl_version, requires_tcl, get_tk_patchlevel,
pixels_conv, tcl_obj_eq) pixels_conv, tcl_obj_eq)
...@@ -67,7 +67,7 @@ class AbstractWidgetTest(object): ...@@ -67,7 +67,7 @@ class AbstractWidgetTest(object):
expected = conv(expected) expected = conv(expected)
if not self.wantobjects: if not self.wantobjects:
if isinstance(expected, tuple): if isinstance(expected, tuple):
expected = Tkinter._join(expected) expected = tkinter._join(expected)
else: else:
expected = str(expected) expected = str(expected)
if eq is None: if eq is None:
...@@ -85,7 +85,7 @@ class AbstractWidgetTest(object): ...@@ -85,7 +85,7 @@ class AbstractWidgetTest(object):
orig = widget[name] orig = widget[name]
if errmsg is not None: if errmsg is not None:
errmsg = errmsg.format(value) errmsg = errmsg.format(value)
with self.assertRaises(Tkinter.TclError) as cm: with self.assertRaises(tkinter.TclError) as cm:
widget[name] = value widget[name] = value
if errmsg is not None: if errmsg is not None:
self.assertEqual(str(cm.exception), errmsg) self.assertEqual(str(cm.exception), errmsg)
...@@ -93,7 +93,7 @@ class AbstractWidgetTest(object): ...@@ -93,7 +93,7 @@ class AbstractWidgetTest(object):
self.assertEqual(widget[name], orig) self.assertEqual(widget[name], orig)
else: else:
widget[name] = orig widget[name] = orig
with self.assertRaises(Tkinter.TclError) as cm: with self.assertRaises(tkinter.TclError) as cm:
widget.configure({name: value}) widget.configure({name: value})
if errmsg is not None: if errmsg is not None:
self.assertEqual(str(cm.exception), errmsg) self.assertEqual(str(cm.exception), errmsg)
...@@ -212,7 +212,7 @@ class AbstractWidgetTest(object): ...@@ -212,7 +212,7 @@ class AbstractWidgetTest(object):
errmsg=errmsg) errmsg=errmsg)
def checkImageParam(self, widget, name): def checkImageParam(self, widget, name):
image = Tkinter.PhotoImage('image1') image = tkinter.PhotoImage('image1')
self.checkParam(widget, name, image, conv=str) self.checkParam(widget, name, image, conv=str)
self.checkInvalidParam(widget, name, 'spam', self.checkInvalidParam(widget, name, 'spam',
errmsg='image "spam" doesn\'t exist') errmsg='image "spam" doesn\'t exist')
...@@ -433,7 +433,7 @@ class StandardOptionsTests(object): ...@@ -433,7 +433,7 @@ class StandardOptionsTests(object):
def test_textvariable(self): def test_textvariable(self):
widget = self.create() widget = self.create()
var = Tkinter.StringVar() var = tkinter.StringVar()
self.checkVariableParam(widget, 'textvariable', var) self.checkVariableParam(widget, 'textvariable', var)
def test_troughcolor(self): def test_troughcolor(self):
...@@ -494,7 +494,7 @@ class StandardOptionsTests(object): ...@@ -494,7 +494,7 @@ class StandardOptionsTests(object):
def test_variable(self): def test_variable(self):
widget = self.create() widget = self.create()
var = Tkinter.DoubleVar() var = tkinter.DoubleVar()
self.checkVariableParam(widget, 'variable', var) self.checkVariableParam(widget, 'variable', var)
...@@ -543,5 +543,5 @@ def add_standard_options(*source_classes): ...@@ -543,5 +543,5 @@ def add_standard_options(*source_classes):
def setUpModule(): def setUpModule():
if test.test_support.verbose: if test.test_support.verbose:
tcl = Tkinter.Tcl() tcl = tkinter.Tcl()
print 'patchlevel =', tcl.call('info', 'patchlevel') print 'patchlevel =', tcl.call('info', 'patchlevel')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment