Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Add a test for manual update when a pre-release has already been downloaded
  • Loading branch information
mayeut committed Jan 1, 2022
1 parent 8dcc666 commit 3775c8d
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions tests/unit/seed/wheels/test_periodic_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ def test_manual_update_honored(mocker, session_app_data, for_py_version):
assert str(result.path) == expected_path


def wheel_path(wheel, of):
def wheel_path(wheel, of, pre_release=""):
new_version = ".".join(str(i) for i in (tuple(sum(x) for x in zip_longest(wheel.version_tuple, of, fillvalue=0))))
new_name = wheel.name.replace(wheel.version, new_version)
new_name = wheel.name.replace(wheel.version, new_version + pre_release)
return str(wheel.path.parent / new_name)


Expand Down Expand Up @@ -545,6 +545,39 @@ def test_download_manual_stop_after_one_download(tmp_path, mocker, freezer):
assert write.call_count == 1


def test_download_manual_ignores_pre_release(tmp_path, mocker, freezer):
freezer.move_to(_UP_NOW)
wheel = get_embed_wheel("pip", "3.9")
app_data_outer = AppDataDiskFolder(str(tmp_path / "app"))
pip_version_remote = [wheel_path(wheel, (0, 0, 1))]
pip_version_pre = NewVersion(Path(wheel_path(wheel, (0, 1, 0), "b1")).name, _UP_NOW, None, "downloaded")

download_wheel = mock_download(mocker, pip_version_remote)
url_o = mocker.patch("virtualenv.seed.wheels.periodic_update.urlopen", side_effect=URLError("unavailable"))

last_update = _UP_NOW - timedelta(days=14)
u_log = UpdateLog(started=last_update, completed=last_update, versions=[pip_version_pre], periodic=True)
read_dict = mocker.patch("virtualenv.app_data.via_disk_folder.JSONStoreDisk.read", return_value=u_log.to_dict())
write = mocker.patch("virtualenv.app_data.via_disk_folder.JSONStoreDisk.write")

do_update("pip", "3.9", str(wheel.path), str(app_data_outer), [], False)

assert download_wheel.call_count == 1
assert url_o.call_count == 2
assert read_dict.call_count == 1
assert write.call_count == 1
wrote_json = write.call_args[0][0]
assert wrote_json["versions"] == [
{
"filename": Path(pip_version_remote[0]).name,
"release_date": None,
"found_date": dump_datetime(_UP_NOW),
"source": "manual",
},
pip_version_pre.to_dict(),
]


def test_download_periodic_stop_at_first_usable(tmp_path, mocker, freezer):
freezer.move_to(_UP_NOW)
wheel = get_embed_wheel("pip", "3.9")
Expand Down

0 comments on commit 3775c8d

Please sign in to comment.