Skip to content
10 changes: 8 additions & 2 deletions datashuttle/tui/tabs/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ def compose(self) -> ComposeResult:
ClickableInput(
self.mainwindow,
id="transfer_subject_input",
placeholder="e.g. sub-001",
placeholder="e.g. sub-001 (default: all)",
),
Label("Session(s)", id="transfer_session_label"),
ClickableInput(
self.mainwindow,
id="transfer_session_input",
placeholder="e.g. ses-001",
placeholder="e.g. ses-001 (default: all)",
),
# These are almost identical to create tab
Label("Datatype(s)", id="transfer_datatype_label"),
Expand Down Expand Up @@ -409,6 +409,12 @@ def transfer_data(self) -> Worker[InterfaceOutput]:
"#transfer_subject_input", "#transfer_session_input"
)
)

if sub_names == [""]:
sub_names = ["all"]
if ses_names == [""]:
ses_names = ["all"]

success, output = self.interface.transfer_custom_selection(
selected_top_level_folder,
sub_names,
Expand Down
35 changes: 35 additions & 0 deletions tests/tests_tui/test_tui_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,41 @@ async def test_transfer_custom(

await pilot.pause()

@pytest.mark.asyncio()
async def test_custom_transfer_default_sub_ses_all(
self, mocker, setup_project_paths
):
"""
This PR tests that for subject and session inputs on the custom
transfer screen, passing no argument will call the transfer
function with arguments "all".
"""
tmp_config_path, tmp_path, project_name = setup_project_paths.values()

app = TuiApp()
async with app.run_test(size=self.tui_size()) as pilot:
await self.check_and_click_onto_existing_project(
pilot, project_name
)
await self.switch_tab(pilot, "transfer")

await self.scroll_to_click_pause(
pilot, "#transfer_custom_radiobutton"
)

spy_download_custom = mocker.spy(
pilot.app.screen.interface.project, "download_custom"
)

await self.run_transfer(pilot, "download")

_, kwargs_ = spy_download_custom.call_args_list[0]

assert kwargs_["sub_names"] == ["all"]
assert kwargs_["ses_names"] == ["all"]

await pilot.pause()

async def switch_top_level_folder_select(
self, pilot, id, top_level_folder
):
Expand Down
71 changes: 4 additions & 67 deletions tests/tests_tui/test_tui_widgets_and_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,15 +1075,14 @@ async def test_all_checkboxes(self, setup_project_paths):
"ephys",
"funcimg",
"anat",
"all",
"all_datatype",
"all_non_datatype",
# "all" and "all_datatype" will turn off transfer datatypes
# and are tested separately in `test_transfer_checkboxes_dynamic_on_off()`.
]:
await self.change_checkbox(
pilot, f"#transfer_{datatype}_checkbox"
)
expected_transfer[datatype]["on"] = True

self.check_datatype_checkboxes(
pilot, "transfer", expected_transfer
)
Expand All @@ -1104,68 +1103,6 @@ async def test_all_checkboxes(self, setup_project_paths):

await pilot.pause()

@pytest.mark.asyncio
async def test_transfer_checkboxes_dynamic_on_off(
self, setup_project_paths
):
"""
This tests that mutually exclusive checkbox options turn
each other off / on when set. This is necessary for transfer
tab custom datatypes in which some checkboxes (e.g. "all")
should not be selected with other (e.g. "behav").
"""
tmp_config_path, tmp_path, project_name = setup_project_paths.values()

app = TuiApp()
async with app.run_test(size=self.tui_size()) as pilot:
# Set up the TUI on the 'transfer' tab (custom) and
# open the datatype selection screen
await self.check_and_click_onto_existing_project(
pilot, project_name
)

await self.switch_tab(pilot, "transfer")
await self.scroll_to_click_pause(
pilot, "#transfer_custom_radiobutton"
)

# Create a function to reload the settings dict, refreshing the contents
def load_dict():
return pilot.app.screen.interface.project._load_persistent_settings()[
"tui"
]["transfer_checkboxes_on"]

# turn on "behav" checkbox, check "all" is turned off
assert load_dict()["all"]["on"]
await self.change_checkbox(pilot, "#transfer_behav_checkbox")
assert not load_dict()["all"]["on"]

# Turn on "all_non_datatype" checkbox, check "behav" is kept on
await self.change_checkbox(
pilot, "#transfer_all_non_datatype_checkbox"
)
assert load_dict()["all_non_datatype"]["on"]
assert load_dict()["behav"]["on"]

# Turn on "all_datatype" checkbox, check "behav" is turned off
await self.change_checkbox(
pilot, "#transfer_all_datatype_checkbox"
)
assert load_dict()["all_datatype"]["on"]
assert not load_dict()["behav"]["on"]

# Turn on "all" checkbox and check all_non_datatype and all_datatype are switched off
await self.change_checkbox(pilot, "#transfer_all_checkbox")
assert load_dict()["all"]["on"]
assert not load_dict()["all_datatype"]["on"]
assert not load_dict()["all_non_datatype"]["on"]

# Turn on "all_non_datatype" and check "all" is now off
await self.change_checkbox(
pilot, "#transfer_all_non_datatype_checkbox"
)
assert not load_dict()["all"]["on"]

def check_datatype_checkboxes(self, pilot, tab, expected_on):
assert tab in ["create", "transfer"]
if tab == "create":
Expand Down Expand Up @@ -1291,7 +1228,7 @@ async def test_all_transfer_widgets(self, setup_project_paths):
pilot.app.screen.query_one(
"#transfer_subject_input"
).placeholder
== "e.g. sub-001"
== "e.g. sub-001 (default: all)"
)

assert (
Expand All @@ -1304,7 +1241,7 @@ async def test_all_transfer_widgets(self, setup_project_paths):
pilot.app.screen.query_one(
"#transfer_session_input"
).placeholder
== "e.g. ses-001"
== "e.g. ses-001 (default: all)"
)

assert (
Expand Down
Loading