2022-01-19 04:11:05 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import unittest.mock
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import BinaryIO
|
2022-11-24 20:33:58 +03:00
|
|
|
from urllib.parse import urlparse
|
2022-01-19 04:11:05 +03:00
|
|
|
|
2022-11-21 23:37:14 +03:00
|
|
|
import conftest
|
|
|
|
|
2022-01-19 04:11:05 +03:00
|
|
|
from nix_update.version import fetch_latest_version
|
|
|
|
from nix_update.version.version import VersionPreference
|
|
|
|
|
|
|
|
TEST_ROOT = Path(__file__).parent.resolve()
|
|
|
|
|
|
|
|
|
|
|
|
def fake_urlopen(url: str) -> BinaryIO:
|
2024-02-24 02:52:42 +03:00
|
|
|
if url.endswith("releases.atom"):
|
|
|
|
return open(TEST_ROOT.joinpath("test_branch_releases.atom"), "rb")
|
|
|
|
else:
|
|
|
|
return open(TEST_ROOT.joinpath("test_branch_commits_master.atom"), "rb")
|
2022-01-19 04:11:05 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_branch(helpers: conftest.Helpers) -> None:
|
2023-08-14 11:08:55 +03:00
|
|
|
del helpers
|
2022-01-19 04:11:05 +03:00
|
|
|
with unittest.mock.patch("urllib.request.urlopen", fake_urlopen):
|
|
|
|
assert (
|
|
|
|
fetch_latest_version(
|
2022-11-24 20:33:58 +03:00
|
|
|
urlparse("https://github.com/Mic92/nix-update"),
|
2022-01-19 04:11:05 +03:00
|
|
|
VersionPreference.BRANCH,
|
|
|
|
"(.*)",
|
|
|
|
"master",
|
|
|
|
).number
|
2024-02-24 02:52:42 +03:00
|
|
|
== "1.2.0-unstable-2024-02-19"
|
2022-01-19 04:11:05 +03:00
|
|
|
)
|