Skip to content

Commit

Permalink
Fix for tests on window
Browse files Browse the repository at this point in the history
  • Loading branch information
zhubonan committed May 30, 2022
1 parent c8e2c94 commit bc62f1e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -3458,6 +3458,7 @@ def test_archive_path_settings(container_with_archive):
temp_container._update_archive_location(1, location)

# This should work
os.unlink(new_location)
location.rename(new_location)
temp_container._update_archive_location(1, new_location)
assert temp_container.get_archive_locations()["1"] == str(new_location)
Expand Down Expand Up @@ -3505,13 +3506,13 @@ def test_get_archive_path(temp_container):
+ "-997.zip"
)

pack = Pack(
pack_id="996", state=PackState.ARCHIVED.value, location="/tmp/archive.zip"
)
temp_dir = temp_container._folder
abs_archive = os.path.join(temp_dir, "temp_archive/2.zip")
pack = Pack(pack_id="996", state=PackState.ARCHIVED.value, location=abs_archive)
session.add(pack)
session.commit()
path = temp_container._get_archive_path_from_pack_id(996)
assert path == "/tmp/archive.zip"
assert path == abs_archive

# Relative path is relative to the container base folder
pack = Pack(
Expand All @@ -3522,6 +3523,8 @@ def test_get_archive_path(temp_container):
path = temp_container._get_archive_path_from_pack_id(995)
assert path == os.path.join(temp_container._folder, "archive2/archive.zip")

temp_container.close()


def test_get_pack_id_with_archive(temp_dir):
"""Test get_pack_id_to_write_to with archived packs"""
Expand Down Expand Up @@ -3569,15 +3572,19 @@ def test_get_pack_id_with_archive(temp_dir):
session.execute(
update(Pack)
.where(Pack.pack_id == str(to_archive))
.values(state=PackState.ARCHIVED.value, location=f"/tmp/{to_archive}.zip")
.values(
state=PackState.ARCHIVED.value,
location=os.path.join(temp_dir, f"{to_archive}.zip"),
)
)
session.commit()

# Writing to pack 2 is not allowed anymore
assert temp_container._get_pack_id_to_write_to() == 3

# Getting the "pack_path" for pack 2 should now point to the custom location
assert (
temp_container._get_pack_path_from_pack_id(to_archive)
== f"/tmp/{to_archive}.zip"
assert temp_container._get_pack_path_from_pack_id(to_archive) == os.path.join(
temp_dir, f"{to_archive}.zip"
)

temp_container.close()

0 comments on commit bc62f1e

Please sign in to comment.