Skip to content

Commit bb2db57

Browse files
committed
Add tests.
1 parent 4d02006 commit bb2db57

4 files changed

Lines changed: 97 additions & 31 deletions

File tree

datashuttle/tui/shared/validate_content.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def compose(self) -> ComposeResult:
106106
Checkbox(
107107
"ALLOW_ALPHANUMERIC",
108108
value=False,
109-
id="ALLOW_ALPHANUMERIC_checkbox",
109+
id="validate_ALLOW_ALPHANUMERIC_checkbox",
110110
),
111111
id="validate_arguments_horizontal",
112112
),
@@ -163,7 +163,7 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
163163
).value
164164

165165
ALLOW_ALPHANUMERIC = self.query_one(
166-
"#ALLOW_ALPHANUMERIC_checkbox"
166+
"#validate_ALLOW_ALPHANUMERIC_checkbox"
167167
).value
168168

169169
if self.interface:

tests/tests_tui/test_tui_create_folders.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ async def test_validation_error_and_bypass_validation(
259259
checking an error displays. Next, turn on 'bypass validation'
260260
and check the folders are created despite being invalid.
261261
"""
262-
tmp_config_path, tmp_path, project_name = setup_project_paths.values()
262+
_, _, project_name = setup_project_paths.values()
263263

264264
app = TuiApp()
265265
async with app.run_test(size=self.tui_size()) as pilot:
@@ -323,6 +323,52 @@ async def test_validation_error_and_bypass_validation(
323323

324324
await pilot.pause()
325325

326+
@pytest.mark.asyncio
327+
async def test_ALLOW_ALPHANUMERIC(self, setup_project_paths):
328+
""""""
329+
_, _, project_name = setup_project_paths.values()
330+
331+
app = TuiApp()
332+
async with app.run_test(size=self.tui_size()) as pilot:
333+
await self.check_and_click_onto_existing_project(
334+
pilot, project_name
335+
)
336+
337+
await self.fill_input(
338+
pilot, "#create_folders_subject_input", "sub-abc"
339+
)
340+
await self.fill_input(
341+
pilot, "#create_folders_session_input", "ses-abc"
342+
)
343+
344+
await self.scroll_to_click_pause(
345+
pilot, "#create_folders_settings_button"
346+
)
347+
await self.scroll_to_click_pause(
348+
pilot, "#create_folders_ALLOW_ALPHANUMERIC_checkbox"
349+
)
350+
await self.scroll_to_click_pause(
351+
pilot, "#create_folders_settings_close_button"
352+
)
353+
354+
await self.scroll_to_click_pause(
355+
pilot, "#create_folders_create_folders_button"
356+
)
357+
358+
assert (
359+
pilot.app.screen.interface.project.cfg["local_path"]
360+
/ "rawdata"
361+
/ "sub-abc"
362+
).is_dir()
363+
assert (
364+
pilot.app.screen.interface.project.cfg["local_path"]
365+
/ "rawdata"
366+
/ "sub-abc"
367+
/ "ses-abc"
368+
).is_dir()
369+
370+
await pilot.pause()
371+
326372
# -------------------------------------------------------------------------
327373
# Test Name Templates
328374
# -------------------------------------------------------------------------

tests/tests_tui/test_tui_validate.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ async def test_validate_on_project_manager_kwargs(
104104
"ses": None,
105105
}
106106
assert kwargs_["strict_mode"] is False
107+
assert kwargs_["ALLOW_ALPHANUMERIC"] is False
107108

108109
# Then, change all arguments and check these are
109110
# changed at the level of the called function.
@@ -117,6 +118,10 @@ async def test_validate_on_project_manager_kwargs(
117118
)
118119
await self.change_checkbox(pilot, "#validate_strict_mode_checkbox")
119120

121+
await self.change_checkbox(
122+
pilot, "#validate_ALLOW_ALPHANUMERIC_checkbox"
123+
)
124+
120125
await self.scroll_to_click_pause(
121126
pilot, "#validate_validate_button"
122127
)
@@ -146,6 +151,7 @@ async def test_validate_on_project_manager_kwargs(
146151
"ses": None,
147152
}
148153
assert kwargs_["strict_mode"] is False
154+
assert kwargs_["ALLOW_ALPHANUMERIC"] is True
149155

150156
# Check the widgets are hidden as expected.
151157
# Path widgets are not shown for Transfer tab
@@ -176,6 +182,10 @@ async def test_validate_at_path_kwargs(self, setup_project_paths, mocker):
176182
)
177183
await self.fill_input(pilot, "#validate_path_input", project_path)
178184

185+
await self.change_checkbox(
186+
pilot, "#validate_ALLOW_ALPHANUMERIC_checkbox"
187+
)
188+
179189
# Spy the function and click 'validate' button
180190
spy_validate = mocker.spy(
181191
datashuttle.tui.shared.validate_content,
@@ -194,6 +204,7 @@ async def test_validate_at_path_kwargs(self, setup_project_paths, mocker):
194204
assert args_[0] == project_path
195205
assert kwargs_["top_level_folder"] == "rawdata"
196206
assert kwargs_["strict_mode"] is False
207+
assert kwargs_["ALLOW_ALPHANUMERIC"] is True
197208

198209
# Check removed widgets, this should be removed because always local
199210
with pytest.raises(textual.css.query.InvalidQueryFormat):

tests/tests_tui/test_tui_widgets_and_defaults.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,20 @@ async def test_create_folder_settings_widgets(self, setup_project_paths):
416416
is False
417417
)
418418

419+
# ALLOW_ALPHANUMERIC
420+
assert (
421+
pilot.app.screen.query_one(
422+
"#create_folders_ALLOW_ALPHANUMERIC_checkbox"
423+
).label._text
424+
== "ALLOW_ALPHANUMERIC"
425+
)
426+
assert (
427+
pilot.app.screen.query_one(
428+
"#create_folders_ALLOW_ALPHANUMERIC_checkbox"
429+
).value
430+
is False
431+
)
432+
419433
# Template validation
420434
assert (
421435
pilot.app.screen.query_one(
@@ -650,12 +664,26 @@ async def test_name_templates_widgets_and_settings(
650664
await pilot.pause()
651665

652666
@pytest.mark.asyncio
653-
async def test_bypass_validation_settings(self, setup_project_paths):
654-
"""Test all configs that underly the 'bypass validation'
667+
@pytest.mark.parametrize(
668+
"parameter_name", ["bypass_validation", "ALLOW_ALPHANUMERIC"]
669+
)
670+
async def test_create_folderes_validation_settings(
671+
self, setup_project_paths, parameter_name
672+
):
673+
"""Test all configs that underly the 'bypass validation' and `ALLOW_ALPHANUMERIC`
655674
setting are updated correctly by the widget.
675+
676+
These two options are similar and are both default off, we so we can test
677+
them using the same process (turning them on and checking the underlying
678+
parameters in the stored dictionaries are also changed as expected).
656679
"""
657680
tmp_config_path, tmp_path, project_name = setup_project_paths.values()
658681

682+
if parameter_name == "bypass_validation":
683+
checkbox_id = "#create_folders_settings_bypass_validation_checkbox"
684+
else:
685+
checkbox_id = "#create_folders_ALLOW_ALPHANUMERIC_checkbox"
686+
659687
app = TuiApp()
660688
async with app.run_test(size=self.tui_size()) as pilot:
661689
await self.setup_existing_project_create_tab_filled_sub_and_ses(
@@ -665,30 +693,17 @@ async def test_bypass_validation_settings(self, setup_project_paths):
665693
pilot, "#create_folders_settings_button"
666694
)
667695

696+
assert pilot.app.screen.query_one(checkbox_id).value is False
668697
assert (
669-
pilot.app.screen.query_one(
670-
"#create_folders_settings_bypass_validation_checkbox"
671-
).value
672-
is False
673-
)
674-
assert (
675-
pilot.app.screen.interface.tui_settings["bypass_validation"]
698+
pilot.app.screen.interface.tui_settings[parameter_name]
676699
is False
677700
)
678701

679-
await self.scroll_to_click_pause(
680-
pilot, "#create_folders_settings_bypass_validation_checkbox"
681-
)
702+
await self.scroll_to_click_pause(pilot, checkbox_id)
682703

704+
assert pilot.app.screen.query_one(checkbox_id).value is True
683705
assert (
684-
pilot.app.screen.query_one(
685-
"#create_folders_settings_bypass_validation_checkbox"
686-
).value
687-
is True
688-
)
689-
assert (
690-
pilot.app.screen.interface.tui_settings["bypass_validation"]
691-
is True
706+
pilot.app.screen.interface.tui_settings[parameter_name] is True
692707
)
693708

694709
await self.scroll_to_click_pause(
@@ -701,15 +716,9 @@ async def test_bypass_validation_settings(self, setup_project_paths):
701716
pilot, "#create_folders_settings_button"
702717
)
703718

719+
assert pilot.app.screen.query_one(checkbox_id).value is True
704720
assert (
705-
pilot.app.screen.query_one(
706-
"#create_folders_settings_bypass_validation_checkbox"
707-
).value
708-
is True
709-
)
710-
assert (
711-
pilot.app.screen.interface.tui_settings["bypass_validation"]
712-
is True
721+
pilot.app.screen.interface.tui_settings[parameter_name] is True
713722
)
714723

715724
await pilot.pause()

0 commit comments

Comments
 (0)