mirror of
https://github.com/python/cpython.git
synced 2025-01-19 23:15:20 +08:00
611f8f5e8e
svn+ssh://svn.python.org/python/branches/py3k ........ r83352 | georg.brandl | 2010-07-31 20:11:07 +0200 (Sa, 31 Jul 2010) | 1 line #9440: Remove borderline test case that fails based on unpredictable conditions such as compiler flags. ........ r83355 | georg.brandl | 2010-07-31 21:17:11 +0200 (Sa, 31 Jul 2010) | 1 line Fix bad merge: test_support -> support. ........ r83356 | georg.brandl | 2010-07-31 21:29:15 +0200 (Sa, 31 Jul 2010) | 1 line Remove trailing whitespace. ........ r83357 | georg.brandl | 2010-07-31 21:59:55 +0200 (Sa, 31 Jul 2010) | 1 line #5778: document that sys.version can contain a newline. ........ r83358 | georg.brandl | 2010-07-31 22:05:31 +0200 (Sa, 31 Jul 2010) | 1 line #9442: do not document a specific format for sys.version; rather refer to version_info and the platform module. ........ r83362 | georg.brandl | 2010-07-31 23:12:15 +0200 (Sa, 31 Jul 2010) | 1 line #8910: add a file explaining why Lib/test/data is there. ........ r83366 | georg.brandl | 2010-07-31 23:26:40 +0200 (Sa, 31 Jul 2010) | 1 line There always is a False and True now. ........ r83368 | georg.brandl | 2010-07-31 23:40:15 +0200 (Sa, 31 Jul 2010) | 1 line #7909: the prefixes \\.\ and \\?\ indicate special Windows paths, do not try to manipulate them. See http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx for details. ........ r83369 | georg.brandl | 2010-07-31 23:41:42 +0200 (Sa, 31 Jul 2010) | 1 line Fix "Berkeley" name. ........
161 lines
4.4 KiB
Python
161 lines
4.4 KiB
Python
#!/usr/bin/env python
|
|
|
|
import unittest
|
|
import os
|
|
from test import support
|
|
|
|
# Skip this test if the _tkinter module wasn't built.
|
|
_tkinter = support.import_module('_tkinter')
|
|
|
|
from tkinter import Tcl
|
|
from _tkinter import TclError
|
|
|
|
|
|
class TkinterTest(unittest.TestCase):
|
|
|
|
def testFlattenLen(self):
|
|
# flatten(<object with no length>)
|
|
self.assertRaises(TypeError, _tkinter._flatten, True)
|
|
|
|
|
|
class TclTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.interp = Tcl()
|
|
|
|
def testEval(self):
|
|
tcl = self.interp
|
|
tcl.eval('set a 1')
|
|
self.assertEqual(tcl.eval('set a'),'1')
|
|
|
|
def testEvalException(self):
|
|
tcl = self.interp
|
|
self.assertRaises(TclError,tcl.eval,'set a')
|
|
|
|
def testEvalException2(self):
|
|
tcl = self.interp
|
|
self.assertRaises(TclError,tcl.eval,'this is wrong')
|
|
|
|
def testCall(self):
|
|
tcl = self.interp
|
|
tcl.call('set','a','1')
|
|
self.assertEqual(tcl.call('set','a'),'1')
|
|
|
|
def testCallException(self):
|
|
tcl = self.interp
|
|
self.assertRaises(TclError,tcl.call,'set','a')
|
|
|
|
def testCallException2(self):
|
|
tcl = self.interp
|
|
self.assertRaises(TclError,tcl.call,'this','is','wrong')
|
|
|
|
def testSetVar(self):
|
|
tcl = self.interp
|
|
tcl.setvar('a','1')
|
|
self.assertEqual(tcl.eval('set a'),'1')
|
|
|
|
def testSetVarArray(self):
|
|
tcl = self.interp
|
|
tcl.setvar('a(1)','1')
|
|
self.assertEqual(tcl.eval('set a(1)'),'1')
|
|
|
|
def testGetVar(self):
|
|
tcl = self.interp
|
|
tcl.eval('set a 1')
|
|
self.assertEqual(tcl.getvar('a'),'1')
|
|
|
|
def testGetVarArray(self):
|
|
tcl = self.interp
|
|
tcl.eval('set a(1) 1')
|
|
self.assertEqual(tcl.getvar('a(1)'),'1')
|
|
|
|
def testGetVarException(self):
|
|
tcl = self.interp
|
|
self.assertRaises(TclError,tcl.getvar,'a')
|
|
|
|
def testGetVarArrayException(self):
|
|
tcl = self.interp
|
|
self.assertRaises(TclError,tcl.getvar,'a(1)')
|
|
|
|
def testUnsetVar(self):
|
|
tcl = self.interp
|
|
tcl.setvar('a',1)
|
|
self.assertEqual(tcl.eval('info exists a'),'1')
|
|
tcl.unsetvar('a')
|
|
self.assertEqual(tcl.eval('info exists a'),'0')
|
|
|
|
def testUnsetVarArray(self):
|
|
tcl = self.interp
|
|
tcl.setvar('a(1)',1)
|
|
tcl.setvar('a(2)',2)
|
|
self.assertEqual(tcl.eval('info exists a(1)'),'1')
|
|
self.assertEqual(tcl.eval('info exists a(2)'),'1')
|
|
tcl.unsetvar('a(1)')
|
|
self.assertEqual(tcl.eval('info exists a(1)'),'0')
|
|
self.assertEqual(tcl.eval('info exists a(2)'),'1')
|
|
|
|
def testUnsetVarException(self):
|
|
tcl = self.interp
|
|
self.assertRaises(TclError,tcl.unsetvar,'a')
|
|
|
|
def testEvalFile(self):
|
|
tcl = self.interp
|
|
filename = "testEvalFile.tcl"
|
|
fd = open(filename,'w')
|
|
script = """set a 1
|
|
set b 2
|
|
set c [ expr $a + $b ]
|
|
"""
|
|
fd.write(script)
|
|
fd.close()
|
|
tcl.evalfile(filename)
|
|
os.remove(filename)
|
|
self.assertEqual(tcl.eval('set a'),'1')
|
|
self.assertEqual(tcl.eval('set b'),'2')
|
|
self.assertEqual(tcl.eval('set c'),'3')
|
|
|
|
def testEvalFileException(self):
|
|
tcl = self.interp
|
|
filename = "doesnotexists"
|
|
try:
|
|
os.remove(filename)
|
|
except Exception as e:
|
|
pass
|
|
self.assertRaises(TclError,tcl.evalfile,filename)
|
|
|
|
def testPackageRequireException(self):
|
|
tcl = self.interp
|
|
self.assertRaises(TclError,tcl.eval,'package require DNE')
|
|
|
|
def testLoadWithUNC(self):
|
|
import sys
|
|
if sys.platform != 'win32':
|
|
return
|
|
|
|
# Build a UNC path from the regular path.
|
|
# Something like
|
|
# \\%COMPUTERNAME%\c$\python27\python.exe
|
|
|
|
fullname = os.path.abspath(sys.executable)
|
|
if fullname[1] != ':':
|
|
return
|
|
unc_name = r'\\%s\%s$\%s' % (os.environ['COMPUTERNAME'],
|
|
fullname[0],
|
|
fullname[3:])
|
|
|
|
with support.EnvironmentVarGuard() as env:
|
|
env.unset("TCL_LIBRARY")
|
|
f = os.popen('%s -c "import Tkinter; print Tkinter"' % (unc_name,))
|
|
|
|
self.assert_('Tkinter.py' in f.read())
|
|
# exit code must be zero
|
|
self.assertEqual(f.close(), None)
|
|
|
|
|
|
|
|
def test_main():
|
|
support.run_unittest(TclTest, TkinterTest)
|
|
|
|
if __name__ == "__main__":
|
|
test_main()
|