Chalk home page
Docs
API
CLI
  1. Testing
  2. Unit Tests

Chalk lets you specify your feature pipelines using idiomatic Python. This means that you can unit test individual resolvers and combinations of resolvers, since they’re just Python functions.

Example

Consider the following features and resolvers:

@features
class HomeFeatures:
    home_id: str
    address: str
    price: int
    sq_ft: int


@realtime
def get_address(
    hid: HomeFeatures.home_id,
) -> HomeFeatures.address:
    return "Bridge Street" if hid == 1 else "Filbert Street"


@realtime
def get_home_data(
    hid: HomeFeatures.home_id,
) -> Features[HomeFeatures.price, HomeFeatures.sq_ft]:
    return HomeFeatures(
        price=200_000,
        sq_ft=2_000,
    )

You can test them just like normal Python functions using any unit testing framework:

class FeatureResolverCallableTestCase(TestCase):
    def test_single_output(self):
        self.assertEqual(
            get_address(2),
            "Filbert Street",
        )

    def test_multiple_output(self):
        result = get_home_data(2)
        self.assertEqual(result.price, 200_000)
        self.assertEqual(result.sq_ft, 2_000)

        self.assertNotEqual(
            result,
            HomeFeatures(
                address="hello",
                price=200_000,
                sq_ft=2_000,
            ),
        )

        self.assertEqual(
            result,
            HomeFeatures(
                price=200_000,
                sq_ft=2_000,
            ),
        )