Skip to content

Commit

Permalink
main: fix bug deleting all data for output path with trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
balinthaller committed Apr 20, 2021
1 parent 07e6786 commit 741f8d3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
6 changes: 5 additions & 1 deletion carte_cli/publisher/remove_deleted_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ def init(self, conf: ConfigTree) -> None:
def _get_datasets_to_delete(
self, datasets: Set[str], file_paths: List[str]
) -> Iterator[str]:
prefix_length = len(self.tables_path)
if not self.tables_path.endswith("/"):
prefix_length += 1

file_ids = [
path[(len(self.tables_path) + 1) : -(len(".md"))] for path in file_paths
path[prefix_length : -(len(".md"))] for path in file_paths
]

for file_path, file_id in zip(file_paths, file_ids):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "carte-cli"
version = "0.3.6"
version = "0.3.7"
description = "A static site generator for data catalogs"
authors = ["Balint Haller <balint@hey.com>"]
license = "GPL-3.0-or-later"
Expand Down
33 changes: 28 additions & 5 deletions tests/publisher/test_remove_deleted_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def test_get_datasets_to_delete():

test_datasets = set(
[
f"db1/dataset1",
f"db1/dataset3",
f"db1/dataset4",
f"db1/dataset5",
f"db2/dataset1",
"db1/dataset1",
"db1/dataset3",
"db1/dataset4",
"db1/dataset5",
"db2/dataset1",
]
)

Expand All @@ -34,3 +34,26 @@ def test_get_datasets_to_delete():
assert len(to_delete) == 2
assert "test-tables-path/db3/dataset1.md" in to_delete
assert "test-tables-path/db2/dataset2.md" in to_delete


def test_output_path_with_trailing_slash():
publisher = RemoveDeletedPublisher()
tables_path = "test-tables-path/"

publisher.tables_path = tables_path

test_datasets = set(["db1/dataset1", "db2/dataset1"])

test_file_paths = [
f"{tables_path}db1/dataset1.md",
f"{tables_path}db2/dataset1.md",
f"{tables_path}db2/dataset2.md",
]

to_delete = [
dataset
for dataset in publisher._get_datasets_to_delete(test_datasets, test_file_paths)
]

assert len(to_delete) == 1
assert to_delete[0] == "test-tables-path/db2/dataset2.md"

0 comments on commit 741f8d3

Please sign in to comment.