Skip to content

Commit

Permalink
Core tests converted to Pytest, with 100% coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Jun 19, 2023
1 parent 932efb0 commit 58bdf2e
Show file tree
Hide file tree
Showing 7 changed files with 466 additions and 358 deletions.
2 changes: 1 addition & 1 deletion changes/1996.removal.2.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
``OptionContainer.add()`` has been renamed ``OptionContainer.append()`` for consistency with List APIs.
``OptionContainer.add()``, ``OptionContainer.remove()`` and ``OptionContainer.insert()`` have been removed, due to being ambiguous with base widget methods of the same name. Use the ``OptionContainer.content.append()``, ``OptionContainer.content.remove()`` and ``OptionContainer.content.insert()`` APIs instead.
5 changes: 0 additions & 5 deletions core/src/toga/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,11 @@ def refresh(self):
# defer the refresh call to the root node.
self._root.refresh()
else:
self.refresh_sublayouts()
# We can't compute a layout until we have a viewport
if self._impl.viewport:
super().refresh(self._impl.viewport)
self._impl.viewport.refreshed()

def refresh_sublayouts(self):
for child in self.children:
child.refresh_sublayouts()

def focus(self):
"""Give this widget the input focus.
Expand Down
54 changes: 7 additions & 47 deletions core/src/toga/widgets/optioncontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ def content(self) -> Widget:
"""The content widget displayed in this tab of the OptionContainer."""
return self._content

def refresh(self):
self._content.refresh()


class OptionList:
def __init__(self, interface):
Expand Down Expand Up @@ -171,7 +168,7 @@ def insert(
# The option now exists on the implementation;
# finalize the display properties that can't be resolved until the
# implementation exists.
widget.refresh()
self.interface.refresh()
item.enabled = enabled


Expand Down Expand Up @@ -203,7 +200,7 @@ def __init__(

if content:
for text, widget in content:
self.append(text, widget)
self.content.append(text, widget)

self.on_select = on_select

Expand Down Expand Up @@ -231,18 +228,11 @@ def content(self) -> OptionList:

@property
def current_tab(self) -> OptionItem:
"""The currently selected item of content.
When setting the current item, you can use:
* The integer index of the item
* An OptionItem reference
* The string label of the item. The first item whose label matches
will be selected.
"""
return self._content[self._impl.get_current_tab_index()]
"""The currently selected tab of content."""
index = self._impl.get_current_tab_index()
if index is None:
return None
return self._content[index]

@current_tab.setter
def current_tab(self, value):
Expand All @@ -267,36 +257,6 @@ def window(self, window):
for item in self._content:
item._content.window = window

def append(self, text: str, widget: Widget):
"""Append a new tab of content to the OptionContainer.
:param text: The text label for the new tab
:param widget: The content widget to use for the new tab.
"""
self._content.append(text, widget)

def insert(self, index: int | str | OptionItem, text: str, widget: Widget):
"""Insert a new tab of content to the OptionContainer at the specified index.
:param index: The index where the new item should be inserted (or a specifier
that can be converted into an index).
:param text: The text label for the new tab.
:param widget: The content widget to use for the new tab.
"""
self._content.insert(index, text, widget)

def remove(self, item: int | str | OptionItem):
"""Remove a tab of content from the OptionContainer.
:param item: The tab of content to remove.
"""
self._content.remove(item)

def refresh_sublayouts(self):
"""Refresh the layout and appearance of this widget."""
for widget in self._content:
widget.refresh()

@property
def on_select(self) -> callable:
"""The callback to invoke when a new tab of content is selected."""
Expand Down
Loading

0 comments on commit 58bdf2e

Please sign in to comment.