fix pypi cannot check after upload
This commit is contained in:
@@ -501,7 +501,122 @@ def test_index_files_returns_none_when_version_absent(monkeypatch):
|
||||
return False
|
||||
|
||||
monkeypatch.setattr(pypi.urllib.request, "urlopen", lambda *a, **k: Response())
|
||||
assert pypi.index_files("pypi", "1.2.3") is None
|
||||
assert pypi.index_files("pypi", "1.2.3") == (None, None)
|
||||
|
||||
|
||||
def test_index_files_distinguishes_lookup_failure_from_absence(monkeypatch):
|
||||
"""A network hiccup must not be reported as "not published yet"."""
|
||||
|
||||
def _raise(*args, **kwargs):
|
||||
raise urllib.error.URLError("connection reset")
|
||||
|
||||
monkeypatch.setattr(pypi.urllib.request, "urlopen", _raise)
|
||||
filenames, error = pypi.index_files("testpypi", "1.2.3")
|
||||
assert filenames is None
|
||||
assert error is not None and "connection reset" in error
|
||||
|
||||
|
||||
def test_index_files_returns_filenames(monkeypatch):
|
||||
class Response:
|
||||
def read(self, *args):
|
||||
return json.dumps(
|
||||
{"releases": {"1.2.3": [{"filename": "b.whl"}, {"filename": "a.whl"}]}}
|
||||
).encode()
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *exc):
|
||||
return False
|
||||
|
||||
monkeypatch.setattr(pypi.urllib.request, "urlopen", lambda *a, **k: Response())
|
||||
assert pypi.index_files("pypi", "1.2.3") == (["a.whl", "b.whl"], None)
|
||||
|
||||
|
||||
def test_wait_for_release_retries_until_indexing_finishes(monkeypatch):
|
||||
"""TestPyPI lags the upload response; the check must poll, not give up."""
|
||||
calls = {"n": 0}
|
||||
slept: list[float] = []
|
||||
|
||||
def _fake(index, version, *, timeout=20.0):
|
||||
calls["n"] += 1
|
||||
if calls["n"] < 3:
|
||||
return None, None
|
||||
return ["a.whl"], None
|
||||
|
||||
monkeypatch.setattr(pypi, "index_files", _fake)
|
||||
filenames, error = pypi.wait_for_release(
|
||||
"testpypi", "1.2.3", attempts=5, delay=1.0, sleep=slept.append
|
||||
)
|
||||
assert filenames == ["a.whl"]
|
||||
assert error is None
|
||||
assert calls["n"] == 3
|
||||
assert slept == [1.0, 1.0]
|
||||
|
||||
|
||||
def test_wait_for_release_reports_the_last_error(monkeypatch):
|
||||
def _fake(index, version, *, timeout=20.0):
|
||||
return None, "HTTP 503"
|
||||
|
||||
monkeypatch.setattr(pypi, "index_files", _fake)
|
||||
filenames, error = pypi.wait_for_release(
|
||||
"pypi", "1.2.3", attempts=2, delay=0.0, sleep=lambda _: None
|
||||
)
|
||||
assert filenames is None
|
||||
assert error == "HTTP 503"
|
||||
|
||||
|
||||
def test_existing_release_state_satisfied_conflict_absent(monkeypatch, capsys):
|
||||
expected = {"orisys-1.2.3-cp310-cp310-win_amd64.whl"}
|
||||
monkeypatch.setattr(pypi, "index_files", lambda i, v, **k: (None, None))
|
||||
assert pypi.existing_release_state("pypi", "1.2.3", expected) == "absent"
|
||||
|
||||
monkeypatch.setattr(pypi, "index_files", lambda i, v, **k: (sorted(expected), None))
|
||||
assert pypi.existing_release_state("pypi", "1.2.3", expected) == "satisfied"
|
||||
|
||||
monkeypatch.setattr(
|
||||
pypi, "index_files", lambda i, v, **k: (["orisys-1.2.3-cp311-cp311-win_amd64.whl"], None)
|
||||
)
|
||||
assert pypi.existing_release_state("pypi", "1.2.3", expected) == "conflict"
|
||||
output = capsys.readouterr().out
|
||||
assert "different file set" in output and "missing" in output
|
||||
|
||||
|
||||
def test_publish_rerun_after_success_is_not_a_failure(tmp_path, monkeypatch, capsys):
|
||||
"""Re-running a finished phase must succeed, not look like a new error."""
|
||||
sdk, wheel = _synthetic_report_layout(tmp_path, "1.2.3")
|
||||
monkeypatch.setattr(pypi, "REPO_ROOT", sdk)
|
||||
from release import auth
|
||||
|
||||
auth.write_token("pypi", "pypi-" + "A" * 30, path=tmp_path / ".pypirc")
|
||||
monkeypatch.setattr(auth, "pypirc_path", lambda: tmp_path / ".pypirc")
|
||||
monkeypatch.setattr(
|
||||
pypi, "index_files", lambda i, v, **k: ([wheel.name], None)
|
||||
)
|
||||
|
||||
exit_code = pypi.publish(
|
||||
pypi.Options(version="1.2.3", apply=True, pypi_only=True, skip_check=True)
|
||||
)
|
||||
output = capsys.readouterr().out
|
||||
assert exit_code == 0
|
||||
assert "already serves orisys 1.2.3" in output
|
||||
assert "every requested index already has this release" in output
|
||||
|
||||
|
||||
def test_publish_aborts_on_a_conflicting_existing_release(tmp_path, monkeypatch, capsys):
|
||||
sdk, wheel = _synthetic_report_layout(tmp_path, "1.2.3")
|
||||
monkeypatch.setattr(pypi, "REPO_ROOT", sdk)
|
||||
from release import auth
|
||||
|
||||
auth.write_token("pypi", "pypi-" + "A" * 30, path=tmp_path / ".pypirc")
|
||||
monkeypatch.setattr(auth, "pypirc_path", lambda: tmp_path / ".pypirc")
|
||||
monkeypatch.setattr(pypi, "index_files", lambda i, v, **k: (["other.whl"], None))
|
||||
|
||||
exit_code = pypi.publish(
|
||||
pypi.Options(version="1.2.3", apply=True, pypi_only=True, skip_check=True)
|
||||
)
|
||||
assert exit_code == 1
|
||||
assert "different file set" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_index_json_urls_cover_both_indexes():
|
||||
|
||||
Reference in New Issue
Block a user