This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: tkinter.font.Font.measure() broken in 3.5
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: martin.panter, ned.deily, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2015-06-08 13:22 by martin.panter, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tkinter_test_font.patch serhiy.storchaka, 2015-06-08 15:46 review
families.patch martin.panter, 2015-06-20 03:54 review
Messages (12)
msg245003 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-06-08 13:22
>>> import tkinter, tkinter.font
>>> tk = tkinter.Tk()
>>> tkinter.font.nametofont("TkHeadingFont").measure("string")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/proj/python/cpython/Lib/tkinter/font.py", line 154, in measure
    return self._root.tk.getint(self._call("font", "measure", self.name, *args))
AttributeError: 'Font' object has no attribute '_root'

This appears to be broken by revision cb80dd82d3da, Issue 23880, which included this change at the end of the measure() method:

-return int(self._call("font", "measure", self.name, *args))
+return self._root.tk.getint(self._call("font", "measure", self.name, *args))

The Font class does not have a “_root” attribute.
msg245007 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-06-08 15:44
New changeset fb05c1355a90 by Serhiy Storchaka in branch '3.5':
Issue #24408: Fixed AttributeError in measure() and metrics() methods of
https://hg.python.org/cpython/rev/fb05c1355a90

New changeset 0dd70c2c44b4 by Serhiy Storchaka in branch 'default':
Issue #24408: Fixed AttributeError in measure() and metrics() methods of
https://hg.python.org/cpython/rev/0dd70c2c44b4
msg245008 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-06-08 15:46
Thank you for your report Martin. Unfortunately tests for tkinter.Font are almost not existing. Here is a patch that adds more tests (it should be applied to all versions).
msg245042 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-06-09 03:46
Thanks for the prompt fix!

The patch with the tests looks good. I left a query about the existing code.
msg245043 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-06-09 04:22
New changeset 7e2a7f3fecdf by Serhiy Storchaka in branch '3.4':
Issue #24408: Added more tkinter.Font tests.
https://hg.python.org/cpython/rev/7e2a7f3fecdf

New changeset 24bb564469b4 by Serhiy Storchaka in branch '3.5':
Issue #24408: Added more tkinter.Font tests.
https://hg.python.org/cpython/rev/24bb564469b4

New changeset 47f321ec69dc by Serhiy Storchaka in branch 'default':
Issue #24408: Added more tkinter.Font tests.
https://hg.python.org/cpython/rev/47f321ec69dc

New changeset ae1bc5b65e65 by Serhiy Storchaka in branch '2.7':
Issue #24408: Added more tkinter.Font tests.
https://hg.python.org/cpython/rev/ae1bc5b65e65
msg245147 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-06-10 22:28
Test fails on OS X (10.10) with Cocoa Tk 8.6(.4) and 8.5(.18):

======================================================================
FAIL: test_families (test_tkinter.test_font.FontTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/py/dev/27/root/fwd/Library/Frameworks/pytest_10.10.framework/Versions/2.7/lib/python2.7/lib-tk/test/test_tkinter/test_font.py", line 79, in test_families
    self.assertIn(self.font.actual('family'), families)
AssertionError: '.Helvetica Neue DeskInterface' not found in ('Academy Engraved LET', 'Al Bayan', 'Al Nile', 'Al Tarikh', 'American Typewriter', 'Andale Mono', 'Arial', 'Arial Black', 'Arial Hebrew', 'Arial Hebrew Scholar', 'Arial Narrow', 'Arial Rounded MT Bold', 'Arial Unicode MS', 'Athelas', 'Avenir', 'Avenir Next', 'Avenir Next Condensed', 'Ayuthaya', 'Baghdad', 'Bangla MN', 'Bangla Sangam MN', 'Bank Gothic', 'Baoli SC', 'Baskerville', 'Beirut', 'Big Caslon', 'Blackmoor LET', 'BlairMdITC TT', 'Bodoni 72', 'Bodoni 72 Oldstyle', 'Bodoni 72 Smallcaps', 'Bodoni Ornaments', 'Bordeaux Roman Bold LET', 'Bradley Hand', 'Brush Script MT', 'Capitals', 'Chalkboard', 'Chalkboard SE', 'Chalkduster', 'Charter', 'Cochin', 'Comic Sans MS', 'Copperplate', 'Corsiva Hebrew', 'Courier', 'Courier New', 'Damascus', 'DecoType Naskh', 'Devanagari MT', 'Devanagari Sangam MN', 'Didot', 'DIN Alternate', 'DIN Condensed', 'Diwan Kufi', 'Diwan Thuluth', 'Euphemia UCAS', 'Farah', 'Farisi', 'Futura', 'GB18030 Bitmap', 'Geeza Pro', 'Geneva', 'Georgia', 'Gill Sans', 'Gujarati MT', 'Gujarati Sangam MN', 'GungSeo', 'Gurmukhi MN', 'Gurmukhi MT', 'Gurmukhi Sangam MN', 'Hannotate SC', 'Hannotate TC', 'HanziPen SC', 'HanziPen TC', 'HeadLineA', 'Heiti SC', 'Heiti TC', 'Helvetica', 'Helvetica Neue', 'Herculanum', 'Hiragino Kaku Gothic Pro', [...]
msg245152 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-06-10 23:12
Some quick googling suggests this “.Helvetica Neue DeskInterface” font is real, and because it begins with a full stop it may be normally hidden from the normal list of fonts. Perhaps the test could be modified to just check the two functions separately:

* families() returns a non-trivial sequence of font names
* actual("family") returns a non-trivial string
msg245539 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-06-20 03:54
Here is a patch to decouple the families() and Font.actual("family") tests as I suggested. Ned, can you confirm if this works on the failing OS X setup? I expect it should be fine.
msg245590 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-06-21 11:44
New changeset 8e90f3ffa784 by Serhiy Storchaka in branch '2.7':
Issue #24408: Fixed test for tkinter.Font on OS X.
https://hg.python.org/cpython/rev/8e90f3ffa784

New changeset 014ee2df443a by Serhiy Storchaka in branch '3.4':
Issue #24408: Fixed test for tkinter.Font on OS X.
https://hg.python.org/cpython/rev/014ee2df443a

New changeset 5b037f934e40 by Serhiy Storchaka in branch '3.5':
Issue #24408: Fixed test for tkinter.Font on OS X.
https://hg.python.org/cpython/rev/5b037f934e40

New changeset 2d072d07dfe2 by Serhiy Storchaka in branch 'default':
Issue #24408: Fixed test for tkinter.Font on OS X.
https://hg.python.org/cpython/rev/2d072d07dfe2
msg245591 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-06-21 11:45
Thank you Ned and Martin.
msg245609 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-06-21 20:57
New changeset 20c9290a5de4 by Ned Deily in branch '2.7':
Issue #24408: Prevent test_font failures with non-ascii font names.
https://hg.python.org/cpython/rev/20c9290a5de4
msg245610 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-06-21 21:04
Thanks for the fix, Martin and Serhiy.  With Tk 8.4 on OS X, at least, it is possible to have non-ascii font names.  I extended the 2.7 test to account for that.
History
Date User Action Args
2022-04-11 14:58:17adminsetgithub: 68596
2015-06-21 21:04:26ned.deilysetmessages: + msg245610
versions: + Python 2.7
2015-06-21 20:57:58python-devsetmessages: + msg245609
2015-06-21 11:45:33serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg245591

stage: patch review -> resolved
2015-06-21 11:44:21python-devsetmessages: + msg245590
2015-06-20 03:54:58martin.pantersetfiles: + families.patch

messages: + msg245539
stage: needs patch -> patch review
2015-06-10 23:12:08martin.pantersetmessages: + msg245152
2015-06-10 22:28:19ned.deilysetstatus: closed -> open

nosy: + ned.deily
messages: + msg245147

resolution: fixed -> (no value)
stage: resolved -> needs patch
2015-06-09 04:28:02serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2015-06-09 04:22:03python-devsetmessages: + msg245043
2015-06-09 03:46:34martin.pantersetmessages: + msg245042
2015-06-08 15:46:59serhiy.storchakasetfiles: + tkinter_test_font.patch
keywords: + patch
messages: + msg245008

stage: needs patch -> patch review
2015-06-08 15:44:58python-devsetnosy: + python-dev
messages: + msg245007
2015-06-08 15:44:07serhiy.storchakasetassignee: serhiy.storchaka
2015-06-08 13:22:17martin.pantercreate