Package: hypothesis-geometry
hypothesis_geometryIn what followspythonis an alias forpython3.6orpypy3.6or any later version (python3.7,pypy3.7and so on).InstallationInstall the latestpip&setuptoolspackages versionspython-mpipinstall--upgradepipsetuptoolsUserDownload and install the latest stable version fromPyPIrepositorypython-mpipinstall--upgradehypothesis_geometryDeveloperDownload the latest version fromGitHubrepositorygitclonehttps://github.com/lycantropos/hypothesis_geometry.gitcdhypothesis_geometryInstall dependenciespython-mpipinstall-rrequirements.txtInstallpythonsetup.pyinstallUsageWith setup>>>fromground.baseimportget_context>>>fromhypothesisimportstrategies>>>fromhypothesis_geometryimportplanar>>>context=get_context()>>>Contour=context.contour_cls>>>Empty=context.empty_cls>>>Mix=context.mix_cls>>>Multipoint=context.multipoint_cls>>>Multipolygon=context.multipolygon_cls>>>Multisegment=context.multisegment_cls>>>Point=context.point_cls>>>Polygon=context.polygon_cls>>>Segment=context.segment_cls>>>min_coordinate,max_coordinate=-100,100>>>coordinates_type=int>>>coordinates=strategies.integers(min_coordinate,max_coordinate)>>>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.Empty geometries>>>empty_geometries=planar.empty_geometries()>>>empty=empty_geometries.example()>>>isinstance(empty,Empty)TruePoints>>>points=planar.points(coordinates)>>>point=points.example()>>>isinstance(point,Point)True>>>(isinstance(point.x,coordinates_type)...andisinstance(point.y,coordinates_type))True>>>(min_coordinate<=point.x<=max_coordinate...andmin_coordinate<=point.y<=max_coordinate)TrueMultipoints>>>min_size,max_size=5,10>>>multipoints=planar.multipoints(coordinates,...min_size=min_size,...max_size=max_size)>>>multipoint=multipoints.example()>>>isinstance(multipoint,Multipoint)True>>>min_size<=len(multipoint.points)<=max_sizeTrue>>>all(isinstance(point.x,coordinates_type)...andisinstance(point.y,coordinates_type)...forpointinmultipoint.points)True>>>all(min_coordinate<=point.x<=max_coordinate...andmin_coordinate<=point.y<=max_coordinate...forpointinmultipoint.points)TrueSegments>>>segments=planar.segments(coordinates)>>>segment=segments.example()>>>isinstance(segment,Segment)True>>>(isinstance(segment.start.x,coordinates_type)...andisinstance(segment.start.y,coordinates_type)...andisinstance(segment.end.x,coordinates_type)...andisinstance(segment.end.y,coordinates_type))True>>>(min_coordinate<=segment.start.x<=max_coordinate...andmin_coordinate<=segment.start.y<=max_coordinate...andmin_coordinate<=segment.end.x<=max_coordinate...andmin_coordinate<=segment.end.y<=max_coordinate)TrueMultisegments>>>min_size,max_size=5,10>>>multisegments=planar.multisegments(coordinates,...min_size=min_size,...max_size=max_size)>>>multisegment=multisegments.example()>>>isinstance(multisegment,Multisegment)True>>>min_size<=len(multisegment.segments)<=max_sizeTrue>>>all(isinstance(segment.start.x,coordinates_type)...andisinstance(segment.start.y,coordinates_type)...andisinstance(segment.end.x,coordinates_type)...andisinstance(segment.end.y,coordinates_type)...forsegmentinmultisegment.segments)True>>>all(min_coordinate<=segment.start.x<=max_coordinate...andmin_coordinate<=segment.start.y<=max_coordinate...andmin_coordinate<=segment.end.x<=max_coordinate...andmin_coordinate<=segment.end.y<=max_coordinate...forsegmentinmultisegment.segments)TrueContours>>>min_size,max_size=5,10>>>contours=planar.contours(coordinates,...min_size=min_size,...max_size=max_size)>>>contour=contours.example()>>>isinstance(contour,Contour)True>>>min_size<=len(contour.vertices)<=max_sizeTrue>>>all(isinstance(vertex.x,coordinates_type)...andisinstance(vertex.y,coordinates_type)...forvertexincontour.vertices)True>>>all(min_coordinate<=vertex.x<=max_coordinate...andmin_coordinate<=vertex.y<=max_coordinate...forvertexincontour.vertices)Truealsoplanar.concave_contours&planar.convex_contoursoptions are available.Multicontours>>>min_size,max_size=5,10>>>min_contour_size,max_contour_size=4,8>>>multicontours=planar.multicontours(coordinates,...min_size=min_size,...max_size=max_size,...min_contour_size=min_contour_size,...max_contour_size=max_contour_size)>>>multicontour=multicontours.example()>>>isinstance(multicontour,list)True>>>all(isinstance(contour,Contour)forcontourinmulticontour)True>>>min_size<=len(multicontour)<=max_sizeTrue>>>all(min_contour_size<=len(contour.vertices)<=max_contour_size...forcontourinmulticontour)True>>>all(isinstance(vertex.x,coordinates_type)...andisinstance(vertex.y,coordinates_type)...forcontourinmulticontour...forvertexincontour.vertices)True>>>all(min_coordinate<=vertex.x<=max_coordinate...andmin_coordinate<=vertex.y<=max_coordinate...forcontourinmulticontour...forvertexincontour.vertices)TruePolygons>>>min_size,max_size=5,10>>>min_holes_size,max_holes_size=1,3>>>min_hole_size,max_hole_size=4,8>>>polygons=planar.polygons(coordinates,...min_size=min_size,...max_size=max_size,...min_holes_size=min_holes_size,...max_holes_size=max_holes_size,...min_hole_size=min_hole_size,...max_hole_size=max_hole_size)>>>polygon=polygons.example()>>>isinstance(polygon,Polygon)True>>>min_size<=len(polygon.border.vertices)<=max_sizeTrue>>>min_holes_size<=len(polygon.holes)<=max_holes_sizeTrue>>>all(min_hole_size<=len(hole.vertices)<=max_hole_sizeforholeinpolygon.holes)True>>>polygon_contours=[polygon.border,*polygon.holes]>>>all(isinstance(vertex.x,coordinates_type)...andisinstance(vertex.y,coordinates_type)...forcontourinpolygon_contours...forvertexincontour.vertices)True>>>all(min_coordinate<=vertex.x<=max_coordinate...andmin_coordinate<=vertex.y<=max_coordinate...forcontourinpolygon_contours...forvertexincontour.vertices)TrueMultipolygons>>>min_size,max_size=2,5>>>min_border_size,max_border_size=5,10>>>min_holes_size,max_holes_size=1,3>>>min_hole_size,max_hole_size=4,8>>>multipolygons=planar.multipolygons(coordinates,...min_size=min_size,...max_size=max_size,...min_border_size=min_border_size,...max_border_size=max_border_size,...min_holes_size=min_holes_size,...max_holes_size=max_holes_size,...min_hole_size=min_hole_size,...max_hole_size=max_hole_size)>>>multipolygon=multipolygons.example()>>>isinstance(multipolygon,Multipolygon)True>>>min_size<=len(multipolygon.polygons)<=max_sizeTrue>>>all(min_border_size<=len(polygon.border.vertices)<=max_border_size...andmin_holes_size<=len(polygon.holes)<=max_holes_size...andall(min_hole_size<=len(hole.vertices)<=max_hole_size...forholeinpolygon.holes)...forpolygoninmultipolygon.polygons)True>>>all(all(isinstance(vertex.x,coordinates_type)...andisinstance(vertex.y,coordinates_type)...forvertexinpolygon.border.vertices)...andall(isinstance(vertex.x,coordinates_type)...andisinstance(vertex.y,coordinates_type)...forholeinpolygon.holes...forvertexinhole.vertices)...forpolygoninmultipolygon.polygons)True>>>all(all(min_coordinate<=vertex.x<=max_coordinate...andmin_coordinate<=vertex.y<=max_coordinate...forvertexinpolygon.border.vertices)...andall(min_coordinate<=vertex.x<=max_coordinate...andmin_coordinate<=vertex.y<=max_coordinate...forholeinpolygon.holes...forvertexinhole.vertices)...forpolygoninmultipolygon.polygons)TrueMixes>>>min_points_size,max_points_size=2,3>>>min_segments_size,max_segments_size=1,4>>>min_polygons_size,max_polygons_size=0,5>>>min_polygon_border_size,max_polygon_border_size=5,10>>>min_polygon_holes_size,max_polygon_holes_size=1,4>>>min_polygon_hole_size,max_polygon_hole_size=3,5>>>mixes=planar.mixes(coordinates,...min_points_size=min_points_size,...max_points_size=max_points_size,...min_segments_size=min_segments_size,...max_segments_size=max_segments_size,...min_polygons_size=min_polygons_size,...max_polygons_size=max_polygons_size,...min_polygon_border_size=min_polygon_border_size,...max_polygon_border_size=max_polygon_border_size,...min_polygon_holes_size=min_polygon_holes_size,...max_polygon_holes_size=max_polygon_holes_size,...min_polygon_hole_size=min_polygon_hole_size,...max_polygon_hole_size=max_polygon_hole_size)>>>mix=mixes.example()>>>isinstance(mix,Mix)True>>>isinstance(mix.discrete,(Empty,Multipoint))True>>>points=[]ifisinstance(mix.discrete,Empty)elsemix.discrete.points>>>min_points_size<=len(points)<=max_points_sizeTrue>>>all(isinstance(point.x,coordinates_type)...andisinstance(point.y,coordinates_type)...forpointinpoints)True>>>all(min_coordinate<=point.x<=max_coordinate...andmin_coordinate<=point.y<=max_coordinate...forpointinpoints)True>>>isinstance(mix.linear,(Empty,Segment,Contour,Multisegment))True>>>segments=([]...ifisinstance(mix.linear,Empty)...else([mix.linear]...ifisinstance(mix.linear,Segment)...else(mix.linear.segments...ifisinstance(mix.linear,Multisegment)...elsecontext.contour_edges(mix.linear))))>>>min_segments_size<=len(segments)<=max_segments_sizeTrue>>>all(isinstance(segment.start.x,coordinates_type)...andisinstance(segment.start.y,coordinates_type)...andisinstance(segment.end.x,coordinates_type)...andisinstance(segment.end.y,coordinates_type)...forsegmentinsegments)True>>>all(min_coordinate<=segment.start.x<=max_coordinate...andmin_coordinate<=segment.start.y<=max_coordinate...andmin_coordinate<=segment.end.x<=max_coordinate...andmin_coordinate<=segment.end.y<=max_coordinate...forsegmentinsegments)True>>>isinstance(mix.shaped,(Empty,Polygon,Multipolygon))True>>>polygons=([]...ifisinstance(mix.shaped,Empty)...else([mix.shaped]...ifisinstance(mix.shaped,Polygon)...elsemix.shaped.polygons))>>>min_polygons_size<=len(polygons)<=max_polygons_sizeTrue>>>all(min_polygon_border_size...<=len(polygon.border.vertices)...<=max_polygon_border_size...and(min_polygon_holes_size...<=len(polygon.holes)...<=max_polygon_holes_size)...andall(min_polygon_hole_size...<=len(hole.vertices)...<=max_polygon_hole_size...forholeinpolygon.holes)...forpolygoninpolygons)True>>>all(all(isinstance(vertex.x,coordinates_type)...andisinstance(vertex.y,coordinates_type)...forvertexinpolygon.border.vertices)...andall(isinstance(vertex.x,coordinates_type)...andisinstance(vertex.y,coordinates_type)...forholeinpolygon.holes...forvertexinhole.vertices)...forpolygoninpolygons)True>>>all(all(min_coordinate<=vertex.x<=max_coordinate...andmin_coordinate<=vertex.y<=max_coordinate...forvertexinpolygon.border.vertices)...andall(min_coordinate<=vertex.x<=max_coordinate...andmin_coordinate<=vertex.y<=max_coordinate...forholeinpolygon.holes...forvertexinhole.vertices)...forpolygoninpolygons)TrueCaveatsStrategies may be slow depending on domain,
so it may be necessary to addHealthCheck.filter_too_much,HealthCheck.too_slowinsuppress_health_checkand setdeadlinetoNone.Unbounded floating point strategies for coordinates
(likehypothesis.strategies.floatswith unsetmin_value/max_value) do not play well with bounded sizes
and may cause a lot of searching iterations with no success,
so it is recommended to use bounded floating point coordinates with bounded sizes
or unbounded coordinates with unbounded sizes.decimal.Decimalcoordinates are not supported, because
they seem to be too hard to work with correctly (e.g. sometimes self-intersecting contours arise),
so it is suggested to usefloatorfractions.Fractioninstead.DevelopmentBumping 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