lycantropos / hypothesis_sqlalchemy

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

Add support for unique constraints #17

Closed lycantropos closed 4 years ago

lycantropos commented 5 years ago

We have currently support for single unique columns and we should add support for unique constraints too (both their generating & handling in records creation).

rubenhelsloot commented 5 years ago

How is this going? If you have a proposal on how to parse and convert constraints, I might be able to look at ways to process CheckConstraints if you'd like

lycantropos commented 5 years ago

@rubenhelsloot: I'm not so familiar with them, there is sqlparse package that may help in parsing constraints' expression, but there is a problem of generating such constraints as a strategy and serializing tokens back to str, is it really needed (because it looks complicated from my point of view)?

lycantropos commented 5 years ago

One way of filtering records based on presence of CheckConstraint in Table is following:

  1. parse expression into some sort of syntax tree.
  2. make Python AST from it.
  3. construct a ast.Lambda node which accepts table record (parameters names should agree with columns names) and evaluates converted expression.
  4. compile it.
  5. use obtained lambda function in filter on records strategy.
rubenhelsloot commented 5 years ago

It is not necessarily needed, I fix it now by adding my own set of filter conditions, but that requires intimate knowledge of the database constraints and I think it would be a nice step towards feature completeness. On the other hand, if you're aiming for a more barebones package that is easy to understand and potentially mock, then I can see how this will add unnecessary complication

lycantropos commented 5 years ago

We can start with UniqueConstraint since it looks easier to implement, after that we can move forward to CheckConstraint I guess, it is not impossible, but requires time, I want to have library as complete and easy to use as possible.

rubenhelsloot commented 5 years ago

All right, is there something I can do to help?

lycantropos commented 5 years ago

@rubenhelsloot: you can open a PR with implementation draft and after some review-update iterations we can make it work or wait one-two days before I'll end with my current task on another project.

lycantropos commented 4 years ago

I was naive at a time thinking that Delaunay triangulation can be implemented in a week, it took me 2 months, so now I'm going to move on constraints right after #22.