Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis SMAIL committed Jan 28, 2025
1 parent d1e2376 commit 058f898
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions tests/storage/business/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@


@pytest.mark.unit_test
def test_import_study(tmp_path_posix: Path) -> None:
def test_import_study(tmp_path: Path) -> None:
name = "my-study"
study_path_posix = tmp_path_posix / name
study_path = Path(study_path_posix)
study_path = tmp_path / name
study_path.mkdir()
(study_path / "study.antares").touch()

Expand All @@ -53,7 +52,7 @@ def test_import_study(tmp_path_posix: Path) -> None:
study_service.get.return_value = data

# first test importing a study for an archived study with `.zip` format
study_service.get_study_path.return_value = tmp_path_posix / "other-study-zip"
study_service.get_study_path.return_value = tmp_path / "other-study-zip"

filepath_zip = shutil.make_archive(str(study_path.absolute()), "zip", study_path)
shutil.rmtree(study_path)
Expand All @@ -63,20 +62,20 @@ def test_import_study(tmp_path_posix: Path) -> None:
md = RawStudy(
id="other-study-zip",
workspace=DEFAULT_WORKSPACE_NAME,
path=tmp_path_posix / "other-study-zip",
path=tmp_path / "other-study-zip",
additional_data=StudyAdditionalData(),
groups=["fake_group_1", "fake_group_2"],
)
with path_zip.open("rb") as input_file:
md = study_service.import_study(md, input_file)
assert md.path == f"{tmp_path_posix}/other-study-zip"
assert md.path == f"{tmp_path}{os.sep}other-study-zip"
# assert that importing file into a created study does not alter its group
assert md.groups == ["fake_group_1", "fake_group_2"]

shutil.rmtree(tmp_path_posix / "other-study-zip")
shutil.rmtree(tmp_path / "other-study-zip")

# second test for an archived study with a `.7z` format
study_service.get_study_path.return_value = tmp_path_posix / "other-study-7zip"
study_service.get_study_path.return_value = tmp_path / "other-study-7zip"

study_path.mkdir()
(study_path / "study.antares").touch()
Expand All @@ -90,17 +89,17 @@ def test_import_study(tmp_path_posix: Path) -> None:
md = RawStudy(
id="other-study-7zip",
workspace=DEFAULT_WORKSPACE_NAME,
path=tmp_path_posix / "other-study-7zip",
path=tmp_path / "other-study-7zip",
additional_data=StudyAdditionalData(),
groups=["fake_group_1", "fake_group_2"],
)
with filepath_7zip.open("rb") as input_file:
md = study_service.import_study(md, input_file)
assert md.path == f"{tmp_path_posix}/other-study-7zip"
assert md.path == f"{tmp_path}{os.sep}other-study-7zip"
# assert that importing file into a created study does not alter its group
assert md.groups == ["fake_group_1", "fake_group_2"]

shutil.rmtree(tmp_path_posix / "other-study-7zip")
shutil.rmtree(tmp_path / "other-study-7zip")

# test for an unsupported archive format
with pytest.raises(BadArchiveContent, match="Unsupported archive format"):
Expand Down

0 comments on commit 058f898

Please sign in to comment.