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
use the column’s type to map that to a strategy; or
use the column’s Python type to map that to a strategy (if the Python type is a simple one); or
use a user-provided custom strategy.
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:
return a text(max_size=3) strategy (poor strategy based in the custom type’s String(3) wrapped type, but it’d work); or
return a sample_from(list(babel.core.get_global("all_currencies").keys())) strategy for the Python type Currency (although this wouldn’t be possible to derive from the Currency code; or
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:
Here it would be useful to either:
text(max_size=3)
strategy (poor strategy based in the custom type’sString(3)
wrapped type, but it’d work); orsample_from(list(babel.core.get_global("all_currencies").keys()))
strategy for the Python typeCurrency
(although this wouldn’t be possible to derive from the Currency code; orsample_from()
strategy.