lycantropos / hypothesis_sqlalchemy

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

Fix tables.records generator when min_records >= 2 and table has no unique columns #9

Closed JoshRosen closed 5 years ago

JoshRosen commented 5 years ago

This PR fixes a corner case bug in the tables.records generator: if min_records >= 2 and the table schema has no unique columns then Hypothesis would fail to generate examples.

The problem is the unique_by function passed to strategies.lists: if a table has no unique columns then to_unique_fields() will return an empty tuple for every record, causing all records to have the same uniqueness key. Instead, I think we should pass unique_by=None when there are no unique columns.

Here, I added a regression test and implemented that fix.

(Thanks for the cool library! I'm experimenting with using Hypothesis for testing SQL database engines and your code has been useful for handling the data generation pieces.)

codecov[bot] commented 5 years ago

Codecov Report

Merging #9 into dev will increase coverage by <.01%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             dev       #9      +/-   ##
=========================================
+ Coverage   99.4%   99.41%   +<.01%     
=========================================
  Files          9        9              
  Lines        168      170       +2     
=========================================
+ Hits         167      169       +2     
  Misses         1        1
Impacted Files Coverage Δ
hypothesis_sqlalchemy/records.py 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7563f33...a796ddf. Read the comment docs.

lycantropos commented 5 years ago

@JoshRosen: thanks for your contribution, let me take a look

lycantropos commented 5 years ago

I've changed target branch to dev, because there are some refactoring changes that I wanted to apply once something significant will be added, after that I'll bump patch version and upload new package to PyPI