From 1750cebbe434247fd73c6269ea34b1ebe875c8c1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Jul 2023 16:01:38 -0400 Subject: [PATCH] Add test capturing expectation. Ref #404 --- tests/fixtures.py | 25 +++++++++++++++++++++++++ tests/test_main.py | 7 +++++++ 2 files changed, 32 insertions(+) diff --git a/tests/fixtures.py b/tests/fixtures.py index c0b0fa32..13d79936 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,6 +1,7 @@ import os import sys import copy +import json import shutil import pathlib import tempfile @@ -8,6 +9,8 @@ import functools import contextlib +from typing import cast, Dict + from .py39compat import FS_NONASCII from . import _path @@ -127,6 +130,28 @@ def make_uppercase(self): build_files(files, self.site_dir) +class DistInfoPkgEditable(DistInfoPkg): + """ + Package with a PEP 660 direct_url.json. + """ + + files: FilesSpec = copy.deepcopy(DistInfoPkg.files) + some_hash = '524127ce937f7cb65665130c695abd18ca386f60bb29687efb976faa1596fdcc' + cast(Dict, files['distinfo_pkg-1.0.0.dist-info']).update( + { + 'direct_url.json': json.dumps( + { + "archive_info": { + "hash": f"sha256={some_hash}", + "hashes": {"sha256": f"{some_hash}"}, + }, + "url": "file:///path/to/distinfo_pkg-1.0.0.editable-py3-none-any.whl", + } + ) + }, + ) + + class DistInfoPkgWithDot(OnSysPath, SiteDir): files: FilesSpec = { "pkg_dot-1.0.0.dist-info": { diff --git a/tests/test_main.py b/tests/test_main.py index 79181bf4..813c4e13 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -457,3 +457,10 @@ def import_names_from_package(package_name): # sources_fallback-pkg has one import ('sources_fallback') inferred from # SOURCES.txt (top_level.txt and installed-files.txt is missing) assert import_names_from_package('sources_fallback-pkg') == {'sources_fallback'} + + +class EditableDistributionTest(fixtures.DistInfoPkgEditable): + def test_origin(self): + dist = Distribution.from_name('distinfo-pkg') + assert dist.origin.url.endswith('.whl') + assert dist.origin.archive_info.hashes.sha256