lycantropos / hypothesis_sqlalchemy

hypothesis strategies for generating SQLAlchemy objects
MIT License
28 stars 8 forks source link

[Question] How to customize strategies? #3

Closed fkromer closed 5 years ago

fkromer commented 6 years ago

It is not clear to me how to customize strategies that they generate customized tables and records. Given your records usage example: How could I generate values for user_id in a customized range of integer values, let's say between 0 and 1000?

lycantropos commented 6 years ago

@fkromer: we can pass additional arguments by keyword, where each keyword corresponds to column name. E.g. if we want user_id to be from range between 0 and 1000 this can be done like

>>> from hypothesis import strategies
>>> from hypothesis_sqlalchemy import tables
>>> custom_columns = {user_table.c.user_id.name: strategies.integers(0, 1000)}
>>> records = tables.records.factory(user_table,
                                     **custom_columns)
>>> records.example()
(155, '(*)', None, '.)#Gpz')
fkromer commented 6 years ago

@lycantropos Thx a lot for the hint. BTW: Great package.