Skip to content

Commit

Permalink
CLN: Deprecate the edit parameter to configure_traits (#1311)
Browse files Browse the repository at this point in the history
* deprecated edit argument to configure_traits

* Check for deprecation warning

* fixed edit arg deprecation

* fix flake8 error

* fix docstring markup error

* fix explicit markup error for docs

* remove blankspace

* added spaces and refcatored

* refactor again

* Expand tests slightly, add explicit test for case where edit not passed

* Fix logic for deprecated 'edit' keyword

* Use assert_called_once; be consistent about mock return value

* Fix indentation

Co-authored-by: avats-dev <avats.osc@gmail.com>
  • Loading branch information
mdickinson and avats-dev authored Oct 13, 2020
1 parent a9dc7cf commit ef732ca
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
18 changes: 16 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,15 @@ 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
30 changes: 30 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,32 @@ 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:
mock_view.return_value = True
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)
mock_view.assert_called_once()

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()
mock_view.assert_called_once()
self.assertEqual(len(captured_warnings), 0)

0 comments on commit ef732ca

Please sign in to comment.