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

Metadata

Release files for fauxgen 0.1.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.1.1
File
fauxgen-0.1.1-py3-none-musllinux_1_1_x86_64.whl Python 3 none Linux musl 1.1+ x86-64 Details
fauxgen-0.1.1-py3-none-musllinux_1_1_armv7l.whl Python 3 none Linux musl 1.1+ ARMv7l Details
fauxgen-0.1.1-py3-none-musllinux_1_1_aarch64.whl Python 3 none Linux musl 1.1+ ARM64 Details
fauxgen-0.1.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details
fauxgen-0.1.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl Python 3 none Linux glibc 2.17+ IBM System/390x Details
fauxgen-0.1.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl Python 3 none Linux glibc 2.17+ PowerPC 64-le Details
fauxgen-0.1.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl Python 3 none Linux glibc 2.17+ x86-32 Details
fauxgen-0.1.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl Python 3 none Linux glibc 2.17+ ARMv7l Details
fauxgen-0.1.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details
fauxgen-0.1.1-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details
fauxgen-0.1.1-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details

Total release size: 22.9 MB

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

Download URL fauxgen-0.1.1-py3-none-musllinux_1_1_x86_64.whl
Size 2.2 MB
Tags Linux musl 1.1+ x86-64 Python 3
SHA-256 checksum
How to use checksums
5d2c7f626a0a8e302baea30ba439c8cc0905f7928ba3700d6a44f9d293d13f05
BLAKE2b-256 checksum
How to use checksums
4927f9bf3d8eb73545922b476088e1a43b3fc6679374bfa1d5f5446268eb832a
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.1.1-py3-none-musllinux_1_1_armv7l.whl

Download URL fauxgen-0.1.1-py3-none-musllinux_1_1_armv7l.whl
Size 1.9 MB
Tags Linux musl 1.1+ ARMv7l Python 3
SHA-256 checksum
How to use checksums
6712e3be563a45ec70c2e0ec9649abd6c23083b18d7d3e7a8819c1ba7691caf6
BLAKE2b-256 checksum
How to use checksums
e7fcd3cf4f032e1d59b408b132799bc2b84bb6f4781c7bbf38220d76d1fc47e1
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.1.1-py3-none-musllinux_1_1_aarch64.whl

Download URL fauxgen-0.1.1-py3-none-musllinux_1_1_aarch64.whl
Size 1.9 MB
Tags Linux musl 1.1+ ARM64 Python 3
SHA-256 checksum
How to use checksums
95a39d55143961e79730ebe998479363cb37bb165bcfd282901e66b33063a9b4
BLAKE2b-256 checksum
How to use checksums
8c50a1e23217b59e1baf776013cfe97fcbc8614e6120f6a912dca353fa82250c
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.1.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fauxgen-0.1.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.1 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
3b38f7e189bdda527936ef7fca4d822a550f64e0d3c199e070aeebee9fad47ae
BLAKE2b-256 checksum
How to use checksums
62a9c2d49d9e3b87a4669e8a3e1c977ff93bbf66be200e28fa780217d09d9841
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.1.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL fauxgen-0.1.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
eec96e94189cbb6b18d5e7b9ba8dedb94808aac434d5f7baacdff24c39847e73
BLAKE2b-256 checksum
How to use checksums
a8340cbdf4252bcb40cf0e9efac7fd3e03f0e6b7c56dfce463accefc9bea7076
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.1.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL fauxgen-0.1.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 2.3 MB
Tags Linux glibc 2.17+ PowerPC 64-le Python 3
SHA-256 checksum
How to use checksums
a5d0d4d215c7b474191255d83154097e101d82a2550d3259647d0a6e0736446c
BLAKE2b-256 checksum
How to use checksums
712c9a7f3627c31020f77a7a0bccaa9e6c416be2922b285f5a2b2d1c1383b795
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.1.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL fauxgen-0.1.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Size 2.2 MB
Tags Linux glibc 2.17+ x86-32 Python 3
SHA-256 checksum
How to use checksums
5cb8c94a2f4248ad11a1760a07415f7b54bf40edcf0ae183cdef6af19e664d4a
BLAKE2b-256 checksum
How to use checksums
2ce8616c6f23f4712adbab109587410a164e9cb2b571e409180a132476899ef7
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.1.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL fauxgen-0.1.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 1.9 MB
Tags Linux glibc 2.17+ ARMv7l Python 3
SHA-256 checksum
How to use checksums
ef953cdbf6b11f752b3f011438d2a8e3468ad7d50c19d5f492378d9d90dff82f
BLAKE2b-256 checksum
How to use checksums
bfc1161d4ec4480baed71d429f50c41b379e697e851111a43a51f939a9fe9b8c
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.1.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL fauxgen-0.1.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.0 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
440a7b775e7fecb7d1042fbe44ea6309e52281c36ee7961883f8bb41052e34e2
BLAKE2b-256 checksum
How to use checksums
a7807c0496f2ac931086e48524015196d94c706761fea4782d93edb2ebe85976
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.1.1-py3-none-macosx_11_0_arm64.whl

Download URL fauxgen-0.1.1-py3-none-macosx_11_0_arm64.whl
Size 1.9 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0c80c0c3dfc68cefe1d440a504ede068ea8a81a322a27f9e087ae1a6f83a0e42
BLAKE2b-256 checksum
How to use checksums
94e6940e62a24f6654daac125824ec1dc0dc9e530b125e0ace259d45262402c9
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.1.1-py3-none-macosx_10_12_x86_64.whl

Download URL fauxgen-0.1.1-py3-none-macosx_10_12_x86_64.whl
Size 2.0 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
7e46cc230aa62d363740540a544de9246979069f1c8b54f61da3495be383ce83
BLAKE2b-256 checksum
How to use checksums
61ca6a7845843770ae83b9392f4479731312ef8a00352de81f31c6646b2bbce3
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

0.3.1

11 release files

0.2.2

11 release files

0.2.0

11 release files

This release

0.1.1 This release

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