Skip to content

Commit 4f56302

Browse files
committed
fix: clean up BoardManual construct paths
1 parent 41a3c36 commit 4f56302

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

pins/boards.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,15 +730,19 @@ def construct_path(self, elements):
730730
f" single file. Cannot construct a path to elements {elements}."
731731
)
732732
return "/".join(pre_components + [pin_path])
733-
elif len(others) == 0:
733+
734+
# handle paths to pins (i.e. end with /) ----
735+
stripped = pin_path[:-1]
736+
737+
if len(others) == 0:
734738
return "/".join(pre_components + [pin_path])
735739
elif len(others) == 1:
736740
version = others[0]
737741
return "/".join(pre_components + [pin_path])
738742
elif len(others) == 2:
739743
version, meta = others
740744

741-
return "/".join(pre_components + [pin_path, meta])
745+
return "/".join(pre_components + [stripped, meta])
742746

743747
raise NotImplementedError(
744748
f"Unable to construct path from these elements: {elements}"

pins/tests/test_boards.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,3 +506,41 @@ def test_board_manual_pin_read():
506506

507507
# do a somewhat data-framey check
508508
assert df.shape[0] > 1
509+
510+
511+
def test_board_manual_construct_path():
512+
fs = fsspec.filesystem("file")
513+
root = "pins/tests/pins-compat"
514+
path_df_csv = "df_csv/20220214T163718Z-eceac/"
515+
path_df_csv_v2 = "df_csv/20220214T163720Z-9bfad/df_csv.csv"
516+
517+
board = BoardManual(
518+
root,
519+
fs,
520+
pin_paths={
521+
"df_csv": path_df_csv,
522+
"df_csv2_v2": path_df_csv_v2,
523+
},
524+
)
525+
526+
# path to pin folder ----
527+
# creates path to pin, ignores version, can include data.txt
528+
assert board.construct_path(["df_csv"]) == f"{root}/{path_df_csv}"
529+
assert board.construct_path(["df_csv", "v"]) == f"{root}/{path_df_csv}"
530+
assert (
531+
board.construct_path(["df_csv", "v", "data.txt"])
532+
== f"{root}/{path_df_csv}data.txt"
533+
)
534+
535+
with pytest.raises(NotImplementedError) as exc_info:
536+
board.construct_path(["df_csv", "v", "data.txt", "too_much"])
537+
538+
assert "Unable to construct path" in exc_info.value.args[0]
539+
540+
# path to individual file ----
541+
assert board.construct_path(["df_csv2_v2"]) == f"{root}/{path_df_csv_v2}"
542+
543+
with pytest.raises(ValueError) as exc_info:
544+
board.construct_path(["df_csv2_v2", "v"])
545+
546+
assert "assumed to be a single file" in exc_info.value.args[0]

0 commit comments

Comments
 (0)