Fistro
A fixture generator based on type annotations.
Examples
from dataclasses import dataclass
from datetime import datetime, date
from typing import List
from fistro.fistro import generate
@dataclass
class Employee:
id: int
birthday: date
last_access: datetime
password: str
number_plates: List[int]
name: str = 'Carlos Sánchez'
employee = generate(Employee)()
print(employee)
It will show something like this:
Employee(id=5809893100, birthday=datetime.date(559, 3, 6), last_access=datetime.datetime(1053, 8, 29, 19, 11, 14), password="iFZ>?)V0'", number_plates=[85863115, 3528889142, 2818728907, 6043092538, 4985672707], name='Carlos Sánchez')
generate function can be called with to_json or to_dict
boolean pararameters to return json or dict
representation respectively:
class AreaOfCompany(BaseModel):
enable: bool
riskOwner: str
description: str
name: str
code: str
print(fistro.generate(AreaOfCompany, as_dict=True))
>>> {'enable': True, 'riskOwner': 'LqPqS\x0c{kZ', 'description': 'k1917GvOV', 'name': '`;ORxzQ7i', 'code': 'w2 |P\rEps'}
print(fistro.generate(AreaOfCompany, as_json=True))
>>> {"enable": true, "riskOwner": "h@Ij34u?H", "description": ",R,G%0<y#", "name": "K4.\u000b:lK!}", "code": "fvitVYrk3"}
Another useful functions are generate_from_json and get_class_body_from_annotations:
from json import loads
from fistro.fistro import generate_from_json, get_class_body_from_annotations
specific_str = """{
"_id": "5ae09b3947467b00111e7bf6",
"localExposure": 0,
"answer": "mitigate",
"idRisk": "5ae09b3947467b00111e7bf6",
"version": 4,
"country": "BR",
"company": "0185",
"currency": "BRL",
"zone": "DIRT8",
"internalRef": "RSP-BR-0185-DIRT8-105",
"creationDate": "2017-12-13T23:00:00.000Z",
"title": "Tributário: Contribuições Previdenciárias sobre Plano de Stock Options",
"riskCategory": {
"es": "22. Contingencias tributarias",
"en": "22. Tax contingencies",
"pt": "22. Contingências Fiscais"
},
"evaluationType": "quantitative",
"basicRef": "26376309-2cc2-4a0d-9c6a-373e0a7d9043",
"localQUANTITATIVENetCASHFLOW": 0,
"euroQUANTITATIVENetCASHFLOW": 0,
"localQUANTITATIVEGrossCASHFLOW": 241000000,
"euroQUANTITATIVEGrossCASHFLOW": 57324742,
"probability": "veryPossible",
"status": "open",
"commissionApproval": false,
"companyRegistry": true,
"companyCode": "0185",
"IDNotification": "0aa0370e-e6d6-405c-a619-a47da0602dee",
"localQUANTITATIVEGrossOIBDA": 241000000,
"localQUANTITATIVEGrossCAPEX": 0,
"localQUANTITATIVENetOIBDA": 0,
"localQUANTITATIVENetCAPEX": 0,
"euroQUANTITATIVEGrossOIBDA": 57324742,
"euroQUANTITATIVEGrossCAPEX": 0,
"euroQUANTITATIVENetOIBDA": 0,
"euroQUANTITATIVENetCAPEX": 0,
"hierarchy": "principal",
"hierarchySubsidiaries": [],
"owner": "Vasco Gruber"
}"""
specific_json = loads(specific_str)
the_class = generate_from_json(specific_json)
print(get_class_body_from_annotations(the_class.__annotations__))
It will print:
_id: str
localExposure: int
answer: str
idRisk: str
version: int
country: str
company: str
currency: str
zone: str
internalRef: str
creationDate: str
title: str
riskCategory: typing.Dict[str, str]
evaluationType: str
basicRef: str
localQUANTITATIVENetCASHFLOW: int
euroQUANTITATIVENetCASHFLOW: int
localQUANTITATIVEGrossCASHFLOW: int
euroQUANTITATIVEGrossCASHFLOW: int
probability: str
status: str
commissionApproval: bool
companyRegistry: bool
companyCode: str
IDNotification: str
localQUANTITATIVEGrossOIBDA: int
localQUANTITATIVEGrossCAPEX: int
localQUANTITATIVENetOIBDA: int
localQUANTITATIVENetCAPEX: int
euroQUANTITATIVEGrossOIBDA: int
euroQUANTITATIVEGrossCAPEX: int
euroQUANTITATIVENetOIBDA: int
euroQUANTITATIVENetCAPEX: int
hierarchy: str
hierarchySubsidiaries: typing.List[typing.Any]
owner: str
Installation
pip install fistro
Credits
In memoriam of Chiquito de la Calzada.
Metadata
Release files for fistro 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fistro-0.3.0.tar.gz | 8.7 kB | Without provenance | Details for fistro-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fistro-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for fistro-0.3.0-py3-none-any.whl |
Total release size: 16.7 kB
Release files / fistro-0.3.0.tar.gz
| Download URL | fistro-0.3.0.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ebb20642f694716897a5b7a8e5cf078cc396e4931ec51aec8f0fd3a8e3f6f5e8
|
|
BLAKE2b-256 checksum How to use checksums |
8e37561823bf96145d8b67e1eae23ae2dc5b02edcfff905f40991aee8161297c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.10.0 Linux/5.10.60.1-microsoft-standard-WSL2
|
Release files / fistro-0.3.0-py3-none-any.whl
| Download URL | fistro-0.3.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e1661766cca0d001b3b25129e439f0f1e249dab287f2ada4b7a5ec3decee1e4
|
|
BLAKE2b-256 checksum How to use checksums |
8340a69580f86299f050b2c72e2d4b7913c01f7802a929064ca9439bbb6eeeb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.10.0 Linux/5.10.60.1-microsoft-standard-WSL2
|
Security for fistro 0.3.0
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.