-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-24813: IDLE: Add bitness to About Idle title #2380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,23 @@ | |
|
||
""" | ||
import os | ||
from platform import python_version | ||
import sys | ||
from platform import python_version, architecture | ||
|
||
from tkinter import Toplevel, Frame, Label, Button, PhotoImage | ||
from tkinter import SUNKEN, TOP, BOTTOM, LEFT, X, BOTH, W, EW, NSEW, E | ||
|
||
from idlelib import textview | ||
|
||
|
||
def _bitness(): | ||
"Return bitness of platform." | ||
bits, linkage = architecture() | ||
if sys.platform == 'darwin': | ||
bits = '64bit' if sys.maxsize > 2**32 else '32bit' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I guess I prefer multiple crisp returns to multiple assignments used to make a delayed return. I do understand the single exit idea from the Structured Programming revolution of the 1970s. 'Single exit' replaced multiple unrestricted GOTOs. A return is a very disciplined goto. Since I have 64 bit installs and 32 bit clone debug builds, I tested and confirmed that the return on windows really is build bits and, in spite of the name, not physical architecture bits. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. concur with @terryjreedy 's method and name of the function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is much better, thank you. |
||
return bits[:2] | ||
|
||
|
||
class AboutDialog(Toplevel): | ||
"""Modal about dialog for idle | ||
|
||
|
@@ -28,11 +37,12 @@ def __init__(self, parent, title=None, _htest=False, _utest=False): | |
self.geometry("+%d+%d" % ( | ||
parent.winfo_rootx()+30, | ||
parent.winfo_rooty()+(30 if not _htest else 100))) | ||
self.bg = "#707070" | ||
self.fg = "#ffffff" | ||
self.bg = "#bbbbbb" | ||
self.fg = "#000000" | ||
self.create_widgets() | ||
self.resizable(height=False, width=False) | ||
self.title(title or f'About IDLE {python_version()}') | ||
self.title(title or | ||
f'About IDLE {python_version()} ({_bitness()} bit)') | ||
self.transient(parent) | ||
self.grab_set() | ||
self.protocol("WM_DELETE_WINDOW", self.ok) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,15 @@ | |
from test.support import requires, findfile | ||
from tkinter import Tk, TclError | ||
import unittest | ||
from unittest import mock | ||
from idlelib.idle_test.mock_idle import Func | ||
from idlelib.idle_test.mock_tk import Mbox_func | ||
from idlelib.help_about import AboutDialog as About | ||
from idlelib import help_about | ||
from idlelib import textview | ||
import os.path | ||
from platform import python_version | ||
from platform import python_version, architecture | ||
|
||
|
||
class LiveDialogTest(unittest.TestCase): | ||
"""Simulate user clicking buttons other than [Close]. | ||
|
@@ -88,18 +91,21 @@ def setUpClass(cls): | |
requires('gui') | ||
cls.root = Tk() | ||
cls.root.withdraw() | ||
help_about._bitness = mock.Mock(return_value=42) | ||
cls.dialog = About(cls.root, _utest=True) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
del cls.dialog | ||
del cls.dialog, help_about._bitness | ||
cls.root.update_idletasks() | ||
cls.root.destroy() | ||
del cls.root | ||
|
||
def test_dialog_title(self): | ||
"""Test about dialog title""" | ||
self.assertEqual(self.dialog.title(), f'About IDLE {python_version()}') | ||
self.assertEqual(self.dialog.title(), | ||
f'About IDLE {python_version()}' | ||
f' (42 bit)') | ||
|
||
|
||
class CloseTest(unittest.TestCase): | ||
|
@@ -170,5 +176,37 @@ def test_file_display(self): | |
self.assertEqual(self.view.called, True) | ||
|
||
|
||
class BitnessTest(unittest.TestCase): | ||
"Test helper function for bitness of system." | ||
|
||
def test_darwin(self): | ||
help_about.sys = mock.MagicMock() | ||
platform = mock.PropertyMock(return_value='darwin') | ||
size = mock.PropertyMock(return_value=2**32) | ||
type(help_about.sys).platform = platform | ||
type(help_about.sys).maxsize = size | ||
help_about.architecture = mock.Mock(return_value=('64bit', 'ELF')) | ||
self.assertEqual(help_about._bitness(), '32') | ||
platform.assert_called_with() | ||
size.assert_called_with() | ||
|
||
size = mock.PropertyMock(return_value=2**64) | ||
type(help_about.sys).maxsize = size | ||
self.assertEqual(help_about._bitness(), '64') | ||
platform.assert_called_with() | ||
size.assert_called_with() | ||
|
||
def test_not_darwin(self): | ||
help_about.sys = mock.MagicMock() | ||
platform = mock.PropertyMock(return_value='linux') | ||
size = mock.PropertyMock(return_value=2**32) | ||
type(help_about.sys).platform = platform | ||
type(help_about.sys).maxsize = size | ||
help_about.architecture = mock.Mock(return_value=('64bit', 'ELF')) | ||
self.assertEqual(help_about._bitness(), '64') | ||
platform.assert_called_with() | ||
size.assert_not_called() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have decided that these tests are way too much for something that almost does
8000
not need to be tested. Testing that the implementation is what we can see it is by reading the code is not very useful, though a common mistake. If the implementation is wrong, it is wrong. Reduce this to testing what we know must be true if there is no bug. Put is some current class. Rename if needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I thought I needed to test each branch of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If build bits were a real function, I would want to to try to hit all branches. And if we otherwise get to to 99'% coverage, I might want to do so, but it would be artificial. On Macs, the value of sys.architecture seems undefined, which is why it is not used. (Or I might just note that 99% is 100% of what is sensibly possible on any one system. ;-) Read something about 'unit testing', such as parts of https://en.wikipedia.org/wiki/Unit_testing and 'test-driven development', such as the first half of https://en.wikipedia.org/wiki/Test-driven_development. There is clearly overlap. Keep in mind that both topics are subjects of programming religion. |
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main(verbosity=2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def build_bits():