| 1 |
import os |
| 2 |
import sys |
| 3 |
import unittest |
| 4 |
from test import test_support |
| 5 |
from Tkinter import Tcl, TclError |
| 6 |
|
| 7 |
test_support.requires('gui') |
| 8 |
|
| 9 |
class TkLoadTest(unittest.TestCase): |
| 10 |
|
| 11 |
@unittest.skipIf('DISPLAY' not in os.environ, 'No $DISPLAY set.') |
| 12 |
def testLoadTk(self): |
| 13 |
tcl = Tcl() |
| 14 |
self.assertRaises(TclError,tcl.winfo_geometry) |
| 15 |
tcl.loadtk() |
| 16 |
self.assertEqual('1x1+0+0', tcl.winfo_geometry()) |
| 17 |
tcl.destroy() |
| 18 |
|
| 19 |
def testLoadTkFailure(self): |
| 20 |
old_display = None |
| 21 |
if sys.platform.startswith(('win', 'darwin', 'cygwin')): |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
return |
| 27 |
with test_support.EnvironmentVarGuard() as env: |
| 28 |
if 'DISPLAY' in os.environ: |
| 29 |
del env['DISPLAY'] |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
display = os.popen('echo $DISPLAY').read().strip() |
| 35 |
if display: |
| 36 |
return |
| 37 |
|
| 38 |
tcl = Tcl() |
| 39 |
self.assertRaises(TclError, tcl.winfo_geometry) |
| 40 |
self.assertRaises(TclError, tcl.loadtk) |
| 41 |
|
| 42 |
tests_gui = (TkLoadTest, ) |
| 43 |
|
| 44 |
if __name__ == "__main__": |
| 45 |
test_support.run_unittest(*tests_gui) |