Skip to content

Commit

Permalink
Remove deleter for the kiva_backend property (which is readonly) (#1686)
Browse files Browse the repository at this point in the history
PR #1670 added deleters for various ETSConfig attributes. However, the kiva_backend property is readonly, with value derived from the toolkit attribute, so we shouldn't be providing a deleter for it. The right way to mock kiva_backend is to set the toolkit attribute (and in fact there's already a test for that).

This PR removes the deleter for the kiva_backend attribute, and makes the `kiva_backend` property getter a pure function with no caching.
  • Loading branch information
mdickinson committed Aug 9, 2022
1 parent 2da657b commit aa05dc6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
25 changes: 6 additions & 19 deletions traits/etsconfig/etsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,25 +321,12 @@ def kiva_backend(self):
"which has not been set."
)

if self._kiva_backend is None:
try:
self._kiva_backend = self._toolkit.split(".")[1]
except IndexError:
# Pick a reasonable default based on the toolkit
if self.toolkit == "wx":
self._kiva_backend = (
"quartz" if sys.platform == "darwin" else "image"
)
elif self.toolkit in ["qt4", "qt"]:
self._kiva_backend = "image"
else:
self._kiva_backend = "image"

return self._kiva_backend

@kiva_backend.deleter
def kiva_backend(self):
self._kiva_backend = None
if "." in self._toolkit:
return self._toolkit.split(".")[1]
elif self.toolkit == "wx" and sys.platform == "darwin":
return "quartz"
else:
return "image"

@property
def user_data(self):
Expand Down
8 changes: 4 additions & 4 deletions traits/etsconfig/tests/test_etsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,13 @@ def test_toolkit_explicit_kiva_backend(self):
self.ETSConfig.toolkit = "wx.celiagg"
self.assertEqual(self.ETSConfig.kiva_backend, "celiagg")

def test_delete_kiva_backend(self):
# given
def test_toolkit_kiva_backend_changes_when_toolkit_changed(self):
self.ETSConfig.toolkit = "wx.celiagg"
self.assertEqual(self.ETSConfig.kiva_backend, "celiagg")
del self.ETSConfig.toolkit

# check that the property can be deleted
del self.ETSConfig.kiva_backend
self.ETSConfig.toolkit = "wx.quartz"
self.assertEqual(self.ETSConfig.kiva_backend, "quartz")

def test_mock_kiva_backend(self):
# when
Expand Down

0 comments on commit aa05dc6

Please sign in to comment.