Visitar URL original
Fix SkeletonBuilder initialization from GUI by C-Achard · Pull Request #3380 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Promote SkeletonBuilder defaults to class attrs
Move UI/usage parameters (lasso_select_size, clear/export button axes/text, ampl) from __init__ to class-level attributes in deeplabcut/utils/skeleton.py so they become shared defaults rather than instance-only values.

Update tests in tests/utils/test_skeleton.py: attach_fake_canvas now creates an _ax on the Figure and sets its x/y limits to ensure plotting code has an axes to operate on; test_export_sorts_pairs_and_warns_for_unconnected now uses the caplog fixture (caplog.at_level and an assertion on caplog.text) instead of pytest.warns to verify the informational log about unconnected bodyparts. These changes improve default handling and make tests more robust about logging and axis availability.
  • Loading branch information
C-Achard committed Jun 24, 2026
commit 539394b6f225a82828793caf38ab5b9164368066
16 changes: 8 additions & 8 deletions deeplabcut/utils/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ def write_config(configname, cfg):


class SkeletonBuilder:
### Usage parameters
lasso_select_size = 5
Comment thread
C-Achard marked this conversation as resolved.
Resolved
clear_button_axes = [0.85, 0.55, 0.1, 0.1]
clear_button_text = "Clear"
export_button_axes = [0.85, 0.45, 0.1, 0.1]
export_button_text = "Save"
ampl = 1.3 # Amplification factor for the zoomed-in view of the animal

def __init__(self, config_path):
### Usage parameters
self.lasso_select_size = 5
self.clear_button_axes = [0.85, 0.55, 0.1, 0.1]
self.clear_button_text = "Clear"
self.export_button_axes = [0.85, 0.45, 0.1, 0.1]
self.export_button_text = "Save"
self.ampl = 1.3 # Amplification factor for the zoomed-in view of the animal
###
self.config_path = config_path
self.cfg = read_config(config_path)
# Find uncropped labeled data
Expand Down
8 changes: 6 additions & 2 deletions tests/utils/test_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def make_test_builder():

def attach_fake_canvas(builder):
builder.fig = Figure()
builder._ax = builder.fig.add_subplot(111)
builder._ax.set_xlim(-5, 25)
builder._ax.set_ylim(-5, 5)
builder.fig.canvas.draw_idle = lambda: None


Expand Down Expand Up @@ -136,7 +139,7 @@ def test_clear_resets_indices_segments_and_linecollection():
# ---------------------------------------------------------------------


def test_export_sorts_pairs_and_warns_for_unconnected(monkeypatch):
def test_export_sorts_pairs_and_warns_for_unconnected(monkeypatch, caplog):
builder = make_test_builder()
builder.config_path = "dummy_config.yaml"
builder.xy = np.array(
Expand All @@ -159,8 +162,9 @@ def fake_write_config(path, cfg):

monkeypatch.setattr(skeleton_mod, "write_config", fake_write_config)

with pytest.warns(UserWarning, match="didn't connect all the bodyparts"):
with caplog.at_level("INFO"):
builder.export()
assert "Not all bodyparts are connected" in caplog.text

assert captured["path"] == "dummy_config.yaml"
assert captured["cfg"]["skeleton"] == [
Expand Down
Loading