GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-151678: Add tests for tkinter.scrolledtext (GH-151753) · python/cpython@639265f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Lib/test/test_tkinter
    • test_scrolledtext.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Lib/test/test_tkinter/test_scrolledtext.py‎

Copy file name to clipboard
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import unittest
2+
import tkinter
3+
from tkinter.scrolledtext import ScrolledText
4+
from test.support import requires
5+
from test.test_tkinter.support import setUpModule # noqa: F401
6+
from test.test_tkinter.support import AbstractTkTest
7+
8+
requires('gui')
9+
10+
11+
class ScrolledTextTest(AbstractTkTest, unittest.TestCase):
12+
13+
def create(self, **kwargs):
14+
st = ScrolledText(self.root, **kwargs)
15+
self.addCleanup(st.destroy)
16+
return st
17+
18+
def test_create(self):
19+
st = self.create(background='red', height=5)
20+
# It is a Text widget held in a Frame together with a Scrollbar.
21+
self.assertIsInstance(st, tkinter.Text)
22+
self.assertIsInstance(st.frame, tkinter.Frame)
23+
self.assertIsInstance(st.vbar, tkinter.Scrollbar)
24+
self.assertEqual(st.winfo_parent(), str(st.frame))
25+
# str() returns the frame, so that geometry managers manage it.
26+
self.assertEqual(str(st), str(st.frame))
27+
# Keyword options configure the Text.
28+
self.assertEqual(str(st['background']), 'red')
29+
self.assertEqual(st['height'], 5 if self.wantobjects else '5')
30+
31+
def test_text_methods(self):
32+
st = self.create()
33+
st.insert('1.0', 'hello\nworld')
34+
self.assertEqual(st.get('1.0', 'end-1c'), 'hello\nworld')
35+
self.assertEqual(st.index('end-1c'), '2.5')
36+
st.delete('1.0', 'end')
37+
self.assertEqual(st.get('1.0', 'end-1c'), '')
38+
39+
def test_geometry_methods(self):
40+
st = self.create()
41+
# configure is not redirected; it configures the Text.
42+
st.configure(height=8)
43+
self.assertEqual(st['height'], 8 if self.wantobjects else '8')
44+
# Pack, Grid and Place methods are redirected to the frame.
45+
st.pack()
46+
self.root.update()
47+
self.assertEqual(st.frame.winfo_manager(), 'pack')
48+
self.assertEqual(st.pack_info(), st.frame.pack_info())
49+
st.pack_forget()
50+
self.assertEqual(st.frame.winfo_manager(), '')
51+
52+
def test_scrollbar(self):
53+
st = self.create(height=5)
54+
st.pack()
55+
st.insert('1.0', '\n'.join(map(str, range(100))))
56+
self.root.update()
57+
# The scrollbar tracks the text view.
58+
self.assertEqual(st.vbar.get(), st.yview())
59+
st.yview_moveto(1.0)
60+
self.root.update()
61+
self.assertEqual(st.vbar.get()[1], 1.0)
62+
63+
64+
if __name__ == "__main__":
65+
unittest.main()

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.