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

Total release size: 23.0 MB

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

Download URL fauxgen-0.2.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
78ca0e10e7d3bd3867a69026aa257330fe3a3a456c9613a1c57157a039fbc9ba
BLAKE2b-256 checksum
How to use checksums
6256ece3c834f8f7cd216ac98646c037d129220a1c9fde20a33e494f0dc28ff9
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.2.1-py3-none-musllinux_1_1_armv7l.whl

Download URL fauxgen-0.2.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
6e7ae90a105bfa1b2744efaf4185db81aa48c5ebf98fc6129aa171a9589499d4
BLAKE2b-256 checksum
How to use checksums
958b7247c960edd6e6814e019b3538725935cc0f7ec374dc4e64222ba3560735
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.2.1-py3-none-musllinux_1_1_aarch64.whl

Download URL fauxgen-0.2.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
0b8d6b8d00e2038886b54632d3a202ddddcfff0fbfee4b2787b88cc180218ea6
BLAKE2b-256 checksum
How to use checksums
ca6d62b0d0e53c01aa3c9a3aa064c9800e5755b80aebe383ef4d451ef89d1c3a
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.2.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fauxgen-0.2.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
c17d093a309bf5ffbca5dce7dea0358e4f4cd77ae721a7d96deb39db872bf250
BLAKE2b-256 checksum
How to use checksums
f1c462d6a744959320323e46a21d78ee899d28e124f1b64e72b9a9703d6f8088
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.2.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL fauxgen-0.2.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
5aca95e0ca4ad81ac35712c32f46c424c17b890847a31acfaccab55bab2280ae
BLAKE2b-256 checksum
How to use checksums
9d4749690e65747c3eee33b22b10b946c8a05cd34e7eaa08cd740bd37d95bced
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.2.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL fauxgen-0.2.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
7e874795ac3a56c8241a7e47b53ae7e947472efdbbbb4271da51049f8b77b80d
BLAKE2b-256 checksum
How to use checksums
a1d836ecb1108507ddc702e2f5e43809a3ce07521387cec6880b178efd443c9f
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.2.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL fauxgen-0.2.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
e1b689810938348ccc82dd5a188ff6a058bae55170aaa1cf035f0828a1fe22f2
BLAKE2b-256 checksum
How to use checksums
a01895c8a4d3a16b3c52b8a1704856e50fcbd5802a46e67bd2e82cb815a95c68
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.2.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL fauxgen-0.2.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
7b4f97181ae7600386456638cbb75d86ffeb4d12c1b9ddd1d68cf68b27eb50aa
BLAKE2b-256 checksum
How to use checksums
6a7be32576fef1b7deb72536aa99f5b2fafb88bea186b50d2a903ebabd8b9727
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.2.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL fauxgen-0.2.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
134ee4aaf048d25061e4f42e3b6a69e33a6cb1dd17b7c145151fcfc061d775f8
BLAKE2b-256 checksum
How to use checksums
8608b166c309fae54c8df324913bac9e98a06044ca1f07ec477da1d691a70a1a
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.2.1-py3-none-macosx_11_0_arm64.whl

Download URL fauxgen-0.2.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
56082676c94df22185506bcecc5f9a47a6aaf4b79f8298fb4800821a31f50341
BLAKE2b-256 checksum
How to use checksums
a611c7259cc1fbb90d03c1e3c21caeb8681280cc152ba8d3239c1c60f95749a1
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.2.1-py3-none-macosx_10_12_x86_64.whl

Download URL fauxgen-0.2.1-py3-none-macosx_10_12_x86_64.whl
Size 2.1 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c9261a662dc432b26b750ed34cf13137c9c830139b51e59197068d588de44522
BLAKE2b-256 checksum
How to use checksums
81af63c19b5d7ada424810f545dee9b25c27b389b0e8d9cafe50cfadd082a130
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

This release

0.2.1 This release

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