CodeSampleX

Sample

openpyxl 3.0.7: styles.Alignment

Verified sample for pypi openpyxl 3.0.7: styles.Alignment. The contract ran on python 3.12 · linux debian/x64 · docker and passed.

sha256:e9afd768156ee95095eb9d9841c5d97699e1e0ed8fbfcbf5e472350340be43a9

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 pip

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify openpyxl.styles.Alignment in pkg:pypi/openpyxl@3.0.7
Packages
Symbols
  • openpyxl.styles.Alignment
Created
2026-10-14T07:54:25Z

Contract

  1. openpyxl.styles.Alignment configures horizontal, vertical, text_rotation, wrap_text, shrink_to_fit, indent, and readingOrder attributes and rejects invalid enum values
  2. openpyxl.styles.Alignment supports combining instances with + and round-tripping via to_tree() and from_tree()
  3. Cell Alignment styles persist across Workbook.save() and load_workbook() in-memory .xlsx serialization

Files

  • PROMPT.md
  • csx.json
  • requirements.txt
  • sample.py
  • spec.json
  • test/contract.py

Download the source artifact (tar.gz)

Source

PROMPT.md
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.
csx.json
{"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"}
requirements.txt
et-xmlfile==2.0.0
openpyxl==3.0.7
sample.py
"""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,
    }
spec.json
{
  "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"
  ]
}
test/contract.py
"""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()

Origin Seeder

anonymous