Skip to content
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

CLN: Deprecate the edit parameter to configure_traits #1311

Merged
merged 14 commits into from
Oct 13, 2020
16 changes: 14 additions & 2 deletions traits/has_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ def configure_traits(
filename=None,
view=None,
kind=None,
edit=True,
edit=None,
context=None,
handler=None,
id="",
Expand Down Expand Up @@ -1980,7 +1980,6 @@ def configure_traits(
Parameters
----------
filename : str
NOTE: Deprecated as of traits 6.0.0.
The name (including path) of a file that contains a pickled
representation of the current object. When this parameter is
specified, the method reads the corresponding file (if it exists)
Expand All @@ -1989,6 +1988,9 @@ def configure_traits(
**OK**), the new values are written to the file. If this parameter
is not specified, the values are loaded from the in-memory object,
and are not persisted when the dialog box is closed.

.. deprecated:: 6.0.0

view : View or str
A View object (or its name) that defines a user interface for
editing trait attribute values of the current object. If the view
Expand All @@ -2006,6 +2008,9 @@ def configure_traits(
specifies an existing file, setting *edit* to False loads the
saved values from that file into the object without requiring
user interaction.

.. deprecated:: 6.2.0

context : object or dictionary
A single object or a dictionary of string/object pairs, whose trait
attributes are to be edited. If not specified, the current object
Expand Down Expand Up @@ -2034,6 +2039,13 @@ def configure_traits(
with open(filename, "rb") as fd:
self.copy_traits(pickle.Unpickler(fd).load())

if edit is None:
edit = True
else:
message = ('The edit argument to configure_traits is '
'deprecated, and will be removed in Traits 7.0.0')
warnings.warn(message, DeprecationWarning)

if edit:
from traitsui.api import toolkit

Expand Down
29 changes: 29 additions & 0 deletions traits/tests/test_configure_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import tempfile
import unittest
import unittest.mock as mock
import warnings

from traits.api import HasTraits, Int
from traits.testing.optional_dependencies import requires_traitsui, traitsui
Expand Down Expand Up @@ -126,3 +127,31 @@ def modify_model(*args, **kwargs):

self.assertIsInstance(unpickled, Model)
self.assertEqual(unpickled.count, model.count)

def test_edit_when_false(self):
# Check for deprecation warning when *edit* is false.
model = Model()
with mock.patch.object(self.toolkit, "view_application") as mock_view:
with self.assertWarns(DeprecationWarning):
model.configure_traits(edit=False)
mock_view.assert_not_called()

def test_edit_when_true(self):
# Check for deprecation warning when *edit* is false.
model = Model()
with mock.patch.object(self.toolkit, "view_application") as mock_view:
mock_view.return_value = True
with self.assertWarns(DeprecationWarning):
model.configure_traits(edit=True)
self.assertEqual(len(mock_view.mock_calls), 1)
mdickinson marked this conversation as resolved.
Show resolved Hide resolved

def test_edit_not_given(self):
# Normal case where the *edit* argument is not supplied.
model = Model()
with mock.patch.object(self.toolkit, "view_application") as mock_view:
mock_view.return_value = True
with warnings.catch_warnings(record=True) as captured_warnings:
warnings.simplefilter("always", DeprecationWarning)
model.configure_traits()
self.assertEqual(len(mock_view.mock_calls), 1)
self.assertEqual(len(captured_warnings), 0)