From 79f97c2b56c68e479419addc5212d7c58a45eef0 Mon Sep 17 00:00:00 2001 From: pragam-m25 Date: Sun, 2 Nov 2025 13:11:38 +0530 Subject: [PATCH 1/5] Tests: Add tests for Checkbox and InputText in UserInputs --- tests/test_solara_viz.py | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/test_solara_viz.py b/tests/test_solara_viz.py index 8408c871dd6..6fab13a35b4 100644 --- a/tests/test_solara_viz.py +++ b/tests/test_solara_viz.py @@ -326,3 +326,59 @@ def __init__(self, param1, *args): ), ): _check_model_params(ModelWithArgsOnly.__init__, model_params) + +def test_model_params_to_widgets_bool(): + """ + Test that a "Checkbox" type parameter correctly creates a vw.Checkbox. + """ + # 1. Input: Hum "is_happy" parameter ko dictionary format mein banaenge + model_params = { + "is_happy": {"type": "Checkbox", "value": True, "label": "Am I Happy?"} + } + + # 2. Action: Hum UserInputs component ko render karenge + @solara.component + def Test(): + return UserInputs(model_params) + + _, rc = solara.render(Test(), handle_error=False) + + # 3. Check (Assert): + # - Kya 1 widget bana? + assert len(rc.find(vw.Checkbox)) == 1 + + # - Widget ko pakdo + widget = rc.find(vw.Checkbox).widget + + # - Kya label sahi hai? + assert widget.label == "Am I Happy?" + # - Kya value (v_model) sahi hai? + assert widget.v_model is True + +def test_model_params_to_widgets_text_input(): + """ + Test that an "InputText" type parameter correctly creates a vw.TextField. + """ + # 1. Input: Hum "agent_name" parameter ko dictionary format mein banaenge + model_params = { + "agent_name": {"type": "InputText", "value": "JohnDoe", "label": "Agent Name"} + } + + # 2. Action: Hum UserInputs component ko render karenge + @solara.component + def Test(): + return UserInputs(model_params) + + _, rc = solara.render(Test(), handle_error=False) + + # 3. Check (Assert): + # - Kya 1 vw.TextField bana? (solara.InputText isse banata hai) + assert len(rc.find(vw.TextField)) == 1 + + # - Widget ko pakdo + widget = rc.find(vw.TextField).widget + + # - Kya label sahi hai? + assert widget.label == "Agent Name" + # - Kya value (v_model) sahi hai? + assert widget.v_model == "JohnDoe" \ No newline at end of file From 6fee341b745cee2197bcd29bb77539f2d8a00736 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 2 Nov 2025 07:44:40 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_solara_viz.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/test_solara_viz.py b/tests/test_solara_viz.py index 6fab13a35b4..90afa3d76e4 100644 --- a/tests/test_solara_viz.py +++ b/tests/test_solara_viz.py @@ -327,10 +327,9 @@ def __init__(self, param1, *args): ): _check_model_params(ModelWithArgsOnly.__init__, model_params) + def test_model_params_to_widgets_bool(): - """ - Test that a "Checkbox" type parameter correctly creates a vw.Checkbox. - """ + """Test that a "Checkbox" type parameter correctly creates a vw.Checkbox.""" # 1. Input: Hum "is_happy" parameter ko dictionary format mein banaenge model_params = { "is_happy": {"type": "Checkbox", "value": True, "label": "Am I Happy?"} @@ -346,7 +345,7 @@ def Test(): # 3. Check (Assert): # - Kya 1 widget bana? assert len(rc.find(vw.Checkbox)) == 1 - + # - Widget ko pakdo widget = rc.find(vw.Checkbox).widget @@ -355,10 +354,9 @@ def Test(): # - Kya value (v_model) sahi hai? assert widget.v_model is True + def test_model_params_to_widgets_text_input(): - """ - Test that an "InputText" type parameter correctly creates a vw.TextField. - """ + """Test that an "InputText" type parameter correctly creates a vw.TextField.""" # 1. Input: Hum "agent_name" parameter ko dictionary format mein banaenge model_params = { "agent_name": {"type": "InputText", "value": "JohnDoe", "label": "Agent Name"} @@ -374,11 +372,11 @@ def Test(): # 3. Check (Assert): # - Kya 1 vw.TextField bana? (solara.InputText isse banata hai) assert len(rc.find(vw.TextField)) == 1 - + # - Widget ko pakdo widget = rc.find(vw.TextField).widget # - Kya label sahi hai? assert widget.label == "Agent Name" # - Kya value (v_model) sahi hai? - assert widget.v_model == "JohnDoe" \ No newline at end of file + assert widget.v_model == "JohnDoe" From a83df045d95a5ef526600d70f55f13832449ddc6 Mon Sep 17 00:00:00 2001 From: pragam-m25 Date: Sun, 2 Nov 2025 13:23:32 +0530 Subject: [PATCH 3/5] Fix: Remove typo in comment for codespell --- tests/test_solara_viz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_solara_viz.py b/tests/test_solara_viz.py index 90afa3d76e4..38714de4697 100644 --- a/tests/test_solara_viz.py +++ b/tests/test_solara_viz.py @@ -370,7 +370,7 @@ def Test(): _, rc = solara.render(Test(), handle_error=False) # 3. Check (Assert): - # - Kya 1 vw.TextField bana? (solara.InputText isse banata hai) + # - Kya 1 vw.TextField bana? (solara.InputText creates this) assert len(rc.find(vw.TextField)) == 1 # - Widget ko pakdo From f5cdb38717ae69afba18c23d05b71a9dcf695d31 Mon Sep 17 00:00:00 2001 From: pragam-m25 Date: Sun, 2 Nov 2025 15:11:42 +0530 Subject: [PATCH 4/5] Refactor: Move InputText test to test_solara_viz_updated.py as per review --- tests/test_solara_viz.py | 54 -------------------------------- tests/test_solara_viz_updated.py | 21 +++++++++++++ 2 files changed, 21 insertions(+), 54 deletions(-) diff --git a/tests/test_solara_viz.py b/tests/test_solara_viz.py index 38714de4697..8408c871dd6 100644 --- a/tests/test_solara_viz.py +++ b/tests/test_solara_viz.py @@ -326,57 +326,3 @@ def __init__(self, param1, *args): ), ): _check_model_params(ModelWithArgsOnly.__init__, model_params) - - -def test_model_params_to_widgets_bool(): - """Test that a "Checkbox" type parameter correctly creates a vw.Checkbox.""" - # 1. Input: Hum "is_happy" parameter ko dictionary format mein banaenge - model_params = { - "is_happy": {"type": "Checkbox", "value": True, "label": "Am I Happy?"} - } - - # 2. Action: Hum UserInputs component ko render karenge - @solara.component - def Test(): - return UserInputs(model_params) - - _, rc = solara.render(Test(), handle_error=False) - - # 3. Check (Assert): - # - Kya 1 widget bana? - assert len(rc.find(vw.Checkbox)) == 1 - - # - Widget ko pakdo - widget = rc.find(vw.Checkbox).widget - - # - Kya label sahi hai? - assert widget.label == "Am I Happy?" - # - Kya value (v_model) sahi hai? - assert widget.v_model is True - - -def test_model_params_to_widgets_text_input(): - """Test that an "InputText" type parameter correctly creates a vw.TextField.""" - # 1. Input: Hum "agent_name" parameter ko dictionary format mein banaenge - model_params = { - "agent_name": {"type": "InputText", "value": "JohnDoe", "label": "Agent Name"} - } - - # 2. Action: Hum UserInputs component ko render karenge - @solara.component - def Test(): - return UserInputs(model_params) - - _, rc = solara.render(Test(), handle_error=False) - - # 3. Check (Assert): - # - Kya 1 vw.TextField bana? (solara.InputText creates this) - assert len(rc.find(vw.TextField)) == 1 - - # - Widget ko pakdo - widget = rc.find(vw.TextField).widget - - # - Kya label sahi hai? - assert widget.label == "Agent Name" - # - Kya value (v_model) sahi hai? - assert widget.v_model == "JohnDoe" diff --git a/tests/test_solara_viz_updated.py b/tests/test_solara_viz_updated.py index 9f49539de55..9d5943a61e6 100644 --- a/tests/test_solara_viz_updated.py +++ b/tests/test_solara_viz_updated.py @@ -325,3 +325,24 @@ def __init__(self, param1, *args): ), ): _check_model_params(ModelWithArgsOnly.__init__, model_params) + + +def test_input_text_field(self): + """Test that "InputText" type creates a vw.TextField.""" + + @solara.component + def Test(user_params): + UserInputs(user_params) + + options = {"type": "InputText", "value": "JohnDoe", "label": "Agent Name"} + user_params = {"agent_name": options} + + # Action: Render the component + _, rc = solara.render(Test(user_params), handle_error=False) + + # Check: Find the widget + textfield = rc.find(vw.TextField).widget + + # Assert: Check label and value + assert textfield.v_model == options["value"] + assert textfield.label == options["label"] From 5daddfeed6e154637dc27ec7fdc9469e54153bd6 Mon Sep 17 00:00:00 2001 From: pragam-m25 Date: Sun, 2 Nov 2025 15:31:57 +0530 Subject: [PATCH 5/5] Fix: Correctly place test method inside TestMakeUserInput class --- tests/test_solara_viz_updated.py | 39 +++++++++++++++----------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/tests/test_solara_viz_updated.py b/tests/test_solara_viz_updated.py index 9d5943a61e6..03db138fa2d 100644 --- a/tests/test_solara_viz_updated.py +++ b/tests/test_solara_viz_updated.py @@ -93,6 +93,24 @@ def Test(user_params): assert slider_int.max is None assert slider_int.step is None + def test_input_text_field(self): + """Test that "InputText" type creates a vw.TextField.""" + + @solara.component + def Test(user_params): + UserInputs(user_params) + + options = {"type": "InputText", "value": "JohnDoe", "label": "Agent Name"} + + user_params = {"agent_name": options} + + _, rc = solara.render(Test(user_params), handle_error=False) + + textfield = rc.find(vw.TextField).widget + + assert textfield.v_model == options["value"] + assert textfield.label == options["label"] + def test_call_space_drawer(mocker): """Test the call to space drawer.""" @@ -325,24 +343,3 @@ def __init__(self, param1, *args): ), ): _check_model_params(ModelWithArgsOnly.__init__, model_params) - - -def test_input_text_field(self): - """Test that "InputText" type creates a vw.TextField.""" - - @solara.component - def Test(user_params): - UserInputs(user_params) - - options = {"type": "InputText", "value": "JohnDoe", "label": "Agent Name"} - user_params = {"agent_name": options} - - # Action: Render the component - _, rc = solara.render(Test(user_params), handle_error=False) - - # Check: Find the widget - textfield = rc.find(vw.TextField).widget - - # Assert: Check label and value - assert textfield.v_model == options["value"] - assert textfield.label == options["label"]