Skip to main content

txtest

Unit tests for written content.

txtest evaluates a text file against criteria you define with the OpenAI Decisions API. Each test produces a PASS, FAIL, or ERROR, with a short description and its value and threshold shown in the terminal.

Installation

Requires Python 3.11 or later. Install from PyPI:

python -m pip install --upgrade txtest

The CLI is included in version 0.0.2 and later. Run txtest --help to check the installation.

Set OPENAI_API_KEY in your environment or create a .env file:

OPENAI_API_KEY=your-api-key

txtest looks for .env in the current directory and its parents. An existing environment variable takes precedence.

Quickstart

The repository includes a fictional library desk-reservation policy and two demonstration tests:

To try these examples, download their files by cloning the repository:

git clone https://github.com/ThiNepo/txtest.git
cd txtest

From the repository root, run:

txtest examples/reservation-policy.md --set policies

This evaluates the complete policy with every .txtest file in txtests/policies/, in filename order. Each test makes one request, sequentially, without automatic retries. A failed test or an API error does not stop the remaining tests. Results stay in the terminal.

For a demonstration of missing information, try the incomplete policy:

txtest examples/reservation-policy-incomplete.md --set policies

Its cancellation procedure is deliberately missing, so the cancellation test is intended to produce FAIL. Scores and probabilities are model judgments and may vary between runs; these examples do not prescribe fixed output values.

The module entry point works too:

python -m txtest examples/reservation-policy.md --set policies

Selecting blocks

Use --block TYPE:VALUE to evaluate one reading of a file with conditional content.

txtest guide.md --set guides --block language:cpp

Write [TYPE VALUE] and [endTYPE] on their own lines. This command keeps the shared text and the body of each [language cpp] block. It removes the markers and skips other language blocks. Blocks of types you do not select stay as written, and markers inside fenced code are literal text.

Repeat --block to select more than one value or type. For example, --block language:cpp --block language:python --block audience:beginner keeps both programming languages and selects the beginner audience. A nested block is visible only when its enclosing blocks are visible. Without --block, the full file is evaluated.

Writing tests

Keep each test in txtests/<set>/<name>.txtest. Sets are resolved from the current directory, and the input is one UTF-8 text file.

A test contains YAML frontmatter followed by Jinja templates in <system> and <user> blocks. For example:

---
description: Explains how to cancel a reservation.
type: predicate
min_probability: 0.5
---
<system>
Does the policy give the reader a concrete procedure for cancelling a reservation?
</system>

<user>
{{ text }}
</user>

description is required and appears beside the result so the reader can understand what was checked. The <system> block becomes the question instructions; the rendered <user> block becomes the text evaluated by that question.

The templates have three variables:

Variable Value
text The input text after applying any --block filters.
filename The input file's name.
path The input path provided to the command.

An undefined Jinja variable produces a test error before a request is made.

Predicate tests

Use type: predicate for a yes/no condition. The result is the model's estimated probability that the condition is true, from 0 to 1. The test passes when the probability is at least min_probability, which defaults to 0.5. Probabilities and their thresholds appear as percentages in the terminal.

Score tests

Use type: score for a rubric with exactly five levels, ordered from lowest to highest. Each entry in levels needs a unique string label and a nonempty description. See the complete policy clarity test for a concrete rubric.

The result uses a 1–5 scale: the API's zero-based score is shifted by one. Fractional scores are preserved and compared with min_score, which defaults to 4, without rounding first. A score equal to the minimum passes. Each test passes or fails independently.

score is the default type when type is omitted. Predicate tests use min_probability; score tests use min_score and levels.

The accepted frontmatter fields are description, type, min_probability, min_score, levels, and model. This implementation uses gpt-6-luna by default and accepts that same value if model is explicitly set.

Exit codes

Code Meaning
0 All tests passed.
1 At least one test failed, with no execution errors.
2 A configuration, input, API, or response error occurred.

A model refusal is an error. An empty or missing test set is also an error.

Development

Run the offline test suite with:

python -m unittest discover -s tests -v

Build and publish

Install the build tool once with python -m pip install build. From the repository root, start with an empty dist/ directory and run the build.

python -m build

The build creates a wheel (.whl) and a source distribution (.tar.gz) in dist/. To publish them to PyPI, run the upload separately.

twine upload dist/*

License

Apache-2.0. See LICENSE.

Metadata

Release files for txtest 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for txtest 0.0.3
File Size Uploaded Provenance Actions
txtest-0.0.3.tar.gz 24.0 kB Without provenance Details for txtest-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for txtest 0.0.3
File Interpreter ABI Platform Actions
txtest-0.0.3-py3-none-any.whl Python 3 none any Details for txtest-0.0.3-py3-none-any.whl

Total release size: 41.0 kB

Release files / txtest-0.0.3.tar.gz

Download URL txtest-0.0.3.tar.gz
Size 24.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1b69ff25d6966c65830ad99512cbfa2edf169fa396c52381e121ad23355b8ad9
BLAKE2b-256 checksum
How to use checksums
c1a6098f548a6facf420751ee4c239f4449572892e66a0ea26a3bea1fbb7a79a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / txtest-0.0.3-py3-none-any.whl

Download URL txtest-0.0.3-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c085c601806e8f7a05c8a1a421d62d4f74ddf51c7e768f685882e70d46f606a
BLAKE2b-256 checksum
How to use checksums
77307863dbdf09c7ed52670105ee684e115c8e759ab96dae2a87cd0eca64a448
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for txtest 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page