Skip to content

Commit

Permalink
Tests for setup.cfg.
Browse files Browse the repository at this point in the history
  • Loading branch information
amjith committed Nov 13, 2024
1 parent 1d4750e commit 8800b8c
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
79 changes: 79 additions & 0 deletions metadata_please/source_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,41 @@ def from_poetry_checkout(path: Path) -> bytes:
if name:
buf.append(f"Name: {name}\n")

# Version
version = doc.get("tool", {}).get("poetry", {}).get("version")
if version:
buf.append(f"Version: {version}\n")

# Requires-Python
requires_python = doc.get("tool", {}).get("poetry", {}).get("requires-python")
if requires_python:
buf.append(f"Requires-Python: {requires_python}\n")

# Project-URL
url = doc.get("tool", {}).get("poetry", {}).get("homepage")
if url:
buf.append(f"Home-Page: {url}\n")

# Author
authors = doc.get("tool", {}).get("poetry", {}).get("authors")
if authors:
buf.append(f"Author: {authors}\n")

# Summary
summary = doc.get("tool", {}).get("poetry", {}).get("description")
if summary:
buf.append(f"Summary: {summary}\n")

# Description
description = doc.get("tool", {}).get("poetry", {}).get("readme")
if description:
buf.append(f"Description: {description}\n")

# Keywords
keywords = doc.get("tool", {}).get("poetry", {}).get("keywords")
if keywords:
buf.append(f"Keywords: {keywords}\n")

return "".join(buf).encode("utf-8")


Expand All @@ -265,6 +300,50 @@ def from_setup_cfg_checkout(path: Path) -> bytes:
except (NoOptionError, NoSectionError):
pass

# Requires-Python
try:
buf.append(f"Requires-Python: {rc.get('options', 'python_requires')}\n")
except (NoOptionError, NoSectionError):
pass

# Home-Page
try:
buf.append(f"Home-Page: {rc.get('metadata', 'url')}\n")
except (NoOptionError, NoSectionError):
pass

# Author
try:
buf.append(f"Author: {rc.get('metadata', 'author')}\n")
except (NoOptionError, NoSectionError):
pass

# Author-Email
try:
buf.append(f"Author-Email: {rc.get('metadata', 'author_email')}\n")
except (NoOptionError, NoSectionError):
pass

# Summary
try:
buf.append(f"Summary: {rc.get('metadata', 'description')}\n")
except (NoOptionError, NoSectionError):
pass

# Description
try:
buf.append(f"Description: {rc.get('metadata', 'long_description')}\n")
except (NoOptionError, NoSectionError):
pass

# Description-Content-Type
try:
buf.append(
f"Description-Content-Type: {rc.get('metadata', 'long_description_content_type')}\n"
)
except (NoOptionError, NoSectionError):
pass

try:
for dep in rc.get("options", "install_requires").splitlines():
dep = dep.strip()
Expand Down
57 changes: 57 additions & 0 deletions metadata_please/tests/source_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_pep621_fields(self) -> None:
self.assertEqual("['farm', 'animals']", rv.keywords)
self.assertEqual(None, rv.long_description_content_type)
self.assertEqual("README.md", rv.description)
self.assertEqual(">=3.7", rv.requires_python)

def test_pep621_extras(self) -> None:
with tempfile.TemporaryDirectory() as d:
Expand All @@ -68,6 +69,32 @@ def test_pep621_extras(self) -> None:
)
self.assertEqual(frozenset({"dev", "marker"}), rv.provides_extra)

def test_poetry_fields(self) -> None:
with tempfile.TemporaryDirectory() as d:
Path(d, "pyproject.toml").write_text(
"""\
[tool.poetry]
name = "somepkg"
version = "1.2.30"
description = "Example Summary"
authors = ["chicken <[email protected]>"]
readme = "README.md"
keywords = ["farm", "animals"]
homepage = "https://example.com"
"""
)
rv = basic_metadata_from_source_checkout(Path(d))
self.assertEqual("somepkg", rv.name)
self.assertEqual("1.2.30", rv.version)
self.assertEqual("Example Summary", rv.summary)
self.assertEqual("https://example.com", rv.url)
self.assertEqual({}, rv.project_urls)
self.assertEqual("['chicken <[email protected]>']", rv.author)
self.assertEqual("['farm', 'animals']", rv.keywords)
self.assertEqual(None, rv.long_description_content_type)
self.assertEqual("README.md", rv.description)
self.assertEqual(None, rv.requires_python)

def test_poetry_full(self) -> None:
with tempfile.TemporaryDirectory() as d:
Path(d, "pyproject.toml").write_text(
Expand Down Expand Up @@ -190,3 +217,33 @@ def test_setuptools_extras(self) -> None:
frozenset({"dev", "marker"}),
rv.provides_extra,
)

def test_setuptools_cfg_fields(self) -> None:
with tempfile.TemporaryDirectory() as d:
Path(d, "setup.cfg").write_text(
"""\
[metadata]
name = somepkg
description = Example Summary
long_description = file: README.md
long_description_content_type = text/markdown
license = MIT
url = https://example.com
author = chicken
author_email = [email protected]
[options]
python_requires = >=3.7
"""
)
rv = basic_metadata_from_source_checkout(Path(d))
self.assertEqual("somepkg", rv.name)
self.assertEqual(None, rv.version)
self.assertEqual("Example Summary", rv.summary)
self.assertEqual("https://example.com", rv.url)
self.assertEqual("chicken", rv.author)
self.assertEqual("[email protected]", rv.author_email)
self.assertEqual(None, rv.keywords)
self.assertEqual("file: README.md", rv.description)
self.assertEqual(">=3.7", rv.requires_python)
self.assertEqual("text/markdown", rv.long_description_content_type)

0 comments on commit 8800b8c

Please sign in to comment.