Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions 27 Lib/idlelib/idle_test/test_squeezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collections import namedtuple
from textwrap import dedent
from tkinter import Text, Tk
from tkinter.font import Font
import unittest
from unittest.mock import Mock, NonCallableMagicMock, patch, sentinel, ANY
from test.support import requires
Expand All @@ -18,6 +19,15 @@

SENTINEL_VALUE = sentinel.SENTINEL_VALUE

def get_font_family():
Comment thread
terryjreedy marked this conversation as resolved.
"If gui allowed, get name of font family guaranteed to exist."
requires('gui')
root = Tk()
root.withdraw()
f = Font(name='TkFixedFont', exists=True, root=root)
actualFont = Font.actual(f)
root.destroy()
return actualFont['family']

def get_test_tk_root(test_instance):
"""Helper for tests: Create a root Tk object."""
Expand Down Expand Up @@ -82,6 +92,15 @@ def test_several_lines_different_lengths(self):

class SqueezerTest(unittest.TestCase):
"""Tests for the Squeezer class."""

@classmethod
def setUpClass(cls):
cls.font_family = get_font_family()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also just be a global constant, i.e. set FIXED_WIDTH_FONT_FAMILY = get_font_family().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would have to be wrapped in try...except SkipTest... to avoid skipping all non-gui tests. As it is, the current line needs the same to avoid skipping non-gui tests within SqueezerTest. But, looking ahead, I want to split SqueezerTest into SqueezerGuiTest and SqueezerNoGuiTest and move root creation into the GUI class setUpClass. (This should also make it faster.)


@classmethod
def tearDownClass(cls):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unnecessary.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably true -- at the moment. But this will be needed if root is created in setUpClass.

del cls.font_family

def tearDown(self):
# Clean up the Squeezer class's reference to its instance,
# to avoid side-effects from one test case upon another.
Expand Down Expand Up @@ -114,7 +133,7 @@ def make_text_widget(self, root=None):
if root is None:
root = get_test_tk_root(self)
text_widget = Text(root)
text_widget["font"] = ('Courier', 10)
text_widget["font"] = (self.font_family, 10)
text_widget.mark_set("iomark", "1.0")
return text_widget

Expand Down Expand Up @@ -300,16 +319,14 @@ def test_reload(self):
orig_auto_squeeze_min_lines = squeezer.auto_squeeze_min_lines

# Increase both font size and auto-squeeze-min-lines.
text_widget["font"] = ('Courier', 20)
text_widget["font"] = (self.font_family, 20)
new_auto_squeeze_min_lines = orig_auto_squeeze_min_lines + 10
self.set_idleconf_option_with_cleanup(
'main', 'PyShell', 'auto-squeeze-min-lines',
str(new_auto_squeeze_min_lines))

Squeezer.reload()
# The following failed on Gentoo buildbots. Issue title will be
# IDLE: Fix squeezer test_reload.
#self.assertGreater(squeezer.zero_char_width, orig_zero_char_width)
self.assertGreater(squeezer.zero_char_width, orig_zero_char_width)
self.assertEqual(squeezer.auto_squeeze_min_lines,
new_auto_squeeze_min_lines)

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.