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