Package: hypothesis-sqlalchemy
hypothesis_sqlalchemyIn what followspythonis an alias forpython3.7orpypy3.7or any later version (python3.8,pypy3.8and so on).InstallationInstall the latestpip&setuptoolspackages versionspython-mpipinstall--upgradepipsetuptoolsUserDownload and install the latest stable version fromPyPIrepositorypython-mpipinstall--upgradehypothesis_sqlalchemyDeveloperDownload the latest version fromGitHubrepositorygitclonehttps://github.com/lycantropos/hypothesis_sqlalchemy.gitcdhypothesis_sqlalchemyInstall dependenciespython-mpipinstall-rrequirements.txtInstallpythonsetup.pyinstallUsageWith setup>>>importwarnings>>>fromhypothesis.errorsimportNonInteractiveExampleWarning>>># ignore hypothesis warnings caused by `example` method call...warnings.filterwarnings('ignore',category=NonInteractiveExampleWarning)let's take a look at what can be generated and how.TablesWe can write a strategy that produces tables>>>fromhypothesis_sqlalchemyimportscheme>>>fromsqlalchemy.engine.defaultimportDefaultDialect>>>dialect=DefaultDialect()>>>tables=scheme.tables(dialect,...min_size=3,...max_size=10)>>>table=tables.example()>>>fromsqlalchemy.schemaimportTable>>>isinstance(table,Table)True>>>fromsqlalchemy.schemaimportColumn>>>all(isinstance(column,Column)forcolumnintable.columns)True>>>3<=len(table.columns)<=10TrueRecordsSuppose we have a table>>>fromsqlalchemy.schemaimport(Column,...MetaData,...Table)>>>fromsqlalchemy.sql.sqltypesimport(Integer,...String)>>>metadata=MetaData()>>>user_table=Table('user',metadata,...Column('user_id',Integer,...primary_key=True),...Column('user_name',String(16),...nullable=False),...Column('email_address',String(60)),...Column('password',String(20),...nullable=False))and we can write strategy thatproduces single records (astuples)>>>fromhypothesisimportstrategies>>>fromhypothesis_sqlalchemy.sampleimporttable_records>>>records=table_records(user_table,...email_address=strategies.emails())>>>record=records.example()>>>isinstance(record,tuple)True>>>len(record)==len(user_table.columns)True>>>all(column.nullableandvalueisNone...orisinstance(value,column.type.python_type)...forvalue,columninzip(record,user_table.columns))Trueproduces recordslists (with configurablelistsize bounds)>>>fromhypothesis_sqlalchemy.sampleimporttable_records_lists>>>records_lists=table_records_lists(user_table,...min_size=2,...max_size=5,...email_address=strategies.emails())>>>records_list=records_lists.example()>>>isinstance(records_list,list)True>>>2<=len(records_list)<=5True>>>all(isinstance(record,tuple)forrecordinrecords_list)True>>>all(len(record)==len(user_table.columns)forrecordinrecords_list)TrueDevelopmentBumping versionPreparationInstallbump2version.Pre-releaseChoose which version number category to bump followingsemver
specification.Test bumping versionbump2version--dry-run--verbose$CATEGORYwhere$CATEGORYis the target version number category name, possible
values arepatch/minor/major.Bump versionbump2version--verbose$CATEGORYThis will set version tomajor.minor.patch-alpha.ReleaseTest bumping versionbump2version--dry-run--verbosereleaseBump versionbump2version--verbosereleaseThis will set version tomajor.minor.patch.Running testsInstall dependenciespython-mpipinstall-rrequirements-tests.txtPlainpytestInsideDockercontainer:withCPythondocker-compose--filedocker-compose.cpython.ymlupwithPyPydocker-compose--filedocker-compose.pypy.ymlupBashscript:withCPython./run-tests.shor./run-tests.shcpythonwithPyPy./run-tests.shpypyPowerShellscript:withCPython.\run-tests.ps1or.\run-tests.ps1cpythonwithPyPy.\run-tests.ps1pypy