Skip to content

cjw296/chide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

491ba25 · Jan 17, 2025

History

68 Commits
Dec 12, 2024
Jan 17, 2025
Jan 17, 2025
Jan 17, 2025
Dec 12, 2024
Jun 20, 2024
Jul 19, 2024
May 5, 2024
Jan 17, 2025
May 5, 2024
Jan 17, 2025
May 5, 2024
May 7, 2024
Apr 14, 2016
Jan 17, 2025

Repository files navigation

Chide

CircleCI Docs

Quickly create and compare sample objects.

Chide's philosophy is to give you a simple registry of parameters needed to instantiate objects for your tests. There's also support for simplifying objects down to mappings of their attributes for easier comparison and rendering, along with parsing and rendering of formats for inserting or asserting about multiple objects that are naturally tabular.

Quickstart

Say we have two classes that each require two parameters in order to be instantiated:

from dataclasses import dataclass

@dataclass
class ClassOne:
  x: int
  y: int

@dataclass
class ClassTwo:
  a: int
  b: ClassOne

We can set up a registry of sample values as follows:

from chide import Collection

samples = Collection({
    ClassOne: {'x': 1, 'y': 2},
    ClassTwo: {'a': 1, 'b': ClassOne},
})

Now we can quickly make sample objects:

>>> samples.make(ClassOne)
ClassOne(x=1, y=2)

We can provide our own overrides if we want:

>>> samples.make(ClassOne, y=3)
ClassOne(x=1, y=3)

We can also create nested trees of objects:

>>> samples.make(ClassTwo)
ClassTwo(a=1, b=ClassOne(x=1, y=2))

About

Quickly create sample objects from data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages