Skip to main content

Add your description here

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fauxgen-0.3.0-py3-none-musllinux_1_1_x86_64.whl (2.3 MB view details)

Uploaded Python 3musllinux: musl 1.1+ x86-64

fauxgen-0.3.0-py3-none-musllinux_1_1_armv7l.whl (2.0 MB view details)

Uploaded Python 3musllinux: musl 1.1+ ARMv7l

fauxgen-0.3.0-py3-none-musllinux_1_1_aarch64.whl (2.1 MB view details)

Uploaded Python 3musllinux: musl 1.1+ ARM64

fauxgen-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

fauxgen-0.3.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

fauxgen-0.3.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

fauxgen-0.3.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (2.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

fauxgen-0.3.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

fauxgen-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

fauxgen-0.3.0-py3-none-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

fauxgen-0.3.0-py3-none-macosx_10_12_x86_64.whl (2.2 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file fauxgen-0.3.0-py3-none-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for fauxgen-0.3.0-py3-none-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 bc1e9b7a21c3baea69574317d973948f1d9e7920a5e2bb1b16381f688565c625
MD5 306dd07d86a3b0c543b44f89364999d7
BLAKE2b-256 87df4382bf5d2ef459a2682a0c1362d79729915a63156d51108aeb115325f399

See more details on using hashes here.

File details

Details for the file fauxgen-0.3.0-py3-none-musllinux_1_1_armv7l.whl.

File metadata

File hashes

Hashes for fauxgen-0.3.0-py3-none-musllinux_1_1_armv7l.whl
Algorithm Hash digest
SHA256 6ea6399b8b5cd33b7a51d645ef54126e43a04349e3f9689b12db6cc54b6a4d06
MD5 934abc82b0798db09a4c84d40b50397a
BLAKE2b-256 3485f666a26871ea9ed87040707650ecd53a67bb5ae1f18f6136ed2b0795d7f7

See more details on using hashes here.

File details

Details for the file fauxgen-0.3.0-py3-none-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for fauxgen-0.3.0-py3-none-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 39da96a636f4d7abb6496de054215c2d812b4802e9ee7f33469ce0182b897b1a
MD5 b833a700e75f27874ea9d7a6fda26246
BLAKE2b-256 bb4e7808705b278d64ac9e30711aa9cace12c1e670c97323a09c9a389e08acef

See more details on using hashes here.

File details

Details for the file fauxgen-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fauxgen-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 97e8124a0b68edb323abfa0afc64a1188a3137818fcd6134c02a8623005bc866
MD5 48a910c9c1c69b4b98869b72b08534d6
BLAKE2b-256 ffd4364e638235c3de13bc1ae84b815ce04561359786bf8e6d8b70507463e570

See more details on using hashes here.

File details

Details for the file fauxgen-0.3.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for fauxgen-0.3.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 a34fccbf8294d50272fa685c02eaa14952de43ddfbe33fe2450266deb54a34c4
MD5 6186c6c8cf6e2f791667c2c945b8ce24
BLAKE2b-256 3be03ec3744fe258a6e64e5dca1d3eb6b71b97a343d6c26164908e9a149ed194

See more details on using hashes here.

File details

Details for the file fauxgen-0.3.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for fauxgen-0.3.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 16070ec7c7cee5fe17ca405343ad135f8f23b4730e48a0e25a92b1c7d0b18b06
MD5 05c4931706844d9309cba76ef7bc884e
BLAKE2b-256 cff24bb1d7abcec72cf5250bca24d27c619216465761f71f1f28b8b5641728fc

See more details on using hashes here.

File details

Details for the file fauxgen-0.3.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for fauxgen-0.3.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 011717f55a455089380c5c9398eec42332333c91083e95bc6f1d25a23f00cd88
MD5 07c5aac56df657274544bff0a3858bb1
BLAKE2b-256 51f6cba6e86f358f4f8229afb40e250ebc4e6236fe219a8a8710775e763a703c

See more details on using hashes here.

File details

Details for the file fauxgen-0.3.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for fauxgen-0.3.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 b1271cd494563b828c7ab5eb80b1768df236bcdba739add51dcbd1d4406cc448
MD5 2c7ca49d325dd266e757d3ce0040f19e
BLAKE2b-256 b9bac630f938ab3f60e246192243f1e81786e1df7bea6abe1351f9b152f82be2

See more details on using hashes here.

File details

Details for the file fauxgen-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fauxgen-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5ca67c7a7c541d873401bfb23ae0ebad3cbfb04e081075e4a31e6b020d88288d
MD5 0ef958df9737a6217eb1837a74d0f0b3
BLAKE2b-256 d9f78a87be7fe954905bed6abc07be864f24b87294a0d06a5015923d1feacde9

See more details on using hashes here.

File details

Details for the file fauxgen-0.3.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fauxgen-0.3.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4ef9fa6af248d247bb6072619e216a25dd1d12503c6134fe583f6382c58ca105
MD5 44873f3c966338c6c42a6e1350c99521
BLAKE2b-256 33b7fde330ab1b3d56e775fab401162b7e55371424dc3be430577b8ce04b4caf

See more details on using hashes here.

File details

Details for the file fauxgen-0.3.0-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for fauxgen-0.3.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5a5ea1ae7e994c38281f05e5d30efbd2b5d0a69a1505f4957acc3ad7b3294839
MD5 1f5aed6455ce300ff2f58db08a00138d
BLAKE2b-256 242fa4ce1b7ff2236aa4585e51b34f63b4b6e11c301506293b0b7a71534a7812

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page