PNG  IHDR  8] PLTE S =tRNS   PNG  IHDR  8] PLTE S =tRNS   REDROOM
PHP 7.4.33
Preview: test_widgetredir.py Size: 4.08 KB
//opt/alt/python27/lib64/python2.7/idlelib/idle_test/test_widgetredir.py

"""Unittest for idlelib.WidgetRedirector

100% coverage
"""
from test.test_support import requires
import unittest
from idlelib.idle_test.mock_idle import Func
from Tkinter import Tk, Text, TclError
from idlelib.WidgetRedirector import WidgetRedirector


class InitCloseTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        requires('gui')
        cls.root = Tk()
        cls.root.withdraw()
        cls.text = Text(cls.root)

    @classmethod
    def tearDownClass(cls):
        del cls.text
        cls.root.destroy()
        del cls.root

    def test_init(self):
        redir = WidgetRedirector(self.text)
        self.assertEqual(redir.widget, self.text)
        self.assertEqual(redir.tk, self.text.tk)
        self.assertRaises(TclError, WidgetRedirector, self.text)
        redir.close()  # restore self.tk, self.text

    def test_close(self):
        redir = WidgetRedirector(self.text)
        redir.register('insert', Func)
        redir.close()
        self.assertEqual(redir._operations, {})
        self.assertFalse(hasattr(self.text, 'widget'))


class WidgetRedirectorTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        requires('gui')
        cls.root = Tk()
        cls.root.withdraw()
        cls.text = Text(cls.root)

    @classmethod
    def tearDownClass(cls):
        del cls.text
        cls.root.destroy()
        del cls.root

    def setUp(self):
        self.redir = WidgetRedirector(self.text)
        self.func = Func()
        self.orig_insert = self.redir.register('insert', self.func)
        self.text.insert('insert', 'asdf')  # leaves self.text empty

    def tearDown(self):
        self.text.delete('1.0', 'end')
        self.redir.close()

    def test_repr(self):  # partly for 100% coverage
        self.assertIn('Redirector', repr(self.redir))
        self.assertIn('Original', repr(self.orig_insert))

    def test_register(self):
        self.assertEqual(self.text.get('1.0', 'end'), '\n')
        self.assertEqual(self.func.args, ('insert', 'asdf'))
        self.assertIn('insert', self.redir._operations)
        self.assertIn('insert', self.text.__dict__)
        self.assertEqual(self.text.insert, self.func)

    def test_original_command(self):
        self.assertEqual(self.orig_insert.operation, 'insert')
        self.assertEqual(self.orig_insert.tk_call, self.text.tk.call)
        self.orig_insert('insert', 'asdf')
        self.assertEqual(self.text.get('1.0', 'end'), 'asdf\n')

    def test_unregister(self):
        self.assertIsNone(self.redir.unregister('invalid operation name'))
        self.assertEqual(self.redir.unregister('insert'), self.func)
        self.assertNotIn('insert', self.redir._operations)
        self.assertNotIn('insert', self.text.__dict__)

    def test_unregister_no_attribute(self):
        del self.text.insert
        self.assertEqual(self.redir.unregister('insert'), self.func)

    def test_dispatch_intercept(self):
        self.func.__init__(True)
        self.assertTrue(self.redir.dispatch('insert', False))
        self.assertFalse(self.func.args[0])

    def test_dispatch_bypass(self):
        self.orig_insert('insert', 'asdf')
        # tk.call returns '' where Python would return None
        self.assertEqual(self.redir.dispatch('delete', '1.0', 'end'), '')
        self.assertEqual(self.text.get('1.0', 'end'), '\n')

    def test_dispatch_error(self):
        self.func.__init__(TclError())
        self.assertEqual(self.redir.dispatch('insert', False), '')
        self.assertEqual(self.redir.dispatch('invalid'), '')

    def test_command_dispatch(self):
        # Test that .__init__ causes redirection of tk calls
        # through redir.dispatch
        self.root.call(self.text._w, 'insert', 'hello')
        self.assertEqual(self.func.args, ('hello',))
        self.assertEqual(self.text.get('1.0', 'end'), '\n')
        # Ensure that called through redir .dispatch and not through
        # self.text.insert by having mock raise TclError.
        self.func.__init__(TclError())
        self.assertEqual(self.root.call(self.text._w, 'insert', 'boo'), '')



if __name__ == '__main__':
    unittest.main(verbosity=2)

Directory Contents

Dirs: 0 × Files: 79

Name Size Perms Modified Actions
13.46 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
12.36 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
12.36 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
1.56 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
2.94 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
2.94 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
11.30 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
12.42 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
12.42 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
5.36 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
4.81 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
5.98 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
5.98 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
4.03 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
4.85 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
4.85 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
6.97 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
12.47 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
12.47 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
782 B lrw-r--r-- 2025-01-08 10:53:54
Edit Download
1.68 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
1.68 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
2.41 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
4.08 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
4.08 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
1.26 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
1.33 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
1.33 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
3.09 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
4.46 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
4.46 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
14.01 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
14.36 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
14.36 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
2.70 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
3.81 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
3.81 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
1.57 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
2.38 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
2.38 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
5.55 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
6.78 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
6.78 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
5.37 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
8.28 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
8.28 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
9.28 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
11.67 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
11.67 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
3.73 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
5.53 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
5.53 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
940 B lrw-r--r-- 2025-01-08 10:53:53
Edit Download
1.50 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
1.50 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
1.58 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
1.78 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
1.78 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
5.73 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
6.87 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
6.87 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
11.22 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
12.81 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
12.81 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
6.59 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
8.20 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
8.20 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
2.74 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
4.60 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
4.60 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
2.69 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
3.31 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
3.31 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
4.08 KB lrw-r--r-- 2025-01-08 10:53:54
Edit Download
6.49 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
6.49 KB lrw-r--r-- 2025-01-08 10:53:53
Edit Download
650 B lrw-r--r-- 2025-01-08 10:53:53
Edit Download
941 B lrw-r--r-- 2025-01-08 10:53:54
Edit Download
941 B lrw-r--r-- 2025-01-08 10:53:54
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).
 !"#$%&'(()*+,-./00123456789 t\ wIDATx ]ys  47Y ƒ -  "  Rv  < f{Ɛ $k l L > L  ~h^ 1  [  r G t& h  l F z3O Y ! p A(_g̷ E8 )S 8 c  Kb"z ~ 5 J xAL WU <  *  5 m;W a pB h ~P J 2 3 6 ҙ .Ƹ P i  4g F R L P ΪK/D  M v (a3 k J Œ4N5* SH ` SdJ z  O J Xՠ V>u ߱ BE&L b2 ?2` tX+  c CB A$ i b C ĀMB E : /  # Dx &l =q Ty  0 \p I ( L Ǎ { e 4k ;`u^ヲ eP!( d {  )T A 8 O;Ě n >;s6 !  :Nx `[S D HU ~ q›J F} a g*D 49 / pn k h (t 8NxƐF _!r չ7 ZR R׷ q/5") Ӎ NY 0 x sZ!   o  fu  ,  K"$ ? pg  㕣=  1» {h " fh7    y  } € +7  $ y " X —ą - G P u 4 m >J 5 L =V ' ^@I p ?MS xЌ XV P ! h "C NS9B8̢ ]!K  e   zA , ӏkbY  !< XQ ٿyS| *" f { w  4@[S <  # 0 ! js [m  =,~ o "ݎ DHf Wo $ g ! Vԅ t mB /y Wf V4񺍸 c+@x?  B ~u " xUN e 0 BĂ) ~J pz! 7y6]l Ԥ@ P a< O /DHC `≻  N m"$  0ObB }{ x AO FCG D R ^ "B  { WDH  UR l@ T #  +"d T ; 0 i  D}. 7 ` ' ] w rE &S i ƕiTD EL P _ u h $ Ա FG wVD G L R Zf ' .!] J /ZR oGЍs Mr Ĥ ʬ 3 Q [3 cL ` ^ p + ( F;# B 5 '  2Y f [  ϶R0e }  E 7 6M aۮ H <& n % L] E}Up x紉, Uw' Q  Ǯշo k ވۙ 0N94 VX5 xEDE l D #֤ } C o )W :  ^ s 9  bRf iX5u ཱི 4 :[  T 1. | [E 2ؽ Iy\ : o x K G 5 ylP ' uK E ftb/i[3 .g _  [3M n G, #NwQ5~  ؚ) | n =Ц"x qg gB ` 듘 ~ x w ? ? R~  _ u. &VQ K˻   H C ( TN˄+ `C dA nB׭ D 3"Z G ê ^k H_ /- ~ " R_  .8 Z_ 6@ o  xg  uP ? 3լ @7AM!  E7^ - =V L  x  g-D0  CtmW 7  O  G _ WD0 g C  w1 r d w : a | \  *" f nֳ ^ H# f L ` Z ۽hV  }S F r0Ù Bć5r] @! NL iQ]{s^=4 d  WD  "  "   M; t" 8 5 e dL| "-*st" ) SWD ?R[S e ooF  20.D ? bo =) A i o d ģ ZҰaO @E =) i D a &ܟa CϞ y6 ,<%{^x%{f8? `iw^ ?/ M * IEND B`