Skip to main content

fauxgen

A factory method generator that streamlines test data creation by automating field value generation.

Overview

Testing classes with numerous fields often requires extensive boilerplate code. fauxgen addresses this challenge by automatically generating factory methods from class definitions, significantly reducing test code complexity.

Currently supports pandera.DataFrameModel with plans for future expansions.

Quick Start

uv add fauxgen
uv run fauxgen gen --module-dir <your_module>

Usage Example

Example project can be found in the examples.

Traditional Approach (Without fauxgen)

Testing DataFrame models traditionally requires explicit specification of all fields, even when testing a single validation:

import pandera as pa
from pandera.typing import Series

class UserSchema(pa.DataFrameModel):
    id: Series[int] = pa.Field(ge=1)
    age: Series[int] = pa.Field(ge=0, le=150)
    name: Series[str] = pa.Field()
    email: Series[str] = pa.Field(nullable=True)
    active: Series[bool] = pa.Field()

def test_user_registration():
    # Forced to specify every field when testing age validation
    df_user = pd.DataFrame([
        {
            "id": 1,            # Unrelated to test
            "age": 151,         # Actual test target
            "name": "test",     # Unrelated to test
            "email": "test@example.com",  # Unrelated to test
            "active": True,     # Unrelated to test
        },
    ]).pipe(DataFrame[UserSchema])
    # Test age validation...

Simplified Testing (With fauxgen)

fauxgen generates factory methods that enable focused testing by automatically handling irrelevant fields:

from .factories import user_schema_record  # Generated by fauxgen

def test_user_registration():
    # Focus solely on the field under test
    # Other fields are automatically populated with valid values
    df_user = pd.DataFrame([
        user_schema_record(age=151), # Set specific age for test
    ]).pipe(DataFrame[UserSchema])  # Test age validation...

def test_user_email_optional():
    # Effortlessly test specific scenarios
    # without worrying about irrelevant fields
    df_user = pd.DataFrame([
        user_schema_record(email=None)  # Set email to None for test
    ]).pipe(DataFrame[UserSchema])  # Test nullable email...

How It Works

Input: pandera.DataFrameModel Definition

import pandera as pa
from pandera.typing import Series

class TestSchema(pa.DataFrameModel):
    int_col: Series[int] = pa.Field(ge=0.1, le=10.0)
    float_col_only_ge: Series[float] = pa.Field(ge=10)
    float_col_only_le: Series[float] = pa.Field(le=10)
    pa_bool_col: Series[pa.Bool] = pa.Field(nullable=True)

Output: Generated Factory Method

import fauxgen as f

class TestSchemaRecord(TypedDict):
    int_col: int
    float_col_only_ge: float
    float_col_only_le: float
    pa_bool_col: bool | None

def test_schema_record(
    *,
    int_col: int | f.Unset = f.UNSET,
    float_col_only_ge: float | f.Unset = f.UNSET,
    float_col_only_le: float | f.Unset = f.UNSET,
    pa_bool_col: bool | None | f.Unset = f.UNSET,
    seed_: int | None = None,
) -> TestSchemaRecord:
    return {
        "int_col": f.Unset.unwrap_or_else(int_col, lambda: f.gen_int(ge=0.1, le=10, seed=seed_)),
        "float_col_only_ge": f.Unset.unwrap_or_else(float_col_only_ge, lambda: f.gen_float(ge=10, le=110, seed=seed_)),
        "float_col_only_le": f.Unset.unwrap_or_else(float_col_only_le, lambda: f.gen_float(ge=-90, le=10, seed=seed_)),
        "pa_bool_col": f.Unset.unwrap_or_else(pa_bool_col, lambda: f.gen_bool(seed=seed_)),
    }

Key Features

  1. Enhanced Type Safety:

    • Leverages TypedDict for comprehensive type checking
    • Provides full IDE support with type hints and autocompletion
  2. Intelligent Field Generation:

    • Selectively override specific fields while auto-generating others
    • Maintains data integrity through validation-aware value generation
  3. Validation-Aware Generation:

    • Automatically respects field constraints (ge, le, etc.)
    • Properly handles optional fields with nullable support

Release files for fauxgen 0.3.1

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

Built distributions (wheels)

Table of built distributions (wheels) for fauxgen 0.3.1
File
fauxgen-0.3.1-py3-none-musllinux_1_1_x86_64.whl Python 3 none Linux musl 1.1+ x86-64 Details
fauxgen-0.3.1-py3-none-musllinux_1_1_armv7l.whl Python 3 none Linux musl 1.1+ ARMv7l Details
fauxgen-0.3.1-py3-none-musllinux_1_1_aarch64.whl Python 3 none Linux musl 1.1+ ARM64 Details
fauxgen-0.3.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details
fauxgen-0.3.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl Python 3 none Linux glibc 2.17+ IBM System/390x Details
fauxgen-0.3.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl Python 3 none Linux glibc 2.17+ PowerPC 64-le Details
fauxgen-0.3.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl Python 3 none Linux glibc 2.17+ x86-32 Details
fauxgen-0.3.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl Python 3 none Linux glibc 2.17+ ARMv7l Details
fauxgen-0.3.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details
fauxgen-0.3.1-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details
fauxgen-0.3.1-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details

Total release size: 24.3 MB

Release files / fauxgen-0.3.1-py3-none-musllinux_1_1_x86_64.whl

Download URL fauxgen-0.3.1-py3-none-musllinux_1_1_x86_64.whl
Size 2.3 MB
Tags Linux musl 1.1+ x86-64 Python 3
SHA-256 checksum
How to use checksums
016c895ca0024494781ce25ead660717bfa8827984147626ac7cb73b1275a289
BLAKE2b-256 checksum
How to use checksums
c4ae2f2e4cbceab40e25a95a956eefa1994b6fc2d37e6658f28b2e603e23fdfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / fauxgen-0.3.1-py3-none-musllinux_1_1_armv7l.whl

Download URL fauxgen-0.3.1-py3-none-musllinux_1_1_armv7l.whl
Size 2.0 MB
Tags Linux musl 1.1+ ARMv7l Python 3
SHA-256 checksum
How to use checksums
34b42a66e5f60f7cde0d6bd4c40afa5f2970152863001c2f4c608e7ebf8527fd
BLAKE2b-256 checksum
How to use checksums
9f500f3de684557a7913f54b157c9cda076fe3ffb5aa39a94a1b65df512f33aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / fauxgen-0.3.1-py3-none-musllinux_1_1_aarch64.whl

Download URL fauxgen-0.3.1-py3-none-musllinux_1_1_aarch64.whl
Size 2.1 MB
Tags Linux musl 1.1+ ARM64 Python 3
SHA-256 checksum
How to use checksums
133edf35a7b219d968ba1dcdfb3f07cc35e829cdcfc12d656f39bbe1756339aa
BLAKE2b-256 checksum
How to use checksums
acf2ee3dfd424872aad481fefc24e0c0d5c7cb7d9f2109db44ba4a9b608bbc8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / fauxgen-0.3.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fauxgen-0.3.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.3 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
92fc2989b84727a1119777aa89ba73206a2eee47c5a693b75ea909fe77065765
BLAKE2b-256 checksum
How to use checksums
bef29467e479f381cc01a0ecc0164353b4c5d752f12baf6901f61fdf2befc14c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / fauxgen-0.3.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL fauxgen-0.3.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 2.4 MB
Tags Linux glibc 2.17+ IBM System/390x Python 3
SHA-256 checksum
How to use checksums
7b26c093d451a773b7d01b7306adafe32de2f4212099268504edda7a8bf18b90
BLAKE2b-256 checksum
How to use checksums
617c0d6b456de988a73f9e1d8ed0868d3db1e1f9c4b5934fbcc423cd84a57206
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / fauxgen-0.3.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL fauxgen-0.3.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 2.6 MB
Tags Linux glibc 2.17+ PowerPC 64-le Python 3
SHA-256 checksum
How to use checksums
2b9a94a43cf743f4b9bbc4d5cf62c82fad9bd3edce3874ca026fd51071f33da3
BLAKE2b-256 checksum
How to use checksums
3b8f6c6e3088753c304fe3aea4df89e38733c8532eb5afdb232b9d74ac5c836a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / fauxgen-0.3.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL fauxgen-0.3.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Size 2.3 MB
Tags Linux glibc 2.17+ x86-32 Python 3
SHA-256 checksum
How to use checksums
91455447f5d4df32da81f27acca7f0428e9d7fe266eaa95304d50d17c8c2dc83
BLAKE2b-256 checksum
How to use checksums
8bb7f9941c2b5c4c508b184107901872af56765e7a2842c0efb83ef20d016b79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / fauxgen-0.3.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL fauxgen-0.3.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 2.0 MB
Tags Linux glibc 2.17+ ARMv7l Python 3
SHA-256 checksum
How to use checksums
fab4b1611132d182a6e73e8a726b3a0eaf1c2be81115e42521b53466359a3af3
BLAKE2b-256 checksum
How to use checksums
93d8202a5b5f38857ac290f17d48162e8aec8ab0194e4e7a7b1ce44f145fafaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / fauxgen-0.3.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL fauxgen-0.3.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.1 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
60c837adfd9559ba859c78309c4d0fbea812052a359ce36cf73ebd99a0b6dc24
BLAKE2b-256 checksum
How to use checksums
d1d93ae95670c4e42397d36b1f9b82c72291bda497c741dd5be9cdbfdb50d05b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / fauxgen-0.3.1-py3-none-macosx_11_0_arm64.whl

Download URL fauxgen-0.3.1-py3-none-macosx_11_0_arm64.whl
Size 2.1 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0e9754c822eed76d68e1db36d49a47a39ca8501082bb728f65370949faecd793
BLAKE2b-256 checksum
How to use checksums
e70e191662c0d5a58c95e3f225f26e7a1e0e765c80a5aa2650574980619c7ff7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / fauxgen-0.3.1-py3-none-macosx_10_12_x86_64.whl

Download URL fauxgen-0.3.1-py3-none-macosx_10_12_x86_64.whl
Size 2.2 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
448d01fb186caa4798ba53340c83cd0190a352985e4cf4b57b5af60ca5d6d001
BLAKE2b-256 checksum
How to use checksums
74caa2f78b9fc90513f5e6af0fe5c15457815ad8221b60f738fefe79200fd0fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.3.1 This release

11 release files

0.2.2

11 release files

0.2.0

11 release files

0.1.1

11 release files

0.1.0

11 release files

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