示例
openpyxl 3.0.7: styles.Alignment
已验证示例 — pypi openpyxl 3.0.7: styles.Alignment. contract 在 python 3.12 · linux debian/x64 · docker 上运行并通过: openpyxl.styles.Alignment configures horizontal…
sha256:e9afd768156ee95095eb9d9841c5d97699e1e0ed8fbfcbf5e472350340be43a9
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 pip
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104… |
2026-10-14 |
案例
HOW- 目标
- verify openpyxl.styles.Alignment in pkg:pypi/openpyxl@3.0.7
- 符号
-
- openpyxl.styles.Alignment
- 创建时间
- 2026-10-14T07:54:25Z
契约
- openpyxl.styles.Alignment configures horizontal, vertical, text_rotation, wrap_text, shrink_to_fit, indent, and readingOrder attributes and rejects invalid enum values
- openpyxl.styles.Alignment supports combining instances with + and round-tripping via to_tree() and from_tree()
- Cell Alignment styles persist across Workbook.save() and load_workbook() in-memory .xlsx serialization
文件
- PROMPT.md
- csx.json
- requirements.txt
- sample.py
- spec.json
- test/contract.py
源代码
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify openpyxl.styles.Alignment in pkg:pypi/openpyxl@3.0.7
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:pypi/openpyxl@3.0.7
Demonstrate these symbols/APIs:
- openpyxl.styles.Alignment
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:00a3a428163ca0d21351572b1efb5593f345825c6de97e48e0c64e95abed824b","contract":["openpyxl.styles.Alignment configures horizontal, vertical, text_rotation, wrap_text, shrink_to_fit, indent, and readingOrder attributes and rejects invalid enum values","openpyxl.styles.Alignment supports combining instances with + and round-tripping via to_tree() and from_tree()","Cell Alignment styles persist across Workbook.save() and load_workbook() in-memory .xlsx serialization"],"goal":"verify openpyxl.styles.Alignment in pkg:pypi/openpyxl@3.0.7","kind":"HOW","packages":["pkg:pypi/openpyxl@3.0.7"],"schemaVersion":1,"symbols":["openpyxl.styles.Alignment"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/openpyxl@3.0.7"],"schemaVersion":1,"subject":"pkg:pypi/openpyxl@3.0.7","symbols":["openpyxl.styles.Alignment"],"verifierAdapter":"python@1"}
et-xmlfile==2.0.0
openpyxl==3.0.7
"""Demonstration of cell alignment configuration and serialization using openpyxl.styles.Alignment."""
from io import BytesIO
from typing import Dict
from openpyxl import Workbook, load_workbook
from openpyxl.styles import Alignment
def create_alignments() -> Dict[str, Alignment]:
"""Create Alignment configurations covering horizontal, vertical, text rotation, wrapping, and indentation."""
return {
"header": Alignment(
horizontal="center",
vertical="center",
text_rotation=45,
wrap_text=True,
shrink_to_fit=False,
indent=0,
),
"body": Alignment(
horizontal="left",
vertical="top",
wrap_text=True,
indent=2,
),
"compact": Alignment(
horizontal="right",
vertical="bottom",
shrink_to_fit=True,
readingOrder=2,
),
}
def merge_alignments(base: Alignment, overlay: Alignment) -> Alignment:
"""Combine two Alignment instances using the + operator and round-trip through XML tree representation."""
merged = base + overlay
xml_node = merged.to_tree()
return Alignment.from_tree(xml_node)
def serialize_and_load_alignments() -> Dict[str, Alignment]:
"""Apply Alignment styles to worksheet cells, save to an in-memory .xlsx stream, and reload."""
wb = Workbook()
ws = wb.active
ws.title = "AlignmentSheet"
alignments = create_alignments()
ws["A1"] = "Header Title"
ws["A1"].alignment = alignments["header"]
ws["B2"] = "Indented wrapped paragraph text"
ws["B2"].alignment = alignments["body"]
ws["C3"] = "12345.67"
ws["C3"].alignment = alignments["compact"]
stream = BytesIO()
wb.save(stream)
stream.seek(0)
loaded_wb = load_workbook(stream)
loaded_ws = loaded_wb["AlignmentSheet"]
return {
"header": loaded_ws["A1"].alignment,
"body": loaded_ws["B2"].alignment,
"compact": loaded_ws["C3"].alignment,
}
{
"schemaVersion": 1,
"goal": "verify openpyxl.styles.Alignment in pkg:pypi/openpyxl@3.0.7",
"kind": "HOW",
"packages": [
"pkg:pypi/openpyxl@3.0.7"
],
"symbols": [
"openpyxl.styles.Alignment"
]
}
"""Contract verification test for openpyxl.styles.Alignment."""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from openpyxl.styles import Alignment
import sample
def test_alignment_attributes_and_validation() -> None:
"""Assertion 1: openpyxl.styles.Alignment configures horizontal, vertical, text_rotation, wrap_text, shrink_to_fit, indent, and readingOrder attributes and rejects invalid enum values."""
alignments = sample.create_alignments()
header = alignments["header"]
assert isinstance(header, Alignment)
assert header.horizontal == "center"
assert header.vertical == "center"
assert header.text_rotation == 45
assert header.wrap_text is True
assert header.shrink_to_fit is False
assert header.indent == 0
body = alignments["body"]
assert body.horizontal == "left"
assert body.vertical == "top"
assert body.wrap_text is True
assert body.indent == 2
compact = alignments["compact"]
assert compact.horizontal == "right"
assert compact.vertical == "bottom"
assert compact.shrink_to_fit is True
assert compact.readingOrder == 2
# Verify alias wrapText / shrinkToFit / textRotation properties
assert header.wrapText is True
assert compact.shrinkToFit is True
assert header.textRotation == 45
# Verify invalid horizontal alignment raises ValueError
raised = False
try:
Alignment(horizontal="invalid_direction")
except ValueError:
raised = True
assert raised is True
def test_alignment_merge_and_xml_roundtrip() -> None:
"""Assertion 2: openpyxl.styles.Alignment supports combining instances with + and round-tripping via to_tree() and from_tree()."""
base = Alignment(horizontal="justify", indent=3)
fallback = Alignment(horizontal="left", vertical="center", wrap_text=True, indent=1)
merged = sample.merge_alignments(base, fallback)
assert isinstance(merged, Alignment)
assert merged.horizontal == "justify"
assert merged.vertical == "center"
assert merged.wrap_text is True
assert merged.indent == 3
# Original instances remain untouched
assert base.vertical is None
assert fallback.horizontal == "left"
assert base != merged
assert dict(merged) == {
"horizontal": "justify",
"vertical": "center",
"wrapText": "1",
"indent": "3",
}
def test_alignment_workbook_roundtrip() -> None:
"""Assertion 3: Cell Alignment styles persist across Workbook.save() and load_workbook() in-memory .xlsx serialization."""
loaded = sample.serialize_and_load_alignments()
header = loaded["header"]
assert header.horizontal == "center"
assert header.vertical == "center"
assert header.text_rotation == 45
assert header.wrap_text is True
body = loaded["body"]
assert body.horizontal == "left"
assert body.vertical == "top"
assert body.wrap_text is True
assert body.indent == 2
compact = loaded["compact"]
assert compact.horizontal == "right"
assert compact.vertical == "bottom"
assert compact.shrink_to_fit is True
assert compact.readingOrder == 2
def main() -> None:
test_alignment_attributes_and_validation()
test_alignment_merge_and_xml_roundtrip()
test_alignment_workbook_roundtrip()
print("All openpyxl.styles.Alignment contract assertions passed.")
if __name__ == "__main__":
main()
原始种子者
匿名