Port of golang's txtar, a trivial tar-like format for unit tests
Project description
txtar
txtar is a Python reimplementation of Go's txtar format, a tool for bundling and managing multiple text files in a single archive.
Features
- Parse
txtarformatted text into structured data. - Serialize structured data back into
txtarformat. - Unpack
txtararchives into the file system.
Usage
In unit tests
from pathlib import Path
import os
def test_my_function():
# Define the txtar structure for sysfs-like files
txtar_content = """
-- sys/class/thermal/thermal_zone0/temp --
55000
-- sys/class/power_supply/BAT0/capacity --
45
-- sys/block/sda/size --
1024000
"""
with MockFS.from_string(txtar_content):
assert os.path.exists("/sys/class/thermal/thermal_zone0/temp")
assert os.path.exists("/sys/class/power_supply/BAT0/capacity")
assert os.path.exists("/sys/block/sda/size")
assert Path("/sys/block/sda/size").exists()
Reading a file
from txtar import TxTar
content = "..." # txtar formatted string
archive = TxTar.parse(content)
Serializing to txtar Format
from txtar import TxTar, File
archive = TxTar(
comments=["Example txtar archive"],
files=[File(name="example.txt", lines=["Hello", "World"])]
)
content = archive.serialize()
Unpacking an Archive
from pathlib import Path
from txtar import TxTar
archive = TxTar.parse("...")
archive.unpack_in(Path("/path/to/unpack"))
Development
- Install dependencies:
poetry install - Run tests with
pytest.
Releasing
poetry publish --build --username __token__ --password $PYPI_PASSWORD
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
txtar-0.1.1.tar.gz
(2.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
txtar-0.1.1-py3-none-any.whl
(2.8 kB
view details)
File details
Details for the file txtar-0.1.1.tar.gz.
File metadata
- Download URL: txtar-0.1.1.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.11.4 Linux/6.2.0-32-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1c0065e8538cd891518fa3f703fdf8f6e2a1be59032ee8c9602118de0a73726
|
|
| MD5 |
8c3f91770864e06ae2af9d2c269797d2
|
|
| BLAKE2b-256 |
f25a74eeed94bc8babf0a2b472d6869e8b792e106cef1bbdce0187778d7196d0
|
File details
Details for the file txtar-0.1.1-py3-none-any.whl.
File metadata
- Download URL: txtar-0.1.1-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.11.4 Linux/6.2.0-32-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed21701cd8418466cf60387c0eac4d300cfccf0de2aa7309850f0790946c3f6a
|
|
| MD5 |
dae74b93fb0f4ff44d6e1ceb2fcc4efc
|
|
| BLAKE2b-256 |
b4a203ac1dd484b8fab77fed0bf72fcf52768a987f101b828078a93cd237e872
|