from test
import test_support
from _tkinter
import TclError
class TclTest(unittest
.TestCase
):
self
.assertEqual(tcl
.eval('set a'),'1')
def testEvalException(self
):
self
.assertRaises(TclError
,tcl
.eval,'set a')
def testEvalException2(self
):
self
.assertRaises(TclError
,tcl
.eval,'this is wrong')
self
.assertEqual(tcl
.call('set','a'),'1')
def testCallException(self
):
self
.assertRaises(TclError
,tcl
.call
,'set','a')
def testCallException2(self
):
self
.assertRaises(TclError
,tcl
.call
,'this','is','wrong')
self
.assertEqual(tcl
.eval('set a'),'1')
def testSetVarArray(self
):
self
.assertEqual(tcl
.eval('set a(1)'),'1')
self
.assertEqual(tcl
.getvar('a'),'1')
def testGetVarArray(self
):
self
.assertEqual(tcl
.getvar('a(1)'),'1')
def testGetVarException(self
):
self
.assertRaises(TclError
,tcl
.getvar
,'a')
def testGetVarArrayException(self
):
self
.assertRaises(TclError
,tcl
.getvar
,'a(1)')
self
.assertEqual(tcl
.eval('info exists a'),'1')
self
.assertEqual(tcl
.eval('info exists a'),'0')
def testUnsetVarArray(self
):
self
.assertEqual(tcl
.eval('info exists a(1)'),'1')
self
.assertEqual(tcl
.eval('info exists a(2)'),'1')
self
.assertEqual(tcl
.eval('info exists a(1)'),'0')
self
.assertEqual(tcl
.eval('info exists a(2)'),'1')
def testUnsetVarException(self
):
self
.assertRaises(TclError
,tcl
.unsetvar
,'a')
filename
= "testEvalFile.tcl"
self
.assertEqual(tcl
.eval('set a'),'1')
self
.assertEqual(tcl
.eval('set b'),'2')
self
.assertEqual(tcl
.eval('set c'),'3')
def testEvalFileException(self
):
filename
= "doesnotexists"
self
.assertRaises(TclError
,tcl
.evalfile
,filename
)
def testPackageRequireException(self
):
self
.assertRaises(TclError
,tcl
.eval,'package require DNE')
if 'DISPLAY' not in os
.environ
:
# skipping test of clean upgradeability
self
.assertRaises(TclError
,tcl
.winfo_geometry
)
self
.assertEqual('1x1+0+0', tcl
.winfo_geometry())
def testLoadTkFailure(self
):
if (sys
.platform
.startswith('win') or
sys
.platform
.startswith('darwin') or
sys
.platform
.startswith('cygwin')):
return # no failure possible on windows?
if 'DISPLAY' in os
.environ
:
old_display
= os
.environ
['DISPLAY']
del os
.environ
['DISPLAY']
# on some platforms, deleting environment variables
# doesn't actually carry through to the process level
# because they don't support unsetenv
# If that's the case, abort.
display
= os
.popen('echo $DISPLAY').read().strip()
self
.assertRaises(TclError
, tcl
.winfo_geometry
)
self
.assertRaises(TclError
, tcl
.loadtk
)
if old_display
is not None:
os
.environ
['DISPLAY'] = old_display
test_support
.run_unittest(TclTest
)
if __name__
== "__main__":