Skip to content

bpo-30779: IDLE -- Factor ConfigChanges class from configdialog, put in config; test. #2612

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

Merged
merged 15 commits into from
Jul 7, 2017

Conversation

terryjreedy
Copy link
Member

No description provided.

@mention-bot
Copy link

@terryjreedy, thanks for your PR! By analyzing the history of the files in this pull request, we identified @csabella, @asvetlov and @kbkaiser to be potential reviewers.

Copy link
Contributor

@mlouielu mlouielu left a comment

Choose a reason for hiding this comment

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

Some method name need to consider to changed.

configpage.remove_section(section)
configpage.Save()


Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove one blank line

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I appreciate the review. Polishing a patch is really hard.

value -- value for the item.

Methods
add_item:
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you prefer to use add_item in above changes? Current code is using additem.

Copy link
Member Author

@terryjreedy terryjreedy Jul 7, 2017

Choose a reason for hiding this comment

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

After reviewing configparser parameters, changed to add_option. Will have to change all in test and configdialog and check its tests.


Methods
add_item:
save_all: Save all the changes to the config file.
Copy link
Contributor

@mlouielu mlouielu Jul 7, 2017

Choose a reason for hiding this comment

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

Need to add set_value document (will dev use this method alone?)

page[section][item] = value

@staticmethod
def set_value(config_type, section, item, value):
Copy link
Contributor

Choose a reason for hiding this comment

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

How about using save_item for consistency?

Copy link
Member Author

@terryjreedy terryjreedy Jul 7, 2017

Choose a reason for hiding this comment

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

save_option for consistency with add_option and save_all ;-). Only called in save_all,and twice in tests.

for config_type in ['keys', 'highlight']:
# Save these even if unchanged!
idleConf.userCfg[config_type].Save()
self.clear()
Copy link
Contributor

@mlouielu mlouielu Jul 7, 2017

Choose a reason for hiding this comment

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

Should the result be clear after save_all?
If should, then the docstring need to note it.

But I think it should not clear after save_all, this should let dev to do when needed

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, it should be clear after save_all, that mean the changed has been apply. Maybe this side-affect need to be documented.

Copy link
Member Author

@terryjreedy terryjreedy Jul 7, 2017

Choose a reason for hiding this comment

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

By our current standard, yes. Changed.

@@ -44,7 +40,7 @@ def setUpModule():

def tearDownModule():
global root, configure
idleConf.userCfg = testcfg
idleConf.userCfg = usercfg
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should rebase/merge master branch since this changed has been merged into via PR #2606.

Copy link
Member Author

Choose a reason for hiding this comment

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

I though maybe I branched after fetching that. Anyway, I fetched again, pushed master to origin, and
ran <git merge origin/master>, from the devguide, which has worked before. and pushed.
... Above -+ is gone from new diff.

def __init__(self):
"Create a page for each configuration file"
self.pages = [] # List of unhashable dicts.
for config_type in ('main', 'highlight', 'keys', 'extensions'):
Copy link
Contributor

Choose a reason for hiding this comment

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

Question on the tuple ('main', 'highlight', 'keys', 'extensions')

This is in the IdleConf.__init__:
self.config_types = ('main', 'extensions', 'highlight', 'keys')

Any benefit to making that a module constant?

Copy link
Member Author

Choose a reason for hiding this comment

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

I left it as idleConf attribute and used the attribute here to eliminate the duplication. Good catch.

if section not in self.changed_items[typ]:
self.changed_items[typ][section] = {}
self.changed_items[typ][section][item] = value
changes.add_option('main', 'EditorWindow', 'encoding', value)

def GetDefaultItems(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't find GetDefaultItems used anywhere. Should it be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I grepped the file for 'default' to make sure you had not changed the name elsewhere to somethingdefaultsomething. 55 hit, not orphan function call. My guess is that someone wrote this, possibly for the check in save_option, and someone (same or other) decided to stick with idleConf instead of the skeletal duplicate, but did not remove.

I removed it in a separate commit.


def add_option(self, config_type, section, item, value):
"Add item/value pair for config_type and section."
page = self[config_type]
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know if we needed to add a check for config_type to make sure it's valid before accessing it.

Copy link
Member Author

@terryjreedy terryjreedy Jul 7, 2017

Choose a reason for hiding this comment

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

What would add_option do if it did? It expects new sections. New config-types are a bug. A test of the user, config dialog, should fail. General principle: only check first or catch after if one has an alternative action in mind that is better than letting an exception bubble up.


def test_clear(self):
changes = self.load()
changes.clear()
Copy link
Member Author

Choose a reason for hiding this comment

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

Test_add_option verifies that load loads something. I added a comment to def load...

@python python deleted a comment from csabella Jul 7, 2017
@terryjreedy terryjreedy merged commit 349abd9 into python:master Jul 7, 2017
@terryjreedy terryjreedy deleted the cf branch July 7, 2017 20:01
terryjreedy added a commit to terryjreedy/cpython that referenced this pull request Jul 7, 2017
…, put in config; test. (pythonGH-2612)

* In config, put dump test code in a function; run it and unittest in 'if __name__ == '__main__'.
* Add class config.ConfigChanges based on changes_class_v4.py on bpo issue.
* Add class test_config.ChangesTest, partly based on configdialog_tests_v1.py on bpo issue.
* Revise configdialog to use ConfigChanges, mostly as specified in tracker msg297804.
* Revise test_configdialog to match configdialog changes.  All tests pass in both files.
* Remove configdialog functions unused or moved to ConfigChanges.
Cheryl Sabella contributed parts of the patch.
(cherry picked from commit 349abd9)
terryjreedy added a commit that referenced this pull request Jul 7, 2017
…, put in config; test. (GH-2612) (#2625)

* In config, put dump test code in a function; run it and unittest in 'if __name__ == '__main__'.
* Add class config.ConfigChanges based on changes_class_v4.py on bpo issue.
* Add class test_config.ChangesTest, partly based on configdialog_tests_v1.py on bpo issue.
* Revise configdialog to use ConfigChanges, mostly as specified in tracker msg297804.
* Revise test_configdialog to match configdialog changes.  All tests pass in both files.
* Remove configdialog functions unused or moved to ConfigChanges.
Cheryl Sabella contributed parts of the patch.
(cherry picked from commit 349abd9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants