Skip to content

Commit

Permalink
Add test and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
roomrys committed Mar 31, 2023
1 parent 0aa324c commit 23791fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions sleap/gui/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def toggle(self, key: GSVarType, default: bool = False):
"""Toggle boolean value for specified key."""
self[key] = not self.get(key, default=default)

def increment(self, key: GSVarType, step: int = 1, mod: Optional[int] = None, default: int = 0):
def increment(
self, key: GSVarType, step: int = 1, mod: Optional[int] = None, default: int = 0
):
"""Increment numeric value for specified key.
Args:
Expand All @@ -98,7 +100,7 @@ def increment(self, key: GSVarType, step: int = 1, mod: Optional[int] = None, de
if key not in self._state_vars:
self[key] = default
return

new_value = self.get(key) + step

# Wrap the value if it's out of bounds.
Expand Down
7 changes: 6 additions & 1 deletion tests/gui/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ def set_y_from_val_param_callback(x):
assert times_x_changed == 4
assert state["x"] == 2

# Test incrementing value with modulus of 1
state.increment("x", mod=1)
assert times_x_changed == 5
assert state["x"] == 0

# test emitting callbacks without changing value
state.emit("x")
assert times_x_changed == 5
assert times_x_changed == 6


def test_gui_state_bool():
Expand Down

0 comments on commit 23791fc

Please sign in to comment.