lycantropos / hypothesis_sqlalchemy

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

Custom type support? #41

Open jenstroeger opened 1 year ago

jenstroeger commented 1 year ago

Interesting package, thank you for the effort!

Have you considered adding support for custom types? For example, suppose I use a custom type like e.g. CurrencyType which basically maps to a SQLA String type (src) then it would be useful to either

With the current version I receive an error:

>>> hypothesis_sqlalchemy.sample.table_records(Test.__table__)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/.../.venv/lib/python3.10/site-packages/hypothesis_sqlalchemy/core/table_records.py", line 15, in instances
    return columns_records.instances(list(table.columns),
  File "/.../.venv/lib/python3.10/site-packages/hypothesis_sqlalchemy/core/columns_records.py", line 29, in instances
    return strategies.tuples(*map(column_scalars, columns))
  File "/.../.venv/lib/python3.10/site-packages/hypothesis_sqlalchemy/core/column.py", line 39, in scalars
    result = column_type.scalars(column.type)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/functools.py", line 889, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "/.../.venv/lib/python3.10/site-packages/hypothesis_sqlalchemy/core/column_type.py", line 134, in scalars
    return _values_by_python_types[type_.python_type]
KeyError: <class 'sqlalchemy_utils.primitives.currency.Currency'>

Here it would be useful to either: